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-2015, 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 
28 #include "common/event.h"
29 
30 #include "graphics/engine/engine.h"
31 
32 
33 class CObject;
34 class CRobotMain;
35 class CInput;
36 
37 
38 // Graphics module namespace
39 namespace Gfx
40 {
41 
42 
47 {
72 };
73 
75 {
84 };
85 
86 enum CenteringPhase
87 {
88  CAM_PHASE_NULL = 0,
89  CAM_PHASE_START = 1,
90  CAM_PHASE_WAIT = 2,
91  CAM_PHASE_STOP = 3,
92 };
93 
95 {
110 };
111 
113 {
126 };
127 
128 
134 class CCamera
135 {
136 public:
137  CCamera();
138  ~CCamera();
139 
141  bool EventProcess(const Event &event);
142 
144  void Init(Math::Vector eye, Math::Vector lookat, float delay);
145 
147  void SetControllingObject(CObject* object);
148  CObject* GetControllingObject();
149 
151  void SetType(CameraType type);
152  CameraType GetType();
153 
155  void SetSmooth(CameraSmooth type);
156  CameraSmooth GetSmoth();
157 
159  void SetDist(float dist);
160  float GetDist();
161 
163  void SetFixDirectionH(float angle);
164  float GetFixDirectionH();
165  void SetFixDirectionV(float angle);
166  float GetFixDirectionV();
167 
169  void SetRemotePan(float value);
170  float GetRemotePan();
171 
173  void SetRemoteZoom(float value);
174  float GetRemoteZoom();
175 
177  void StartVisit(Math::Vector goal, float dist);
179  void StopVisit();
180 
182  void GetCamera(Math::Vector &eye, Math::Vector &lookat);
183 
185  bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time);
187  bool StopCentering(CObject *object, float time);
189  void AbortCentering();
190 
192  void FlushEffect();
194  void StartEffect(CameraEffect effect, Math::Vector pos, float force);
195 
197  void FlushOver();
199  void SetOverBaseColor(Color color);
200  void StartOver(CameraOverEffect effect, Math::Vector pos, float force);
201 
203  void FixCamera();
204  void SetScriptEye(Math::Vector eye);
205  void SetScriptLookat(Math::Vector lookat);
206 
207  void SetEffect(bool enable);
208  bool GetEffect();
209  void SetBlood(bool enable);
210  bool GetBlood();
211  void SetCameraScroll(bool scroll);
212  bool GetCameraScroll();
213  void SetCameraInvertX(bool invert);
214  bool GetCameraInvertX();
215  void SetCameraInvertY(bool invert);
216  bool GetCameraInvertY();
217 
219  float GetMotorTurn();
222 
223  void SetCameraSpeed(float speed);
224 
225 protected:
227  bool EventMouseMove(const Event &event);
231  bool EventFrame(const Event &event);
233  bool EventFrameFree(const Event &event);
235  bool EventFrameEdit(const Event &event);
237  bool EventFrameDialog(const Event &event);
239  bool EventFrameBack(const Event &event);
241  bool EventFrameFix(const Event &event);
243  bool EventFrameExplo(const Event &event);
245  bool EventFrameOnBoard(const Event &event);
247  bool EventFrameInfo(const Event &event);
249  bool EventFrameVisit(const Event &event);
251  bool EventFrameScript(const Event &event);
252 
254  void SetViewTime(const Math::Vector &vEyePt, const Math::Vector &vLookatPt, float rTime);
256  bool IsCollision(Math::Vector &eye, Math::Vector lookat);
258  bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat);
260  bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat);
261 
263  Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
265  Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
266 
268  void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up);
270  void EffectFrame(const Event &event);
272  void OverFrame(const Event &event);
273 
274 protected:
275  CEngine* m_engine;
276  CRobotMain* m_main;
277  CTerrain* m_terrain;
278  CWater* m_water;
279  CInput* m_input;
280 
287 
291  float m_initDelay;
292 
305 
306  float m_focus;
307 
308  bool m_rightDown;
309  Math::Point m_rightPosInit;
310  Math::Point m_rightPosCenter;
311  Math::Point m_rightPosMove;
312 
320  float m_heightEye;
324  float m_speed;
325 
327  float m_backDist;
329  float m_backMin;
334  bool m_transparency;
335 
337  float m_fixDist;
342 
346  float m_visitDist;
348  float m_visitTime;
355 
358 
359  float m_remotePan;
360  float m_remoteZoom;
361 
362  Math::Point m_mousePos;
363  float m_mouseDirH;
364  float m_mouseDirV;
365  float m_mouseMarging;
366 
367  float m_motorTurn;
368 
369  CenteringPhase m_centeringPhase;
370  float m_centeringAngleH;
371  float m_centeringAngleV;
372  float m_centeringDist;
373  float m_centeringCurrentH;
374  float m_centeringCurrentV;
375  float m_centeringTime;
376  float m_centeringProgress;
377 
378  CameraEffect m_effectType;
379  Math::Vector m_effectPos;
380  float m_effectForce;
381  float m_effectProgress;
382  Math::Vector m_effectOffset;
383 
384  CameraOverEffect m_overType;
385  float m_overForce;
386  float m_overTime;
387  Color m_overColorBase;
388  Color m_overColor;
389  int m_overMode;
390  float m_overFadeIn;
391  float m_overFadeOut;
392 
393  Math::Vector m_scriptEye;
394  Math::Vector m_scriptLookat;
395 
397  bool m_effect;
399  bool m_blood;
406 
407 };
408 
409 
410 } // namespace Gfx
void SetViewTime(const Math::Vector &vEyePt, const Math::Vector &vLookatPt, float rTime)
Specifies the location and direction of view to the 3D engine.
Definition: camera.cpp:838
float m_initDelay
Time of initial centering.
Definition: camera.h:291
void SetType(CameraType type)
Change the type of camera.
Definition: camera.cpp:281
CameraType
Type of camera.
Definition: camera.h:46
bool m_blood
Blood?
Definition: camera.h:399
Math::Vector m_eyePt
CAM_TYPE_FREE: eye.
Definition: camera.h:314
Vibration during construction.
Definition: camera.h:107
Math::Vector m_actualLookat
Current aim.
Definition: camera.h:296
Math::Vector m_visitGoal
CAM_TYPE_VISIT: target position.
Definition: camera.h:344
Static camera following robot.
Definition: camera.h:59
float m_editHeight
CAM_TYPE_EDIT: height.
Definition: camera.h:357
float m_fixDist
CAM_TYPE_FIX: distance.
Definition: camera.h:337
Main graphics engine - CEngine class.
Explosion.
Definition: camera.h:103
Camera behind a robot.
Definition: camera.h:57
void StopVisit()
Circular end of a visit with the camera.
Definition: camera.cpp:487
Free camera (? never in principle ?)
Definition: camera.h:51
bool EventFrameEdit(const Event &event)
Moves the point of view.
Definition: camera.cpp:1316
void EventMouseWheel(WheelDirection dir)
Mouse wheel operation.
Definition: camera.cpp:1083
bool EventFrameInfo(const Event &event)
Moves the point of view.
Definition: camera.cpp:1619
Math::Vector m_actualEye
Current eye.
Definition: camera.h:294
void StartVisit(Math::Vector goal, float dist)
Start with a tour round the camera.
Definition: camera.cpp:476
float m_visitDirectionH
CAM_TYPE_VISIT: direction.
Definition: camera.h:352
float m_speed
CAM_TYPE_FREE: speed of movement.
Definition: camera.h:324
Digging in.
Definition: camera.h:99
void AbortCentering()
Stop framing special in the current position.
Definition: camera.cpp:549
CameraOverEffect
Definition: camera.h:112
float m_backMin
CAM_TYPE_BACK: distance minimal.
Definition: camera.h:329
Math::Vector m_normLookat
Normal aim.
Definition: camera.h:304
CameraSmooth
Definition: camera.h:74
bool m_cameraInvertY
Y inversion in the edges?
Definition: camera.h:405
bool EventFrameDialog(const Event &event)
Moves the point of view.
Definition: camera.cpp:1358
float m_directionH
CAM_TYPE_FREE: horizontal direction.
Definition: camera.h:316
void SetControllingObject(CObject *object)
Sets the object controlling the camera.
Definition: camera.cpp:271
Lightning.
Definition: camera.h:125
void SetFixDirectionH(float angle)
Manage angle mode CAM_TYPE_FIX.
Definition: camera.cpp:422
Math::Vector m_normEye
Normal eye.
Definition: camera.h:302
float m_visitTime
CAM_TYPE_VISIT: relative time.
Definition: camera.h:348
bool EventFrameScript(const Event &event)
Moves the point of view.
Definition: camera.cpp:1672
bool EventFrameVisit(const Event &event)
Moves the point of view.
Definition: camera.cpp:1627
void SetSmooth(CameraSmooth type)
Management of the smoothing mode.
Definition: camera.cpp:402
? Vehicle driving is severely ?
Definition: camera.h:101
No effect.
Definition: camera.h:115
Definition: robotmain.h:151
void SetDist(float dist)
Management of the setback distance.
Definition: camera.cpp:412
Camera for displaying information.
Definition: camera.h:65
Sharp.
Definition: camera.h:77
bool IsCollision(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:915
bool EventFrameFree(const Event &event)
Moves the point of view.
Definition: camera.cpp:1237
void FlushEffect()
Removes the special effect with the camera.
Definition: camera.cpp:567
float m_addDirectionV
CAM_TYPE_BACK: additional direction.
Definition: camera.h:333
White -> nothing.
Definition: camera.h:119
CameraEffect
Definition: camera.h:94
bool StopCentering(CObject *object, float time)
Ends a special movement of camera to frame action.
Definition: camera.cpp:524
float m_visitDist
CAM_TYPE_VISIT: distance.
Definition: camera.h:346
Special.
Definition: camera.h:83
float m_heightLookat
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:322
CameraSmooth m_smooth
Type of smoothing.
Definition: camera.h:284
float m_directionV
CAM_TYPE_FREE: vertical direction.
Definition: camera.h:318
2D point
Definition: point.h:50
Math::Vector m_finalLookat
Final aim.
Definition: camera.h:300
float m_fixDirectionV
CAM_TYPE_FIX: direction.
Definition: camera.h:341
Camera while editing a program.
Definition: camera.h:53
void EffectFrame(const Event &event)
Advances the effect of the camera.
Definition: camera.cpp:585
float m_fixDirectionH
CAM_TYPE_FIX: direction.
Definition: camera.h:339
float m_addDirectionH
CAM_TYPE_BACK: additional direction.
Definition: camera.h:331
bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time)
Specifies a special movement of camera to frame action.
Definition: camera.cpp:498
Camera moving in 3D scene.
Definition: camera.h:134
float m_visitDirectionV
CAM_TYPE_VISIT: direction.
Definition: camera.h:354
Flash red.
Definition: camera.h:117
bool EventMouseMove(const Event &event)
Changes the camera according to the mouse moved.
Definition: camera.cpp:1077
Terrain loader/generator and manager.
Definition: terrain.h:145
void SetRemoteZoom(float value)
Management of the remote zoom (0 .. 1) of the camera.
Definition: camera.cpp:452
bool m_effect
Shocks if explosion?
Definition: camera.h:397
Normal.
Definition: camera.h:79
bool EventFrame(const Event &event)
Changes the camera according to the time elapsed.
Definition: camera.cpp:1135
EngineMouseType
Type of mouse cursor displayed in-game.
Definition: engine.h:445
Namespace for (new) graphics code.
Definition: app.h:49
bool m_cameraScroll
Scroll in the edges?
Definition: camera.h:401
Camera on board a robot.
Definition: camera.h:55
? Spleen reactor ?
Definition: camera.h:109
bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:1014
The graphics engine.
Definition: engine.h:620
void SetOverBaseColor(Color color)
Specifies the base color.
Definition: camera.cpp:669
Visit instead of an error.
Definition: camera.h:67
Static camera height.
Definition: camera.h:71
Event types, structs and event queue.
CameraType m_type
The type of camera.
Definition: camera.h:282
No effect.
Definition: camera.h:97
Hard.
Definition: camera.h:81
bool EventFrameOnBoard(const Event &event)
Moves the point of view.
Definition: camera.cpp:1602
Nothing -> blue.
Definition: camera.h:123
Camera during a film script.
Definition: camera.h:63
Water manager/renderer.
Definition: water.h:74
bool EventFrameFix(const Event &event)
Moves the point of view.
Definition: camera.cpp:1520
bool EventFrameExplo(const Event &event)
Moves the point of view.
Definition: camera.cpp:1571
bool EventProcess(const Event &event)
Management of an event.
Definition: camera.cpp:1055
Math::Vector m_finalEye
Final eye.
Definition: camera.h:298
bool EventFrameBack(const Event &event)
Moves the point of view.
Definition: camera.cpp:1363
CameraType m_visitType
CAM_TYPE_VISIT: initial type.
Definition: camera.h:350
float GetMotorTurn()
Returns an additional force to turn.
Definition: camera.cpp:225
3D (3x1) vector
Definition: vector.h:53
EngineMouseType GetMouseDef(Math::Point pos)
Returns the default sprite to use for the mouse.
Definition: camera.cpp:1174
CObject * m_cameraObj
Object linked to the camera.
Definition: camera.h:286
void OverFrame(const Event &event)
Advanced overlay effect in the foreground.
Definition: camera.cpp:742
Undefined.
Definition: camera.h:49
float m_backDist
CAM_TYPE_BACK: distance.
Definition: camera.h:327
void FlushOver()
Removes the effect of superposition in the foreground.
Definition: camera.cpp:662
void Init(Math::Vector eye, Math::Vector lookat, float delay)
Initializes the camera.
Definition: camera.cpp:232
float m_heightEye
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:320
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:1718
Camera steady after explosion.
Definition: camera.h:61
Event sent by system, interface or game.
Definition: event.h:709
float m_eyeDistance
Distance between the eyes.
Definition: camera.h:289
? Not mortal shot ?
Definition: camera.h:105
void StartEffect(CameraEffect effect, Math::Vector pos, float force)
Starts a special effect with the camera.
Definition: camera.cpp:575
Base class for all 3D in-game objects.
Definition: object.h:59
WheelDirection
Direction of mouse wheel movement.
Definition: event.h:613
bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:923
void GetCamera(Math::Vector &eye, Math::Vector &lookat)
Returns the point of view of the camera.
Definition: camera.cpp:492
Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV)
Adjusts the camera not to enter the ground.
Definition: camera.cpp:1701
bool m_cameraInvertX
X inversion in the edges?
Definition: camera.h:403
void SetRemotePan(float value)
Managing the triggering mode of the camera panning.
Definition: camera.cpp:442
void FixCamera()
Sets the soft movement of the camera.
Definition: camera.cpp:830
Management of mouse, keyboard and joystick.
Definition: input.h:68
Camera for dialog.
Definition: camera.h:69
Nothing -> white.
Definition: camera.h:121
void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up)
Specifies the location and direction of view.
Definition: camera.cpp:1689