ScummVM API documentation
camera.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ALCACHOFA_CAMERA_H
23 #define ALCACHOFA_CAMERA_H
24 
25 #include "alcachofa/common.h"
26 #include "math/matrix4.h"
27 
28 namespace Alcachofa {
29 
30 class WalkingCharacter;
31 class Process;
32 struct Task;
33 
34 static constexpr const int16_t kBaseScale = 300;
35 static constexpr const float kInvBaseScale = 1.0f / kBaseScale;
36 
37 class Camera {
38 public:
39  inline Math::Angle rotation() const { return _cur._rotation; }
40  inline Math::Vector2d &shake() { return _shake; }
41  inline WalkingCharacter *followTarget() { return _followTarget; }
42 
43  void update();
44  Math::Vector3d transform2Dto3D(Math::Vector3d v) const;
45  Math::Vector3d transform3Dto2D(Math::Vector3d v) const;
46  Common::Point transform3Dto2D(Common::Point p) const;
47  void resetRotationAndScale();
48  void setRoomBounds(Common::Point bgSize, int16 bgScale);
49  void setFollow(WalkingCharacter *target, bool catchUp = false);
50  void setPosition(Math::Vector2d v);
51  void setPosition(Math::Vector3d v);
52  void backup(uint slot);
53  void restore(uint slot);
54  void syncGame(Common::Serializer &s);
55 
56  Task *lerpPos(Process &process,
57  Math::Vector2d targetPos,
58  int32 duration, EasingType easingType);
59  Task *lerpPos(Process &process,
60  Math::Vector3d targetPos,
61  int32 duration, EasingType easingType);
62  Task *lerpPosZ(Process &process,
63  float targetPosZ,
64  int32 duration, EasingType easingType);
65  Task *lerpScale(Process &process,
66  float targetScale,
67  int32 duration, EasingType easingType);
68  Task *lerpRotation(Process &process,
69  float targetRotation,
70  int32 duration, EasingType easingType);
71  Task *lerpPosScale(Process &process,
72  Math::Vector3d targetPos, float targetScale,
73  int32 duration, EasingType moveEasingType, EasingType scaleEasingType);
74  Task *waitToStop(Process &process);
75  Task *shake(Process &process, Math::Vector2d amplitude, Math::Vector2d frequency, int32 duration);
76 
77 private:
78  friend struct CamLerpTask;
79  friend struct CamLerpPosTask;
80  friend struct CamLerpScaleTask;
81  friend struct CamLerpPosScaleTask;
82  friend struct CamLerpRotationTask;
83  friend struct CamShakeTask;
84  friend struct CamWaitToStopTask;
85  friend struct CamSetInactiveAttributeTask;
86  Math::Vector3d setAppliedCenter(Math::Vector3d center);
87  void setupMatricesAround(Math::Vector3d center);
88  void updateFollowing(float deltaTime);
89 
90  struct State {
91  Math::Vector3d _usedCenter = Math::Vector3d(512, 384, 0);
92  float
93  _scale = 1.0f,
94  _speed = 0.0f,
95  _maxSpeedFactor = 230.0f;
96  Math::Angle _rotation;
97  bool _isBraking = false;
98  bool _isFollowingTarget = false;
99 
100  void syncGame(Common::Serializer &s);
101  };
102 
103  static constexpr uint kStateBackupCount = 2;
104  State _cur, _backups[kStateBackupCount];
105  WalkingCharacter *_followTarget = nullptr;
106  uint32 _lastUpdateTime = 0;
107  bool _isChanging = false,
108  _catchUp = false;
109  float _roomScale = 1.0f;
110  Math::Vector2d
111  _roomMin = Math::Vector2d(-10000, -10000),
112  _roomMax = Math::Vector2d(10000, 10000),
113  _shake;
114  Math::Vector3d _appliedCenter;
115  Math::Matrix4
116  _mat3Dto2D,
117  _mat2Dto3D;
118 };
119 
120 }
121 
122 #endif // ALCACHOFA_CAMERA_H
Definition: objects.h:461
Definition: alcachofa.h:45
Definition: scheduler.h:84
Definition: scheduler.h:164
Definition: serializer.h:79
Definition: rect.h:144
Definition: camera.h:37