OpenMoHAA 0.82.1
Loading...
Searching...
No Matches
camera.h
1/*
2===========================================================================
3Copyright (C) 2015 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// camera.h: Camera. Duh.
24//
25
26#pragma once
27
28#include "g_local.h"
29#include "entity.h"
30#include "bspline.h"
31#include "container.h"
32#include "level.h"
33
34#define CAMERA_SWITCHTIME 0.5f
35
36#define ORBIT (1 << 0)
37#define START_ON (1 << 1)
38#define AUTOMATIC (1 << 2)
39#define NO_TRACE (1 << 3)
40#define NO_WATCH (1 << 4)
41#define LEVEL_EXIT (1 << 5)
42
43extern Event EV_Camera_CameraThink;
44extern Event EV_Camera_StartMoving;
45extern Event EV_Camera_Pause;
46extern Event EV_Camera_Continue;
47extern Event EV_Camera_StopMoving;
48extern Event EV_Camera_SetSpeed;
49extern Event EV_Camera_SetFollowDistance;
50extern Event EV_Camera_SetOrbitHeight;
51extern Event EV_Camera_SetYaw;
52extern Event EV_Camera_AbsoluteYaw;
53extern Event EV_Camera_RelativeYaw;
54extern Event EV_Camera_SetFOV;
55extern Event EV_Camera_Orbit;
56extern Event EV_Camera_Follow;
57extern Event EV_Camera_Watch;
58extern Event EV_Camera_WatchPath;
59extern Event EV_Camera_LookAt;
60extern Event EV_Camera_TurnTo;
61extern Event EV_Camera_MoveToEntity;
62extern Event EV_Camera_MoveToPos;
63extern Event EV_Camera_NoWatch;
64extern Event EV_Camera_FadeTime;
65extern Event EV_Camera_Cut;
66
67class Camera;
68
69class CameraMoveState : public Class
70{
71public:
72 Vector pos;
73 Vector movedir; // direction of travel
74 Vector angles; // angles from spline camera
75
76 BSpline cameraPath;
77 SplinePathPtr splinePath;
78 SplinePathPtr currentNode;
79 SplinePathPtr loopNode;
80
81 float cameraTime;
82 int lastTime;
83 int newTime;
84
85 qboolean followingpath;
86 EntityPtr followEnt;
87 EntityPtr orbitEnt;
88
89 void operator=(CameraMoveState& newstate);
90 void Evaluate(Camera *camera);
91 void Initialize(Camera *camera);
92 void DoNodeEvents(Camera *camera);
93 void Archive(Archiver& arc) override;
94};
95
96inline void CameraMoveState::operator=(CameraMoveState& newstate)
97{
98 movedir = newstate.movedir;
99 pos = newstate.pos;
100 angles = newstate.angles;
101
102 cameraPath = newstate.cameraPath;
103 splinePath = newstate.splinePath;
104 currentNode = newstate.currentNode;
105 loopNode = newstate.loopNode;
106
107 cameraTime = newstate.cameraTime;
108 lastTime = newstate.lastTime;
109 newTime = newstate.newTime;
110
111 followEnt = newstate.followEnt;
112 orbitEnt = newstate.orbitEnt;
113
114 followingpath = newstate.followingpath;
115}
116
117inline void CameraMoveState::Archive(Archiver& arc)
118{
119 arc.ArchiveVector(&movedir);
120 arc.ArchiveVector(&pos);
121 arc.ArchiveVector(&angles);
122
123 cameraPath.Archive(arc);
124
125 arc.ArchiveSafePointer(&splinePath);
126 arc.ArchiveSafePointer(&currentNode);
127 arc.ArchiveSafePointer(&loopNode);
128
129 arc.ArchiveFloat(&cameraTime);
130 arc.ArchiveInteger(&lastTime);
131 arc.ArchiveInteger(&newTime);
132
133 arc.ArchiveSafePointer(&followEnt);
134 arc.ArchiveSafePointer(&orbitEnt);
135
136 arc.ArchiveBoolean(&followingpath);
137}
138
139class CameraWatchState : public Class
140{
141public:
142 Vector watchAngles;
143
144 EntityPtr watchEnt;
145 qboolean watchNodes;
146 qboolean watchPath;
147
148 void Evaluate(Camera *camera, CameraMoveState *move);
149 void Initialize(Camera *camera);
150 void Archive(Archiver& arc) override;
151};
152
153inline void CameraWatchState::Archive(Archiver& arc)
154{
155 arc.ArchiveVector(&watchAngles);
156 arc.ArchiveSafePointer(&watchEnt);
157 arc.ArchiveBoolean(&watchNodes);
158 arc.ArchiveBoolean(&watchPath);
159}
160
161class CameraState : public Class
162{
163public:
164 CameraMoveState move;
165 CameraWatchState watch;
166 float fov;
167
168 void Evaluate(Camera *camera);
169 void Initialize(Camera *camera);
170 void Archive(Archiver& arc) override;
171};
172
173inline void CameraState::Archive(Archiver& arc)
174{
175 move.Archive(arc);
176 watch.Archive(arc);
177 arc.ArchiveFloat(&fov);
178}
179
180class Camera : public Entity
181{
182private:
183 friend class CameraState;
184 friend class CameraWatchState;
185 friend class CameraMoveState;
186 //
187 // follow parameters
188 //
189 float follow_yaw;
190 qboolean follow_yaw_fixed;
191 float follow_dist;
192 int follow_mask;
193
194 // camera speed
195 float camera_speed;
196 // current camera fov
197 float camera_fov;
198 // orbit height
199 float orbit_height;
200 // orbit_dotrace
201 qboolean orbit_dotrace;
202 // whether or not auto calculate fov, a non-zero value means yes
203 float auto_fov;
204
205 // automatic variables
206 float automatic_startTime;
207 float automatic_stopTime;
208 float automatic_radius;
209 float automatic_maxFOV;
210 qboolean automatic_active;
211 Container<str> automatic_states;
212
213 // Miscellaneous
214 Vector m_vPosOffset;
215
216protected:
217 CameraState currentstate;
218 CameraState newstate;
219
220 float watchTime; // if non-zero, camera view is transitioning
221 float followTime; // if non-zero, camera position is tranisitioning
222 float fovTime; // if non-zero, fov is being lerped
223
224 float fadeTime; // time to transition over
225 float fovFadeTime; // time for fov transition
226 float followFadeTime; // time for fov transition
227 float watchFadeTime; // time for fov transition
228
229 bool m_bShowquakes;
230
231 str nextCamera;
232
233 qboolean showcamera;
234
235 void SetupCamera(Event *ev);
236 void CameraThink(Event *ev);
237 void CreateOrbit(Vector pos, float radius, Vector& forward, Vector& left);
238 void CreatePath(SplinePath *path, splinetype_t type);
239 void UpdateStates(void);
240 Vector CalculatePosition(void);
241 Vector CalculateOrientation(void);
242 float CalculateFov(void);
243 virtual void bind(Entity *master, qboolean use_my_angles = false) override;
244 void unbind(void) override;
245
246public:
247 CLASS_PROTOTYPE(Camera);
248
249 Camera();
250 void Stop(void);
251 void FollowPath(SplinePath *path, qboolean loop, Entity *watch);
252 void Orbit(Entity *ent, float dist, Entity *watch, float yaw_offset = 0, qboolean dotrace = qtrue);
253 void FollowEntity(Entity *ent, float dist, int mask, Entity *watch = NULL);
254 void Watch(str watch, float time);
255 void Watch(Entity *ent, float time);
256 void SetFOV(float fov, float time);
257
258 void StartMoving(Event *ev);
259 void StopMoving(Event *ev);
260 void Pause(Event *ev);
261 void Continue(Event *ev);
262 void SetAnglesEvent(Event *ev);
263 void SetSpeed(Event *ev);
264 void SetFollowDistance(Event *ev);
265 void SetOrbitHeight(float height);
266 void SetOrbitHeight(Event *ev);
267 void SetFollowYaw(Event *ev);
268 void AbsoluteYaw(Event *ev);
269 void RelativeYaw(Event *ev);
270 void SetFOV(Event *ev);
271 void OrbitEvent(Event *ev);
272 void FollowEvent(Event *ev);
273 void WatchEvent(Event *ev);
274 void WatchStringEvent(Event *ev);
275 void WatchPathEvent(Event *ev);
276 void WatchNodesEvent(Event *ev);
277 void NoWatchEvent(Event *ev);
278 void EventShowQuakes(Event *ev);
279 void LookAt(Event *ev);
280 void MoveToEntity(Event *ev);
281 void MoveToPos(Event *ev);
282 void Cut(Event *ev);
283 void FadeTime(Event *ev);
284 void TurnTo(Event *ev);
285 void SetNextCamera(Event *ev);
286 float CalculateScore(Entity *player, str state);
287 float AutomaticStart(Entity *player);
288 float AutomaticStop(Entity *player);
289 qboolean IsAutomatic(void);
290 qboolean IsLevelExit(void);
291 void SetAutoStateEvent(Event *ev);
292 void SetAutoRadiusEvent(Event *ev);
293 void SetAutoStartTimeEvent(Event *ev);
294 void SetAutoStopTimeEvent(Event *ev);
295 void SetMaximumAutoFOVEvent(Event *ev);
296 void SetAutoActiveEvent(Event *ev);
297
298 str& NextCamera(void);
299 float Fov(void);
300
301 void Reset(Vector org, Vector ang);
302
303 bool ShowQuakes(void) const;
304 Vector GetPositionOffset(void);
305 void SetPositionOffset(Vector vNewOfs);
306
307 void Archive(Archiver& arc) override;
308};
309
310inline bool Camera::ShowQuakes(void) const
311{
312 return m_bShowquakes;
313}
314
315inline Vector Camera::GetPositionOffset(void)
316{
317 return m_vPosOffset;
318}
319
320inline void Camera::SetPositionOffset(Vector vNewOfs)
321{
322 m_vPosOffset = vNewOfs;
323}
324
325inline void Camera::Archive(Archiver& arc)
326{
327 Entity::Archive(arc);
328
329 arc.ArchiveFloat(&follow_yaw);
330 arc.ArchiveBoolean(&follow_yaw_fixed);
331 arc.ArchiveFloat(&follow_dist);
332 arc.ArchiveInteger(&follow_mask);
333
334 arc.ArchiveFloat(&camera_speed);
335 arc.ArchiveFloat(&camera_fov);
336 arc.ArchiveFloat(&orbit_height);
337 arc.ArchiveBoolean(&orbit_dotrace);
338 arc.ArchiveFloat(&auto_fov);
339
340 arc.ArchiveFloat(&automatic_startTime);
341 arc.ArchiveFloat(&automatic_stopTime);
342 arc.ArchiveFloat(&automatic_radius);
343 arc.ArchiveFloat(&automatic_maxFOV);
344 arc.ArchiveBoolean(&automatic_active);
345
346 automatic_states.Archive(arc);
347
348 // currentstate
349 currentstate.Archive(arc);
350 // newstate
351 newstate.Archive(arc);
352
353 arc.ArchiveFloat(&watchTime);
354 arc.ArchiveFloat(&followTime);
355 arc.ArchiveFloat(&fovTime);
356 arc.ArchiveFloat(&fadeTime);
357 arc.ArchiveFloat(&fovFadeTime);
358 arc.ArchiveFloat(&followFadeTime);
359 arc.ArchiveFloat(&watchFadeTime);
360
361 arc.ArchiveString(&nextCamera);
362
363 arc.ArchiveBoolean(&showcamera);
364
365 if (arc.Loading()) {
366 if (spawnflags & AUTOMATIC) {
367 level.AddAutomaticCamera(this);
368 }
369 }
370}
371
372void SetCamera(Entity *ent, float switchTime);
373Entity *GetWatchEntity(str watch);
374
375typedef SafePtr<Camera> CameraPtr;
376
377class CameraManager : public Listener
378{
379protected:
380 Container<str> pathList;
381 BSpline cameraPath;
382 SplinePathPtr path;
383 SplinePathPtr current;
384 float speed;
385 int watch;
386 str pathName;
387 CameraPtr cam;
388 qboolean cameraPath_dirty;
389
390 void NewPath(Event *ev);
391 void SetPath(Event *ev);
392 void SetTargetName(Event *ev);
393 void SetTarget(Event *ev);
394 void AddPoint(Event *ev);
395 void ReplacePoint(Event *ev);
396 void DeletePoint(Event *ev);
397 void MovePlayer(Event *ev);
398 void NextPoint(Event *ev);
399 void PreviousPoint(Event *ev);
400 void ShowingPath(Event *ev);
401 void ShowPath(Event *ev);
402 void HidePath(Event *ev);
403 void StopPlayback(Event *ev);
404 void PlayPath(Event *ev);
405 void LoopPath(Event *ev);
406 void Watch(Event *ev);
407 void NoWatch(Event *ev);
408 void Fov(Event *ev);
409 void FadeTime(Event *ev);
410 void Speed(Event *ev);
411 void Save(Event *ev);
412 void Load(Event *ev);
413 void SaveMap(Event *ev);
414 void UpdateEvent(Event *ev);
415 void NextPath(Event *ev);
416 void PreviousPath(Event *ev);
417 void RenamePath(Event *ev);
418
419 void ShowPath(void);
420 void UpdateUI(void);
421 void SetPathName(str name);
422 void SavePath(str pathName);
423
424public:
425 CLASS_PROTOTYPE(CameraManager);
426
427 CameraManager();
428 void SetPath(str pathName);
429 void Archive(Archiver& arc) override;
430};
431
432inline void CameraManager::Archive(Archiver& arc)
433{
434 Listener::Archive(arc);
435
436 pathList.Archive(arc);
437
438 // no need to archive the cameraPath
439 arc.ArchiveSafePointer(&path);
440 arc.ArchiveSafePointer(&current);
441 arc.ArchiveFloat(&speed);
442 arc.ArchiveInteger(&watch);
443 arc.ArchiveString(&pathName);
444 arc.ArchiveSafePointer(&cam);
445
446 // make sure the cameraPath gets rebuilt
447 cameraPath_dirty = qtrue;
448}
449
450extern CameraManager CameraMan;
Definition archive.h:86
Definition bspline.h:173
Definition camera.h:378
Definition camera.h:70
Definition camera.h:162
Definition camera.h:140
Definition camera.h:181
Definition container.h:85
Definition entity.h:203
Definition listener.h:246
Definition safeptr.h:160
Definition bspline.h:382
Definition vector.h:61
Definition str.h:77
Definition puff.c:88