Colobot
camera.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 #include "graphics/engine/engine.h"
28 
29 
30 class CObject;
31 class CRobotMain;
32 class CInput;
33 struct Event;
34 
35 
36 // Graphics module namespace
37 namespace Gfx
38 {
39 
40 
45 {
66 };
67 
69 {
76 };
77 
78 enum CenteringPhase
79 {
80  CAM_PHASE_NULL = 0,
81  CAM_PHASE_START = 1,
82  CAM_PHASE_WAIT = 2,
83  CAM_PHASE_STOP = 3,
84 };
85 
87 {
102 };
103 
105 {
118 };
119 
120 
128 class CCamera
129 {
130 public:
131  CCamera();
132  ~CCamera();
133 
135  bool EventProcess(const Event &event);
136 
143  void Init(Math::Vector eye, Math::Vector lookat, float delay);
144 
146  void SetControllingObject(CObject* object);
149 
151  void SetType(CameraType type);
154 
156  void SetSmooth(CameraSmooth type);
159 
160 
162  void GetCamera(Math::Vector &eye, Math::Vector &lookat);
163 
165 
166  void StartVisit(Math::Vector goal, float dist);
169  void StopVisit();
171 
173 
174  bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time);
177  bool StopCentering(CObject *object, float time);
179  void AbortCentering();
181 
183 
184  void StartEffect(CameraEffect effect, Math::Vector pos, float force);
187  void FlushEffect();
189 
191 
192  void StartOver(CameraOverEffect effect, Math::Vector pos, float force);
195  void FlushOver();
197  void SetOverBaseColor(Color color);
199 
201 
202  void SetScriptCamera(Math::Vector eye, Math::Vector lookat);
211 
213 
214  void SetEffect(bool enable);
215  bool GetEffect();
216  void SetBlood(bool enable);
217  bool GetBlood();
218  void SetOldCameraScroll(bool scroll);
219  bool GetOldCameraScroll();
220  void SetCameraInvertX(bool invert);
221  bool GetCameraInvertX();
222  void SetCameraInvertY(bool invert);
223  bool GetCameraInvertY();
225 
227  void SetFreeze(bool freeze);
228 
230  void SetCameraSpeed(float speed);
231 
232 protected:
234  void EffectFrame(const Event &event);
236  void OverFrame(const Event &event);
237 
238  bool EventFrameFree(const Event &event, bool keysAllowed);
239  bool EventFrameBack(const Event &event);
240  bool EventFrameFix(const Event &event);
241  bool EventFrameExplo(const Event &event);
242  bool EventFrameOnBoard(const Event &event);
243  bool EventFrameVisit(const Event &event);
244  bool EventFrameScript(const Event &event);
245 
253  void UpdateCameraAnimation(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime);
254 
264  void IsCollision(Math::Vector &eye, Math::Vector lookat);
266  void IsCollisionBack();
268  void IsCollisionFix(Math::Vector &eye, Math::Vector lookat);
269 
271  Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
273  Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
274 
282  void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up = Math::Vector(0.0f, 1.0f, 0.0f));
283 
289  Math::Vector CalculateCameraMovement(const Event &event, bool keysAllowed = true);
290 
291 protected:
292  CEngine* m_engine;
293  CRobotMain* m_main;
294  CTerrain* m_terrain;
295  CWater* m_water;
296  CInput* m_input;
297 
304 
306  float m_initDelay;
307 
320 
321  float m_focus;
322 
330  float m_heightEye;
334  float m_speed;
335 
337  float m_backDist;
339  float m_backMin;
344 
346  float m_fixDist;
351 
355  float m_visitDist;
357  float m_visitTime;
362 
370  float m_mouseWheelDelta = 0.0f;
371 
372  CenteringPhase m_centeringPhase;
373  float m_centeringAngleH;
374  float m_centeringAngleV;
375  float m_centeringDist;
376  float m_centeringCurrentH;
377  float m_centeringCurrentV;
378  float m_centeringTime;
379  float m_centeringProgress;
380 
381  CameraEffect m_effectType;
382  Math::Vector m_effectPos;
383  float m_effectForce;
384  float m_effectProgress;
385  Math::Vector m_effectOffset;
386 
387  CameraOverEffect m_overType;
388  float m_overForce;
389  float m_overTime;
390  Color m_overColorBase;
391  Color m_overColor;
392  int m_overMode;
393  float m_overFadeIn;
394  float m_overFadeOut;
395 
396  Math::Vector m_scriptEye;
397  Math::Vector m_scriptLookat;
398 
400  bool m_freeze = false;
401 
403 
404  bool m_effect;
405  bool m_blood;
406  bool m_oldCameraScroll;
407  bool m_cameraInvertX;
408  bool m_cameraInvertY;
410 };
411 
412 
413 } // namespace Gfx
float m_initDelay
Remaining time of initial camera entry animation.
Definition: camera.h:306
void SetFreeze(bool freeze)
Temporarily freeze camera movement.
Definition: camera.cpp:1485
void SetType(CameraType type)
Change the type of camera.
Definition: camera.cpp:255
CameraType
Type of camera.
Definition: camera.h:44
CameraType GetType()
Get the type of the camera.
Definition: camera.cpp:365
Math::Vector m_eyePt
CAM_TYPE_FREE: eye.
Definition: camera.h:324
Vibration during construction.
Definition: camera.h:99
Math::Vector m_actualLookat
Current aim.
Definition: camera.h:311
Math::Vector m_visitGoal
CAM_TYPE_VISIT: target position.
Definition: camera.h:353
Static camera following robot.
Definition: camera.h:57
float m_fixDist
CAM_TYPE_FIX: distance.
Definition: camera.h:346
Main graphics engine - CEngine class.
Explosion.
Definition: camera.h:95
Camera behind a robot.
Definition: camera.h:55
void StopVisit()
Stop visit camera.
Definition: camera.cpp:390
Free camera.
Definition: camera.h:49
void IsCollisionBack()
Avoid the obstacles (CAM_TYPE_BACK)
Definition: camera.cpp:818
Math::Vector m_actualEye
Current eye.
Definition: camera.h:309
void StartOver(CameraOverEffect effect, Math::Vector pos, float force)
Starts camera overlay effect.
Definition: camera.cpp:596
Math::Point m_mousePos
Last known mouse position, used to calculate change since last frame.
Definition: camera.h:364
void SetScriptCamera(Math::Vector eye, Math::Vector lookat)
Script camera: Set camera position.
Definition: camera.cpp:1381
void StartVisit(Math::Vector goal, float dist)
Start visit camera.
Definition: camera.cpp:380
Math::Vector m_prevEye
Eye position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT.
Definition: camera.h:317
float m_speed
CAM_TYPE_FREE: speed of movement.
Definition: camera.h:334
Digging in.
Definition: camera.h:91
void AbortCentering()
Abort centering animation in the current position.
Definition: camera.cpp:452
CameraOverEffect
Definition: camera.h:104
float m_backMin
CAM_TYPE_BACK: minimal distance.
Definition: camera.h:339
CameraSmooth
Definition: camera.h:68
float m_directionH
CAM_TYPE_FREE: horizontal direction.
Definition: camera.h:326
void SetControllingObject(CObject *object)
Sets the object controlling the camera.
Definition: camera.cpp:245
Lightning.
Definition: camera.h:117
void IsCollision(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:811
void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up=Math::Vector(0.0f, 1.0f, 0.0f))
Updates the location and direction of the camera in the 3D engine.
Definition: camera.cpp:1396
float m_visitTime
CAM_TYPE_VISIT: relative time.
Definition: camera.h:357
bool m_freeze
Is camera frozen?
Definition: camera.h:400
void SetSmooth(CameraSmooth type)
Set smoothing mode.
Definition: camera.cpp:370
Hard landing.
Definition: camera.h:93
No effect.
Definition: camera.h:107
Definition: robotmain.h:159
CameraSmooth GetSmooth()
Get smoothing mode.
Definition: camera.cpp:375
Sharp.
Definition: camera.h:71
void FlushEffect()
Removes the camera shake effect.
Definition: camera.cpp:469
float m_addDirectionV
CAM_TYPE_BACK: additional vertical direction.
Definition: camera.h:343
White -> nothing.
Definition: camera.h:111
CameraEffect
Definition: camera.h:86
bool StopCentering(CObject *object, float time)
Go back to normal position after showing some happening action.
Definition: camera.cpp:427
Math::Vector CalculateCameraMovement(const Event &event, bool keysAllowed=true)
Calculate camera movement (from user inputs) to apply.
Definition: camera.cpp:1454
float m_visitDist
CAM_TYPE_VISIT: distance.
Definition: camera.h:355
CObject * GetControllingObject()
Gets the object controlling the camera.
Definition: camera.cpp:250
Math::Point m_mouseDelta
Change of mouse position since last frame.
Definition: camera.h:366
float m_mouseWheelDelta
Change of mouse wheel since last frame.
Definition: camera.h:370
float m_heightLookat
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:332
CameraSmooth m_smooth
Type of smoothing.
Definition: camera.h:301
float m_directionV
CAM_TYPE_FREE: vertical direction.
Definition: camera.h:328
2D point
Definition: point.h:50
Math::Vector m_finalLookat
Final lookat.
Definition: camera.h:315
void SetScriptCameraAnimate(Math::Vector eye, Math::Vector lookat)
Script camera: Animate to given camera position.
Definition: camera.cpp:1390
float m_fixDirectionV
CAM_TYPE_FIX: vertical direction.
Definition: camera.h:350
Camera while editing a program.
Definition: camera.h:51
void EffectFrame(const Event &event)
Advances the effect of the camera.
Definition: camera.cpp:489
void SetCameraSpeed(float speed)
Set camera speed.
Definition: camera.cpp:1449
Math::Vector m_prevLookat
Lookat position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT.
Definition: camera.h:319
float m_fixDirectionH
CAM_TYPE_FIX: horizontal direction.
Definition: camera.h:348
float m_addDirectionH
CAM_TYPE_BACK: additional horizontal direction.
Definition: camera.h:341
void IsCollisionFix(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles (CAM_TYPE_FIX or CAM_TYPE_PLANE)
Definition: camera.cpp:905
bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time)
Move camera to show happening action.
Definition: camera.cpp:401
Camera moving in 3D scene.
Definition: camera.h:128
float m_visitDirectionV
CAM_TYPE_VISIT: direction.
Definition: camera.h:361
Flash red.
Definition: camera.h:109
Terrain loader/generator and manager.
Definition: terrain.h:147
Normal.
Definition: camera.h:73
void SetScriptCameraAnimateLookat(Math::Vector lookat)
Script camera: Animate to given lookat position.
Definition: camera.cpp:1376
Namespace for (new) graphics code.
Definition: app.h:49
Camera on board a robot.
Definition: camera.h:53
Overheated reactor.
Definition: camera.h:101
The graphics engine.
Definition: engine.h:585
void SetOverBaseColor(Color color)
Specifies camera overlay effect base color.
Definition: camera.cpp:591
Visit camera, rotates around given position.
Definition: camera.h:63
Static camera height.
Definition: camera.h:65
CameraType m_type
The type of camera.
Definition: camera.h:299
No effect.
Definition: camera.h:89
Hard.
Definition: camera.h:75
void UpdateCameraAnimation(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime)
Calculates camera animation and sends updated camera position to the 3D engine.
Definition: camera.cpp:751
Nothing -> blue.
Definition: camera.h:115
Camera during a cutscene.
Definition: camera.h:61
Water manager/renderer.
Definition: water.h:72
bool EventProcess(const Event &event)
Management of an event.
Definition: camera.cpp:945
Math::Vector m_finalEye
Final eye.
Definition: camera.h:313
CameraType m_visitType
CAM_TYPE_VISIT: initial type.
Definition: camera.h:359
Math::Point m_mouseDeltaEdge
Change of camera position caused by edge camera.
Definition: camera.h:368
3D (3x1) vector
Definition: vector.h:53
CObject * m_cameraObj
Object linked to the camera.
Definition: camera.h:303
void OverFrame(const Event &event)
Advanced overlay effect in the foreground.
Definition: camera.cpp:664
Undefined.
Definition: camera.h:47
float m_backDist
CAM_TYPE_BACK: distance.
Definition: camera.h:337
void FlushOver()
Removes camera overlay effect.
Definition: camera.cpp:584
void Init(Math::Vector eye, Math::Vector lookat, float delay)
Initializes the camera.
Definition: camera.cpp:209
float m_heightEye
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:330
RGBA color.
Definition: color.h:39
Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV)
Adjusts the camera not to enter an object.
Definition: camera.cpp:1422
void SetScriptCameraAnimateEye(Math::Vector eye)
Script camera: Animate to given eye position.
Definition: camera.cpp:1371
Camera steady after explosion.
Definition: camera.h:59
Event sent by system, interface or game.
Definition: event.h:735
Shot by an enemy.
Definition: camera.h:97
void StartEffect(CameraEffect effect, Math::Vector pos, float force)
Starts a camera shake effect.
Definition: camera.cpp:479
Base class for all 3D in-game objects.
Definition: object.h:63
void GetCamera(Math::Vector &eye, Math::Vector &lookat)
Returns the current point of view of the camera.
Definition: camera.cpp:395
Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV)
Adjusts the camera not to enter the ground.
Definition: camera.cpp:1405
Management of mouse, keyboard and joystick.
Definition: input.h:71
Nothing -> white.
Definition: camera.h:113