Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
camera.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
3 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
4 // *
5 // * This program is free software: you can redistribute it and/or modify
6 // * it under the terms of the GNU General Public License as published by
7 // * the Free Software Foundation, either version 3 of the License, or
8 // * (at your option) any later version.
9 // *
10 // * This program is distributed in the hope that it will be useful,
11 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // * GNU General Public License for more details.
14 // *
15 // * You should have received a copy of the GNU General Public License
16 // * along with this program. If not, see http://www.gnu.org/licenses/.
17 
23 #pragma once
24 
25 
26 #include "common/event.h"
27 
28 #include "graphics/engine/engine.h"
29 
30 
31 class CObject;
32 class CRobotMain;
33 
34 
35 // Graphics module namespace
36 namespace Gfx {
37 
38 
43 {
68 };
69 
71 {
80 };
81 
82 enum CenteringPhase
83 {
84  CAM_PHASE_NULL = 0,
85  CAM_PHASE_START = 1,
86  CAM_PHASE_WAIT = 2,
87  CAM_PHASE_STOP = 3,
88 };
89 
91 {
106 };
107 
109 {
122 };
123 
124 
130 class CCamera {
131 public:
132  CCamera();
133  ~CCamera();
134 
136  bool EventProcess(const Event &event);
137 
139  void Init(Math::Vector eye, Math::Vector lookat, float delay);
140 
142  void SetControllingObject(CObject* object);
143  CObject* GetControllingObject();
144 
146  void SetType(CameraType type);
147  CameraType GetType();
148 
150  void SetSmooth(CameraSmooth type);
151  CameraSmooth GetSmoth();
152 
154  void SetDist(float dist);
155  float GetDist();
156 
158  void SetFixDirection(float angle);
159  float GetFixDirection();
160 
162  void SetRemotePan(float value);
163  float GetRemotePan();
164 
166  void SetRemoteZoom(float value);
167  float GetRemoteZoom();
168 
170  void StartVisit(Math::Vector goal, float dist);
172  void StopVisit();
173 
175  void GetCamera(Math::Vector &eye, Math::Vector &lookat);
176 
178  bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time);
180  bool StopCentering(CObject *object, float time);
182  void AbortCentering();
183 
185  void FlushEffect();
187  void StartEffect(CameraEffect effect, Math::Vector pos, float force);
188 
190  void FlushOver();
192  void SetOverBaseColor(Color color);
193  void StartOver(CameraOverEffect effect, Math::Vector pos, float force);
194 
196  void FixCamera();
197  void SetScriptEye(Math::Vector eye);
198  void SetScriptLookat(Math::Vector lookat);
199 
200  void SetEffect(bool enable);
201  void SetCameraScroll(bool scroll);
202  void SetCameraInvertX(bool invert);
203  void SetCameraInvertY(bool invert);
204 
206  float GetMotorTurn();
209 
210 protected:
212  bool EventMouseMove(const Event &event);
216  bool EventFrame(const Event &event);
218  bool EventFrameFree(const Event &event);
220  bool EventFrameEdit(const Event &event);
222  bool EventFrameDialog(const Event &event);
224  bool EventFrameBack(const Event &event);
226  bool EventFrameFix(const Event &event);
228  bool EventFrameExplo(const Event &event);
230  bool EventFrameOnBoard(const Event &event);
232  bool EventFrameInfo(const Event &event);
234  bool EventFrameVisit(const Event &event);
236  bool EventFrameScript(const Event &event);
237 
239  void SetViewTime(const Math::Vector &vEyePt, const Math::Vector &vLookatPt, float rTime);
241  bool IsCollision(Math::Vector &eye, Math::Vector lookat);
243  bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat);
245  bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat);
246 
248  Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
250  Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
251 
253  void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up);
255  void EffectFrame(const Event &event);
257  void OverFrame(const Event &event);
258 
259 protected:
260  CEngine* m_engine;
261  CRobotMain* m_main;
262  CTerrain* m_terrain;
263  CWater* m_water;
264 
271 
275  float m_initDelay;
276 
289 
290  float m_focus;
291 
292  bool m_rightDown;
293  Math::Point m_rightPosInit;
294  Math::Point m_rightPosCenter;
295  Math::Point m_rightPosMove;
296 
304  float m_heightEye;
308  float m_speed;
309 
311  float m_backDist;
313  float m_backMin;
318  bool m_transparency;
319 
321  float m_fixDist;
326 
330  float m_visitDist;
332  float m_visitTime;
339 
342 
343  float m_remotePan;
344  float m_remoteZoom;
345 
346  Math::Point m_mousePos;
347  float m_mouseDirH;
348  float m_mouseDirV;
349  float m_mouseMarging;
350 
351  float m_motorTurn;
352 
353  CenteringPhase m_centeringPhase;
354  float m_centeringAngleH;
355  float m_centeringAngleV;
356  float m_centeringDist;
357  float m_centeringCurrentH;
358  float m_centeringCurrentV;
359  float m_centeringTime;
360  float m_centeringProgress;
361 
362  CameraEffect m_effectType;
363  Math::Vector m_effectPos;
364  float m_effectForce;
365  float m_effectProgress;
366  Math::Vector m_effectOffset;
367 
368  CameraOverEffect m_overType;
369  float m_overForce;
370  float m_overTime;
371  Color m_overColorBase;
372  Color m_overColor;
373  int m_overMode;
374  float m_overFadeIn;
375  float m_overFadeOut;
376 
377  Math::Vector m_scriptEye;
378  Math::Vector m_scriptLookat;
379 
381  bool m_effect;
388 
389 };
390 
391 
392 } // namespace Gfx
393 
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:778
float m_initDelay
Time of initial centering.
Definition: camera.h:275
void SetType(CameraType type)
Change the type of camera.
Definition: camera.cpp:225
CameraType
Type of camera.
Definition: camera.h:42
Math::Vector m_eyePt
CAM_TYPE_FREE: eye.
Definition: camera.h:298
Vibration during construction.
Definition: camera.h:103
Math::Vector m_actualLookat
Current aim.
Definition: camera.h:280
Math::Vector m_visitGoal
CAM_TYPE_VISIT: target position.
Definition: camera.h:328
Static camera following robot.
Definition: camera.h:55
float m_editHeight
CAM_TYPE_EDIT: height.
Definition: camera.h:341
float m_fixDist
CAM_TYPE_FIX: distance.
Definition: camera.h:321
Main graphics engine - CEngine class.
Explosion.
Definition: camera.h:99
Camera behind a robot.
Definition: camera.h:53
void StopVisit()
Circular end of a visit with the camera.
Definition: camera.cpp:427
Free camera (? never in principle ?)
Definition: camera.h:47
bool EventFrameEdit(const Event &event)
Moves the point of view.
Definition: camera.cpp:1252
void EventMouseWheel(WheelDirection dir)
Mouse wheel operation.
Definition: camera.cpp:1035
bool EventFrameInfo(const Event &event)
Moves the point of view.
Definition: camera.cpp:1548
Math::Vector m_actualEye
Current eye.
Definition: camera.h:278
void StartVisit(Math::Vector goal, float dist)
Start with a tour round the camera.
Definition: camera.cpp:416
float m_visitDirectionH
CAM_TYPE_VISIT: direction.
Definition: camera.h:336
float m_speed
CAM_TYPE_FREE: speed of movement.
Definition: camera.h:308
Digging in.
Definition: camera.h:95
void AbortCentering()
Stop framing special in the current position.
Definition: camera.cpp:489
CameraOverEffect
Definition: camera.h:108
float m_backMin
CAM_TYPE_BACK: distance minimal.
Definition: camera.h:313
Math::Vector m_normLookat
Normal aim.
Definition: camera.h:288
CameraSmooth
Definition: camera.h:70
bool m_cameraInvertY
Y inversion in the edges?
Definition: camera.h:387
bool EventFrameDialog(const Event &event)
Moves the point of view.
Definition: camera.cpp:1294
float m_directionH
CAM_TYPE_FREE: horizontal direction.
Definition: camera.h:300
void SetControllingObject(CObject *object)
Sets the object controlling the camera.
Definition: camera.cpp:215
Lightning.
Definition: camera.h:121
Math::Vector m_normEye
Normal eye.
Definition: camera.h:286
float m_visitTime
CAM_TYPE_VISIT: relative time.
Definition: camera.h:332
bool EventFrameScript(const Event &event)
Moves the point of view.
Definition: camera.cpp:1601
bool EventFrameVisit(const Event &event)
Moves the point of view.
Definition: camera.cpp:1556
void SetSmooth(CameraSmooth type)
Management of the smoothing mode.
Definition: camera.cpp:352
? Vehicle driving is severely ?
Definition: camera.h:97
No effect.
Definition: camera.h:111
Definition: robotmain.h:196
void SetDist(float dist)
Management of the setback distance.
Definition: camera.cpp:362
Camera for displaying information.
Definition: camera.h:61
Sharp.
Definition: camera.h:73
bool IsCollision(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:855
bool EventFrameFree(const Event &event)
Moves the point of view.
Definition: camera.cpp:1189
void SetFixDirection(float angle)
Manage angle mode CAM_TYPE_FIX.
Definition: camera.cpp:372
void FlushEffect()
Removes the special effect with the camera.
Definition: camera.cpp:507
float m_addDirectionV
CAM_TYPE_BACK: additional direction.
Definition: camera.h:317
White -> nothing.
Definition: camera.h:115
CameraEffect
Definition: camera.h:90
bool StopCentering(CObject *object, float time)
Ends a special movement of camera to frame action.
Definition: camera.cpp:464
float m_visitDist
CAM_TYPE_VISIT: distance.
Definition: camera.h:330
Special.
Definition: camera.h:79
float m_heightLookat
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:306
CameraSmooth m_smooth
Type of smoothing.
Definition: camera.h:268
float m_directionV
CAM_TYPE_FREE: vertical direction.
Definition: camera.h:302
2D point
Definition: point.h:46
Math::Vector m_finalLookat
Final aim.
Definition: camera.h:284
float m_fixDirectionV
CAM_TYPE_FIX: direction.
Definition: camera.h:325
Camera while editing a program.
Definition: camera.h:49
void EffectFrame(const Event &event)
Advances the effect of the camera.
Definition: camera.cpp:525
float m_fixDirectionH
CAM_TYPE_FIX: direction.
Definition: camera.h:323
float m_addDirectionH
CAM_TYPE_BACK: additional direction.
Definition: camera.h:315
bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time)
Specifies a special movement of camera to frame action.
Definition: camera.cpp:438
Camera moving in 3D scene.
Definition: camera.h:130
float m_visitDirectionV
CAM_TYPE_VISIT: direction.
Definition: camera.h:338
Flash red.
Definition: camera.h:113
bool EventMouseMove(const Event &event)
Changes the camera according to the mouse moved.
Definition: camera.cpp:1029
Terrain loader/generator and manager.
Definition: terrain.h:220
void SetRemoteZoom(float value)
Management of the remote zoom (0 .. 1) of the camera.
Definition: camera.cpp:392
bool m_effect
Shocks if explosion?
Definition: camera.h:381
Normal.
Definition: camera.h:75
bool EventFrame(const Event &event)
Changes the camera according to the time elapsed.
Definition: camera.cpp:1087
EngineMouseType
Type of mouse cursor displayed in-game.
Definition: engine.h:508
bool m_cameraScroll
Scroll in the edges?
Definition: camera.h:383
Camera on board a robot.
Definition: camera.h:51
? Spleen reactor ?
Definition: camera.h:105
bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:960
The graphics engine.
Definition: engine.h:682
void SetOverBaseColor(Color color)
Specifies the base color.
Definition: camera.cpp:609
Visit instead of an error.
Definition: camera.h:63
Static camera height.
Definition: camera.h:67
Event types, structs and event queue.
CameraType m_type
The type of camera.
Definition: camera.h:266
No effect.
Definition: camera.h:93
Hard.
Definition: camera.h:77
bool EventFrameOnBoard(const Event &event)
Moves the point of view.
Definition: camera.cpp:1531
Nothing -> blue.
Definition: camera.h:119
Camera during a film script.
Definition: camera.h:59
Water manager/renderer.
Definition: water.h:116
bool EventFrameFix(const Event &event)
Moves the point of view.
Definition: camera.cpp:1454
bool EventFrameExplo(const Event &event)
Moves the point of view.
Definition: camera.cpp:1500
bool EventProcess(const Event &event)
Management of an event.
Definition: camera.cpp:1007
Math::Vector m_finalEye
Final eye.
Definition: camera.h:282
bool EventFrameBack(const Event &event)
Moves the point of view.
Definition: camera.cpp:1299
CameraType m_visitType
CAM_TYPE_VISIT: initial type.
Definition: camera.h:334
float GetMotorTurn()
Returns an additional force to turn.
Definition: camera.cpp:169
3D (3x1) vector
Definition: vector.h:49
EngineMouseType GetMouseDef(Math::Point pos)
Returns the default sprite to use for the mouse.
Definition: camera.cpp:1126
CObject * m_cameraObj
Object linked to the camera.
Definition: camera.h:270
void OverFrame(const Event &event)
Advanced overlay effect in the foreground.
Definition: camera.cpp:682
Undefined.
Definition: camera.h:45
float m_backDist
CAM_TYPE_BACK: distance.
Definition: camera.h:311
void FlushOver()
Removes the effect of superposition in the foreground.
Definition: camera.cpp:602
void Init(Math::Vector eye, Math::Vector lookat, float delay)
Initializes the camera.
Definition: camera.cpp:176
float m_heightEye
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:304
RGBA color.
Definition: color.h:35
Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV)
Adjusts the camera not to enter an object.
Definition: camera.cpp:1647
Camera steady after explosion.
Definition: camera.h:57
Event sent by system, interface or game.
Definition: event.h:686
float m_eyeDistance
Distance between the eyes.
Definition: camera.h:273
? Not mortal shot ?
Definition: camera.h:101
void StartEffect(CameraEffect effect, Math::Vector pos, float force)
Starts a special effect with the camera.
Definition: camera.cpp:515
Definition: object.h:352
WheelDirection
Direction of mouse wheel movement.
Definition: event.h:609
bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:863
void GetCamera(Math::Vector &eye, Math::Vector &lookat)
Returns the point of view of the camera.
Definition: camera.cpp:432
Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV)
Adjusts the camera not to enter the ground.
Definition: camera.cpp:1630
bool m_cameraInvertX
X inversion in the edges?
Definition: camera.h:385
void SetRemotePan(float value)
Managing the triggering mode of the camera panning.
Definition: camera.cpp:382
void FixCamera()
Sets the soft movement of the camera.
Definition: camera.cpp:770
Camera for dialog.
Definition: camera.h:65
Nothing -> white.
Definition: camera.h:117
void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up)
Specifies the location and direction of view.
Definition: camera.cpp:1618