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 Graphic;
31 class WalkingCharacter;
32 class Process;
33 struct Task;
34 
35 static constexpr const int16_t kBaseScale = 300;
36 static constexpr const float kInvBaseScale = 1.0f / kBaseScale;
37 
38 class Camera {
39 public:
40  virtual ~Camera();
41  virtual Math::Angle rotation() const = 0;
42  virtual float scale() const = 0;
43 
44  virtual void preUpdate() = 0;
45  virtual void update() = 0;
46  virtual void setRoomBounds(Graphic &background) = 0;
47  virtual void setFollow(WalkingCharacter *target) = 0;
48  virtual void onChangedRoom(bool resetCamera) = 0;
49  virtual void onTriggeredDoor(WalkingCharacter *target) = 0;
50  virtual void onTriggeredDoor(Common::Point fixedPosition) = 0;
51  virtual void onScriptChangedCharacter(MainCharacterKind kind) = 0;
52  virtual void onUserChangedCharacter() = 0;
53  virtual void onOpenMenu() = 0;
54  virtual void onCloseMenu() = 0;
55  virtual void syncGame(Common::Serializer &s) = 0;
56 
57  Math::Vector3d transform2Dto3D(Math::Vector3d v) const;
58  Math::Vector3d transform3Dto2D(Math::Vector3d v) const;
59  Common::Point transform3Dto2D(Common::Point p) const;
60 
61 protected:
62  Math::Vector3d setAppliedCenter(Math::Vector3d center);
63  void setupMatricesAround(Math::Vector3d center);
64 
65  float _roomScale = 1.0f;
66  Math::Vector2d
67  _roomMin = Math::Vector2d(-10000, -10000),
68  _roomMax = Math::Vector2d(10000, 10000);
69  Math::Vector3d _appliedCenter;
70  Math::Matrix4
71  _mat3Dto2D,
72  _mat2Dto3D;
73 };
74 
75 class CameraV1 : public Camera {
76 public:
77  Math::Angle rotation() const override;
78  float scale() const override;
79 
80  void preUpdate() override;
81  void update() override;
82  void setRoomBounds(Graphic &background) override;
83  void setFollow(WalkingCharacter *target) override;
84  void onChangedRoom(bool resetCamera) override;
85  void onTriggeredDoor(WalkingCharacter *target) override;
86  void onTriggeredDoor(Common::Point fixedPosition) override;
87  void onScriptChangedCharacter(MainCharacterKind kind) override;
88  void onUserChangedCharacter() override;
89  void onOpenMenu() override;
90  void onCloseMenu() override;
91  void syncGame(Common::Serializer &s) override;
92  void lerpOrSet(Common::Point target, int32 mode);
93 
94  Task *disguise(Process &process, int32 duration);
95 
96 private:
97  friend struct CamV1DisguiseTask;
98 
99  WalkingCharacter *_followTarget = nullptr;
100  Math::Vector3d _target;
101  bool _isLerping = false;
102  float _lerpSpeed = 0.0f;
103  uint32 _lastUpdateTime = 0;
104 };
105 
106 class CameraV3 : public Camera {
107 public:
108  Math::Angle rotation() const override;
109  float scale() const override;
110 
111  void preUpdate() override;
112  void update() override;
113  void setRoomBounds(Graphic &background) override;
114  void setFollow(WalkingCharacter *target) override;
115  void setFollow(WalkingCharacter *target, bool catchup);
116  void onChangedRoom(bool resetCamera) override;
117  void onTriggeredDoor(WalkingCharacter *target) override;
118  void onTriggeredDoor(Common::Point fixedPosition) override;
119  void onScriptChangedCharacter(MainCharacterKind kind) override;
120  void onUserChangedCharacter() override;
121  void onOpenMenu() override;
122  void onCloseMenu() override;
123  void syncGame(Common::Serializer &s) override;
124 
125  Task *lerpPos(Process &process,
126  Math::Vector2d targetPos,
127  int32 duration, EasingType easingType);
128  Task *lerpPos(Process &process,
129  Math::Vector3d targetPos,
130  int32 duration, EasingType easingType);
131  Task *lerpPosZ(Process &process,
132  float targetPosZ,
133  int32 duration, EasingType easingType);
134  Task *lerpScale(Process &process,
135  float targetScale,
136  int32 duration, EasingType easingType);
137  Task *lerpRotation(Process &process,
138  float targetRotation,
139  int32 duration, EasingType easingType);
140  Task *lerpPosScale(Process &process,
141  Math::Vector3d targetPos, float targetScale,
142  int32 duration, EasingType moveEasingType, EasingType scaleEasingType);
143  Task *waitToStop(Process &process);
144  Task *shake(Process &process, Math::Vector2d amplitude, Math::Vector2d frequency, int32 duration);
145 
146 private:
147  friend struct CamLerpTask;
148  friend struct CamLerpPosTask;
149  friend struct CamLerpScaleTask;
150  friend struct CamLerpPosScaleTask;
151  friend struct CamLerpRotationTask;
152  friend struct CamShakeTask;
153  friend struct CamWaitToStopTask;
154  friend struct CamSetInactiveAttributeTask;
155 
156  void resetRotationAndScale();
157  void setPosition(Math::Vector2d v);
158  void setPosition(Math::Vector3d v);
159  void backup(uint slot);
160  void restore(uint slot);
161  void updateFollowing(float deltaTime);
162 
163  struct State {
164  Math::Vector3d _usedCenter = Math::Vector3d(512, 384, 0);
165  float
166  _scale = 1.0f,
167  _speed = 0.0f,
168  _maxSpeedFactor = 230.0f;
169  Math::Angle _rotation;
170  bool _isBraking = false;
171  bool _isFollowingTarget = false;
172 
173  void syncGame(Common::Serializer &s);
174  };
175 
176  static constexpr uint kStateBackupCount = 2;
177  State _cur, _backups[kStateBackupCount];
178  WalkingCharacter *_followTarget = nullptr;
179  uint32 _lastUpdateTime = 0;
180  bool _isChanging = false,
181  _catchUp = false;
182  Math::Vector2d _shake;
183 };
184 
185 }
186 
187 #endif // ALCACHOFA_CAMERA_H
Definition: objects.h:505
Definition: alcachofa.h:45
Definition: scheduler.h:84
Definition: scheduler.h:164
Definition: graphics.h:297
Definition: serializer.h:79
Definition: camera.h:106
Definition: rect.h:144
Definition: camera.h:75
Definition: camera.h:38