Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.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 
46 {
71 };
72 
74 {
83 };
84 
85 enum CenteringPhase
86 {
87  CAM_PHASE_NULL = 0,
88  CAM_PHASE_START = 1,
89  CAM_PHASE_WAIT = 2,
90  CAM_PHASE_STOP = 3,
91 };
92 
94 {
109 };
110 
112 {
125 };
126 
127 
133 class CCamera {
134 public:
135  CCamera();
136  ~CCamera();
137 
139  bool EventProcess(const Event &event);
140 
142  void Init(Math::Vector eye, Math::Vector lookat, float delay);
143 
145  void SetControllingObject(CObject* object);
146  CObject* GetControllingObject();
147 
149  void SetType(CameraType type);
150  CameraType GetType();
151 
153  void SetSmooth(CameraSmooth type);
154  CameraSmooth GetSmoth();
155 
157  void SetDist(float dist);
158  float GetDist();
159 
161  void SetFixDirection(float angle);
162  float GetFixDirection();
163 
165  void SetRemotePan(float value);
166  float GetRemotePan();
167 
169  void SetRemoteZoom(float value);
170  float GetRemoteZoom();
171 
173  void StartVisit(Math::Vector goal, float dist);
175  void StopVisit();
176 
178  void GetCamera(Math::Vector &eye, Math::Vector &lookat);
179 
181  bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time);
183  bool StopCentering(CObject *object, float time);
185  void AbortCentering();
186 
188  void FlushEffect();
190  void StartEffect(CameraEffect effect, Math::Vector pos, float force);
191 
193  void FlushOver();
195  void SetOverBaseColor(Color color);
196  void StartOver(CameraOverEffect effect, Math::Vector pos, float force);
197 
199  void FixCamera();
200  void SetScriptEye(Math::Vector eye);
201  void SetScriptLookat(Math::Vector lookat);
202 
203  void SetEffect(bool enable);
204  void SetBlood(bool enable);
205  bool GetBlood();
206  void SetCameraScroll(bool scroll);
207  void SetCameraInvertX(bool invert);
208  void SetCameraInvertY(bool invert);
209 
211  float GetMotorTurn();
214 
215 protected:
217  bool EventMouseMove(const Event &event);
221  bool EventFrame(const Event &event);
223  bool EventFrameFree(const Event &event);
225  bool EventFrameEdit(const Event &event);
227  bool EventFrameDialog(const Event &event);
229  bool EventFrameBack(const Event &event);
231  bool EventFrameFix(const Event &event);
233  bool EventFrameExplo(const Event &event);
235  bool EventFrameOnBoard(const Event &event);
237  bool EventFrameInfo(const Event &event);
239  bool EventFrameVisit(const Event &event);
241  bool EventFrameScript(const Event &event);
242 
244  void SetViewTime(const Math::Vector &vEyePt, const Math::Vector &vLookatPt, float rTime);
246  bool IsCollision(Math::Vector &eye, Math::Vector lookat);
248  bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat);
250  bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat);
251 
253  Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
255  Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
256 
258  void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up);
260  void EffectFrame(const Event &event);
262  void OverFrame(const Event &event);
263 
264 protected:
265  CEngine* m_engine;
266  CRobotMain* m_main;
267  CTerrain* m_terrain;
268  CWater* m_water;
269  CInput* m_input;
270 
277 
281  float m_initDelay;
282 
295 
296  float m_focus;
297 
298  bool m_rightDown;
299  Math::Point m_rightPosInit;
300  Math::Point m_rightPosCenter;
301  Math::Point m_rightPosMove;
302 
310  float m_heightEye;
314  float m_speed;
315 
317  float m_backDist;
319  float m_backMin;
324  bool m_transparency;
325 
327  float m_fixDist;
332 
336  float m_visitDist;
338  float m_visitTime;
345 
348 
349  float m_remotePan;
350  float m_remoteZoom;
351 
352  Math::Point m_mousePos;
353  float m_mouseDirH;
354  float m_mouseDirV;
355  float m_mouseMarging;
356 
357  float m_motorTurn;
358 
359  CenteringPhase m_centeringPhase;
360  float m_centeringAngleH;
361  float m_centeringAngleV;
362  float m_centeringDist;
363  float m_centeringCurrentH;
364  float m_centeringCurrentV;
365  float m_centeringTime;
366  float m_centeringProgress;
367 
368  CameraEffect m_effectType;
369  Math::Vector m_effectPos;
370  float m_effectForce;
371  float m_effectProgress;
372  Math::Vector m_effectOffset;
373 
374  CameraOverEffect m_overType;
375  float m_overForce;
376  float m_overTime;
377  Color m_overColorBase;
378  Color m_overColor;
379  int m_overMode;
380  float m_overFadeIn;
381  float m_overFadeOut;
382 
383  Math::Vector m_scriptEye;
384  Math::Vector m_scriptLookat;
385 
387  bool m_effect;
389  bool m_blood;
396 
397 };
398 
399 
400 } // namespace Gfx
401 
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:788
float m_initDelay
Time of initial centering.
Definition: camera.h:281
void SetType(CameraType type)
Change the type of camera.
Definition: camera.cpp:239
CameraType
Type of camera.
Definition: camera.h:45
bool m_blood
Blood?
Definition: camera.h:389
Math::Vector m_eyePt
CAM_TYPE_FREE: eye.
Definition: camera.h:304
Vibration during construction.
Definition: camera.h:106
Math::Vector m_actualLookat
Current aim.
Definition: camera.h:286
Math::Vector m_visitGoal
CAM_TYPE_VISIT: target position.
Definition: camera.h:334
Static camera following robot.
Definition: camera.h:58
float m_editHeight
CAM_TYPE_EDIT: height.
Definition: camera.h:347
float m_fixDist
CAM_TYPE_FIX: distance.
Definition: camera.h:327
Main graphics engine - CEngine class.
Explosion.
Definition: camera.h:102
Camera behind a robot.
Definition: camera.h:56
void StopVisit()
Circular end of a visit with the camera.
Definition: camera.cpp:437
Free camera (? never in principle ?)
Definition: camera.h:50
bool EventFrameEdit(const Event &event)
Moves the point of view.
Definition: camera.cpp:1256
void EventMouseWheel(WheelDirection dir)
Mouse wheel operation.
Definition: camera.cpp:1039
bool EventFrameInfo(const Event &event)
Moves the point of view.
Definition: camera.cpp:1552
Math::Vector m_actualEye
Current eye.
Definition: camera.h:284
void StartVisit(Math::Vector goal, float dist)
Start with a tour round the camera.
Definition: camera.cpp:426
float m_visitDirectionH
CAM_TYPE_VISIT: direction.
Definition: camera.h:342
float m_speed
CAM_TYPE_FREE: speed of movement.
Definition: camera.h:314
Digging in.
Definition: camera.h:98
void AbortCentering()
Stop framing special in the current position.
Definition: camera.cpp:499
CameraOverEffect
Definition: camera.h:111
float m_backMin
CAM_TYPE_BACK: distance minimal.
Definition: camera.h:319
Math::Vector m_normLookat
Normal aim.
Definition: camera.h:294
CameraSmooth
Definition: camera.h:73
bool m_cameraInvertY
Y inversion in the edges?
Definition: camera.h:395
bool EventFrameDialog(const Event &event)
Moves the point of view.
Definition: camera.cpp:1298
float m_directionH
CAM_TYPE_FREE: horizontal direction.
Definition: camera.h:306
void SetControllingObject(CObject *object)
Sets the object controlling the camera.
Definition: camera.cpp:229
Lightning.
Definition: camera.h:124
Math::Vector m_normEye
Normal eye.
Definition: camera.h:292
float m_visitTime
CAM_TYPE_VISIT: relative time.
Definition: camera.h:338
bool EventFrameScript(const Event &event)
Moves the point of view.
Definition: camera.cpp:1605
bool EventFrameVisit(const Event &event)
Moves the point of view.
Definition: camera.cpp:1560
void SetSmooth(CameraSmooth type)
Management of the smoothing mode.
Definition: camera.cpp:362
? Vehicle driving is severely ?
Definition: camera.h:100
No effect.
Definition: camera.h:114
Definition: robotmain.h:172
void SetDist(float dist)
Management of the setback distance.
Definition: camera.cpp:372
Camera for displaying information.
Definition: camera.h:64
Sharp.
Definition: camera.h:76
bool IsCollision(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:865
bool EventFrameFree(const Event &event)
Moves the point of view.
Definition: camera.cpp:1193
void SetFixDirection(float angle)
Manage angle mode CAM_TYPE_FIX.
Definition: camera.cpp:382
void FlushEffect()
Removes the special effect with the camera.
Definition: camera.cpp:517
float m_addDirectionV
CAM_TYPE_BACK: additional direction.
Definition: camera.h:323
White -> nothing.
Definition: camera.h:118
CameraEffect
Definition: camera.h:93
bool StopCentering(CObject *object, float time)
Ends a special movement of camera to frame action.
Definition: camera.cpp:474
float m_visitDist
CAM_TYPE_VISIT: distance.
Definition: camera.h:336
Special.
Definition: camera.h:82
float m_heightLookat
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:312
CameraSmooth m_smooth
Type of smoothing.
Definition: camera.h:274
float m_directionV
CAM_TYPE_FREE: vertical direction.
Definition: camera.h:308
2D point
Definition: point.h:49
Math::Vector m_finalLookat
Final aim.
Definition: camera.h:290
float m_fixDirectionV
CAM_TYPE_FIX: direction.
Definition: camera.h:331
Camera while editing a program.
Definition: camera.h:52
void EffectFrame(const Event &event)
Advances the effect of the camera.
Definition: camera.cpp:535
float m_fixDirectionH
CAM_TYPE_FIX: direction.
Definition: camera.h:329
float m_addDirectionH
CAM_TYPE_BACK: additional direction.
Definition: camera.h:321
bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time)
Specifies a special movement of camera to frame action.
Definition: camera.cpp:448
Camera moving in 3D scene.
Definition: camera.h:133
float m_visitDirectionV
CAM_TYPE_VISIT: direction.
Definition: camera.h:344
Flash red.
Definition: camera.h:116
bool EventMouseMove(const Event &event)
Changes the camera according to the mouse moved.
Definition: camera.cpp:1033
Terrain loader/generator and manager.
Definition: terrain.h:222
void SetRemoteZoom(float value)
Management of the remote zoom (0 .. 1) of the camera.
Definition: camera.cpp:402
bool m_effect
Shocks if explosion?
Definition: camera.h:387
Normal.
Definition: camera.h:78
bool EventFrame(const Event &event)
Changes the camera according to the time elapsed.
Definition: camera.cpp:1091
EngineMouseType
Type of mouse cursor displayed in-game.
Definition: engine.h:510
Namespace for (new) graphics code.
Definition: app.h:49
bool m_cameraScroll
Scroll in the edges?
Definition: camera.h:391
Camera on board a robot.
Definition: camera.h:54
? Spleen reactor ?
Definition: camera.h:108
bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:967
The graphics engine.
Definition: engine.h:684
void SetOverBaseColor(Color color)
Specifies the base color.
Definition: camera.cpp:619
Visit instead of an error.
Definition: camera.h:66
Static camera height.
Definition: camera.h:70
Event types, structs and event queue.
CameraType m_type
The type of camera.
Definition: camera.h:272
No effect.
Definition: camera.h:96
Hard.
Definition: camera.h:80
bool EventFrameOnBoard(const Event &event)
Moves the point of view.
Definition: camera.cpp:1535
Nothing -> blue.
Definition: camera.h:122
Camera during a film script.
Definition: camera.h:62
Water manager/renderer.
Definition: water.h:118
bool EventFrameFix(const Event &event)
Moves the point of view.
Definition: camera.cpp:1458
bool EventFrameExplo(const Event &event)
Moves the point of view.
Definition: camera.cpp:1504
bool EventProcess(const Event &event)
Management of an event.
Definition: camera.cpp:1011
Math::Vector m_finalEye
Final eye.
Definition: camera.h:288
bool EventFrameBack(const Event &event)
Moves the point of view.
Definition: camera.cpp:1303
CameraType m_visitType
CAM_TYPE_VISIT: initial type.
Definition: camera.h:340
float GetMotorTurn()
Returns an additional force to turn.
Definition: camera.cpp:183
3D (3x1) vector
Definition: vector.h:52
EngineMouseType GetMouseDef(Math::Point pos)
Returns the default sprite to use for the mouse.
Definition: camera.cpp:1130
CObject * m_cameraObj
Object linked to the camera.
Definition: camera.h:276
void OverFrame(const Event &event)
Advanced overlay effect in the foreground.
Definition: camera.cpp:692
Undefined.
Definition: camera.h:48
float m_backDist
CAM_TYPE_BACK: distance.
Definition: camera.h:317
void FlushOver()
Removes the effect of superposition in the foreground.
Definition: camera.cpp:612
void Init(Math::Vector eye, Math::Vector lookat, float delay)
Initializes the camera.
Definition: camera.cpp:190
float m_heightEye
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:310
RGBA color.
Definition: color.h:38
Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV)
Adjusts the camera not to enter an object.
Definition: camera.cpp:1651
Camera steady after explosion.
Definition: camera.h:60
Event sent by system, interface or game.
Definition: event.h:678
float m_eyeDistance
Distance between the eyes.
Definition: camera.h:279
? Not mortal shot ?
Definition: camera.h:104
void StartEffect(CameraEffect effect, Math::Vector pos, float force)
Starts a special effect with the camera.
Definition: camera.cpp:525
Definition: object.h:357
WheelDirection
Direction of mouse wheel movement.
Definition: event.h:601
bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:873
void GetCamera(Math::Vector &eye, Math::Vector &lookat)
Returns the point of view of the camera.
Definition: camera.cpp:442
Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV)
Adjusts the camera not to enter the ground.
Definition: camera.cpp:1634
bool m_cameraInvertX
X inversion in the edges?
Definition: camera.h:393
void SetRemotePan(float value)
Managing the triggering mode of the camera panning.
Definition: camera.cpp:392
void FixCamera()
Sets the soft movement of the camera.
Definition: camera.cpp:780
Management of mouse, keyboard and joystick.
Definition: input.h:68
Camera for dialog.
Definition: camera.h:68
Nothing -> white.
Definition: camera.h:120
void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up)
Specifies the location and direction of view.
Definition: camera.cpp:1622