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