YAPOG  0.0.1
Yet Another Pokemon Online Game
ProgressiveCameraController.cpp
Go to the documentation of this file.
5 
6 namespace yap
7 {
11 
13  : CameraController (camera)
14  , velocityFactor_ (
15  Vector2 (
16  DEFAULT_VELOCITY_FACTOR,
17  DEFAULT_VELOCITY_FACTOR))
18  {
19  }
20 
22  {
23  }
24 
26  const Vector2& velocityFactor)
27  {
28  velocityFactor_ = velocityFactor;
29  }
30 
32  {
33  CenterOnTarget ();
34  }
35 
37  {
38  if (target_ == nullptr)
39  return;
40 
41  Vector2 offset;
42 
43  const Vector2& targetPoint = target_->GetCenter ();
44  Vector2 cameraSizeFactor = Vector2 (
45  camera_.GetSize ().x / camera_.GetSize ().y,
46  camera_.GetSize ().y / camera_.GetSize ().x);
47 
48  if (MathHelper::Abs (targetPoint.x - camera_.GetCenter ().x) >
49  CAMERA_MOVE_TRIGGER_LIMIT * cameraSizeFactor.x)
50  offset.x =
51  velocityFactor_.x *
52  (targetPoint.x - camera_.GetCenter ().x) /
54  cameraSizeFactor.y *
55  dt.GetValue ();
56 
57  if (MathHelper::Abs (targetPoint.y - camera_.GetCenter ().y) >
58  CAMERA_MOVE_TRIGGER_LIMIT * cameraSizeFactor.y)
59  offset.y =
60  velocityFactor_.y *
61  (targetPoint.y - camera_.GetCenter ().y) /
63  cameraSizeFactor.x *
64  dt.GetValue ();
65 
66  CheckBounds (offset);
67 
68  camera_.Move (offset);
69  }
70 } // namespace yap