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 {
70 };
71 
73 {
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 {
132 public:
133  CCamera();
134  ~CCamera();
135 
137  bool EventProcess(const Event &event);
138 
140  void Init(Math::Vector eye, Math::Vector lookat, float delay);
141 
143  void SetControllingObject(CObject* object);
144  CObject* GetControllingObject();
145 
147  void SetType(CameraType type);
148  CameraType GetType();
149 
151  void SetSmooth(CameraSmooth type);
152  CameraSmooth GetSmooth();
153 
155  void SetDist(float dist);
156  float GetDist();
157 
159  void SetFixDirectionH(float angle);
160  float GetFixDirectionH();
161  void SetFixDirectionV(float angle);
162  float GetFixDirectionV();
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  bool GetEffect();
205  void SetBlood(bool enable);
206  bool GetBlood();
207  void SetOldCameraScroll(bool scroll);
208  bool GetOldCameraScroll();
209  void SetCameraInvertX(bool invert);
210  bool GetCameraInvertX();
211  void SetCameraInvertY(bool invert);
212  bool GetCameraInvertY();
213 
214  void SetCameraSpeed(float speed);
215 
216 protected:
218  bool EventMouseMove(const Event &event);
220  void EventMouseWheel(const Event &event);
222  void EventMouseButton(const Event &event);
224  bool EventFrame(const Event &event);
226  bool EventFrameFree(const Event &event);
228  bool EventFrameEdit(const Event &event);
230  bool EventFrameDialog(const Event &event);
232  bool EventFrameBack(const Event &event);
234  bool EventFrameFix(const Event &event);
236  bool EventFrameExplo(const Event &event);
238  bool EventFrameOnBoard(const Event &event);
240  bool EventFrameInfo(const Event &event);
242  bool EventFrameVisit(const Event &event);
244  bool EventFrameScript(const Event &event);
245 
247  void SetViewTime(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime);
249  bool IsCollision(Math::Vector &eye, Math::Vector lookat);
251  bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat);
253  bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat);
254 
256  Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
258  Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
259 
261  void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up);
263  void EffectFrame(const Event &event);
265  void OverFrame(const Event &event);
266 
267 protected:
268  CEngine* m_engine;
269  CRobotMain* m_main;
270  CTerrain* m_terrain;
271  CWater* m_water;
272  CInput* m_input;
273 
280 
284  float m_initDelay;
285 
298 
299  float m_focus;
300 
308  float m_heightEye;
312  float m_speed;
313 
315  float m_backDist;
317  float m_backMin;
322  bool m_transparency;
323 
325  float m_fixDist;
330 
334  float m_visitDist;
336  float m_visitTime;
341 
344 
345  float m_remotePan;
346 
349  Math::Point m_mouseDelta = Math::Point(0.0f, 0.0f);
350  Math::Point m_mouseDeltaEdge = Math::Point(0.0f, 0.0f);
351 
352  CenteringPhase m_centeringPhase;
353  float m_centeringAngleH;
354  float m_centeringAngleV;
355  float m_centeringDist;
356  float m_centeringCurrentH;
357  float m_centeringCurrentV;
358  float m_centeringTime;
359  float m_centeringProgress;
360 
361  CameraEffect m_effectType;
362  Math::Vector m_effectPos;
363  float m_effectForce;
364  float m_effectProgress;
365  Math::Vector m_effectOffset;
366 
367  CameraOverEffect m_overType;
368  float m_overForce;
369  float m_overTime;
370  Color m_overColorBase;
371  Color m_overColor;
372  int m_overMode;
373  float m_overFadeIn;
374  float m_overFadeOut;
375 
376  Math::Vector m_scriptEye;
377  Math::Vector m_scriptLookat;
378 
380  bool m_effect;
382  bool m_blood;
389 };
390 
391 
392 } // namespace Gfx
float m_initDelay
Time of initial centering.
Definition: camera.h:284
void SetType(CameraType type)
Change the type of camera.
Definition: camera.cpp:263
CameraType
Type of camera.
Definition: camera.h:44
bool m_blood
Blood?
Definition: camera.h:382
Math::Vector m_eyePt
CAM_TYPE_FREE: eye.
Definition: camera.h:302
Vibration during construction.
Definition: camera.h:103
Math::Vector m_actualLookat
Current aim.
Definition: camera.h:289
Math::Vector m_visitGoal
CAM_TYPE_VISIT: target position.
Definition: camera.h:332
Static camera following robot.
Definition: camera.h:57
float m_editHeight
CAM_TYPE_EDIT: height.
Definition: camera.h:343
void SetViewTime(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime)
Specifies the location and direction of view to the 3D engine.
Definition: camera.cpp:839
float m_fixDist
CAM_TYPE_FIX: distance.
Definition: camera.h:325
Main graphics engine - CEngine class.
Explosion.
Definition: camera.h:99
Camera behind a robot.
Definition: camera.h:55
void StopVisit()
Circular end of a visit with the camera.
Definition: camera.cpp:467
Free camera (? never in principle ?)
Definition: camera.h:49
bool EventFrameEdit(const Event &event)
Moves the point of view.
Definition: camera.cpp:1317
bool EventFrameInfo(const Event &event)
Moves the point of view.
Definition: camera.cpp:1600
Math::Vector m_actualEye
Current eye.
Definition: camera.h:287
Math::Point m_mousePos
Last known mouse position, used to calculate change since last frame.
Definition: camera.h:348
void StartVisit(Math::Vector goal, float dist)
Start with a tour round the camera.
Definition: camera.cpp:457
float m_speed
CAM_TYPE_FREE: speed of movement.
Definition: camera.h:312
Digging in.
Definition: camera.h:95
void AbortCentering()
Stop framing special in the current position.
Definition: camera.cpp:529
CameraOverEffect
Definition: camera.h:108
float m_backMin
CAM_TYPE_BACK: distance minimal.
Definition: camera.h:317
Math::Vector m_normLookat
Normal aim.
Definition: camera.h:297
CameraSmooth
Definition: camera.h:72
bool m_cameraInvertY
Y inversion in the edges?
Definition: camera.h:388
bool EventFrameDialog(const Event &event)
Moves the point of view.
Definition: camera.cpp:1355
float m_directionH
CAM_TYPE_FREE: horizontal direction.
Definition: camera.h:304
void SetControllingObject(CObject *object)
Sets the object controlling the camera.
Definition: camera.cpp:253
Lightning.
Definition: camera.h:121
void SetFixDirectionH(float angle)
Manage angle mode CAM_TYPE_FIX.
Definition: camera.cpp:403
Math::Vector m_normEye
Normal eye.
Definition: camera.h:295
float m_visitTime
CAM_TYPE_VISIT: relative time.
Definition: camera.h:336
bool m_oldCameraScroll
Scroll in the edges?
Definition: camera.h:384
bool EventFrameScript(const Event &event)
Moves the point of view.
Definition: camera.cpp:1651
bool EventFrameVisit(const Event &event)
Moves the point of view.
Definition: camera.cpp:1608
void SetSmooth(CameraSmooth type)
Management of the smoothing mode.
Definition: camera.cpp:383
void EventMouseWheel(const Event &event)
Mouse wheel operation.
Definition: camera.cpp:1145
? Vehicle driving is severely ?
Definition: camera.h:97
No effect.
Definition: camera.h:111
Definition: robotmain.h:152
void SetDist(float dist)
Management of the setback distance.
Definition: camera.cpp:393
Camera for displaying information.
Definition: camera.h:63
Sharp.
Definition: camera.h:75
bool IsCollision(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:914
bool EventFrameFree(const Event &event)
Moves the point of view.
Definition: camera.cpp:1239
void FlushEffect()
Removes the special effect with the camera.
Definition: camera.cpp:547
float m_addDirectionV
CAM_TYPE_BACK: additional direction.
Definition: camera.h:321
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:504
float m_visitDist
CAM_TYPE_VISIT: distance.
Definition: camera.h:334
float m_heightLookat
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:310
CameraSmooth m_smooth
Type of smoothing.
Definition: camera.h:277
float m_directionV
CAM_TYPE_FREE: vertical direction.
Definition: camera.h:306
2D point
Definition: point.h:50
Math::Vector m_finalLookat
Final aim.
Definition: camera.h:293
float m_fixDirectionV
CAM_TYPE_FIX: direction.
Definition: camera.h:329
Camera while editing a program.
Definition: camera.h:51
void EffectFrame(const Event &event)
Advances the effect of the camera.
Definition: camera.cpp:567
float m_fixDirectionH
CAM_TYPE_FIX: direction.
Definition: camera.h:327
float m_addDirectionH
CAM_TYPE_BACK: additional direction.
Definition: camera.h:319
bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time)
Specifies a special movement of camera to frame action.
Definition: camera.cpp:478
Camera moving in 3D scene.
Definition: camera.h:130
float m_visitDirectionV
CAM_TYPE_VISIT: direction.
Definition: camera.h:340
Flash red.
Definition: camera.h:113
bool EventMouseMove(const Event &event)
Changes the camera according to the mouse moved.
Definition: camera.cpp:1081
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:433
bool m_effect
Shocks if explosion?
Definition: camera.h:380
Normal.
Definition: camera.h:77
bool EventFrame(const Event &event)
Changes the camera according to the time elapsed.
Definition: camera.cpp:1193
Namespace for (new) graphics code.
Definition: app.h:49
Camera on board a robot.
Definition: camera.h:53
? Spleen reactor ?
Definition: camera.h:105
bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:1013
The graphics engine.
Definition: engine.h:619
void SetOverBaseColor(Color color)
Specifies the base color.
Definition: camera.cpp:670
Visit instead of an error.
Definition: camera.h:65
void EventMouseButton(const Event &event)
Mouse button handling.
Definition: camera.cpp:1178
Static camera height.
Definition: camera.h:69
CameraType m_type
The type of camera.
Definition: camera.h:275
No effect.
Definition: camera.h:93
Hard.
Definition: camera.h:79
bool EventFrameOnBoard(const Event &event)
Moves the point of view.
Definition: camera.cpp:1583
Nothing -> blue.
Definition: camera.h:119
Camera during a film script.
Definition: camera.h:61
Water manager/renderer.
Definition: water.h:72
bool EventFrameFix(const Event &event)
Moves the point of view.
Definition: camera.cpp:1503
bool EventFrameExplo(const Event &event)
Moves the point of view.
Definition: camera.cpp:1552
bool EventProcess(const Event &event)
Management of an event.
Definition: camera.cpp:1054
Math::Vector m_finalEye
Final eye.
Definition: camera.h:291
bool EventFrameBack(const Event &event)
Moves the point of view.
Definition: camera.cpp:1360
CameraType m_visitType
CAM_TYPE_VISIT: initial type.
Definition: camera.h:338
3D (3x1) vector
Definition: vector.h:53
CObject * m_cameraObj
Object linked to the camera.
Definition: camera.h:279
void OverFrame(const Event &event)
Advanced overlay effect in the foreground.
Definition: camera.cpp:743
Undefined.
Definition: camera.h:47
float m_backDist
CAM_TYPE_BACK: distance.
Definition: camera.h:315
void FlushOver()
Removes the effect of superposition in the foreground.
Definition: camera.cpp:663
void Init(Math::Vector eye, Math::Vector lookat, float delay)
Initializes the camera.
Definition: camera.cpp:215
float m_heightEye
CAM_TYPE_FREE: height above the ground.
Definition: camera.h:308
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:1697
Camera steady after explosion.
Definition: camera.h:59
Event sent by system, interface or game.
Definition: event.h:699
float m_eyeDistance
Distance between the eyes.
Definition: camera.h:282
? 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:557
Base class for all 3D in-game objects.
Definition: object.h:63
bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat)
Avoid the obstacles.
Definition: camera.cpp:922
void GetCamera(Math::Vector &eye, Math::Vector &lookat)
Returns the point of view of the camera.
Definition: camera.cpp:472
Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV)
Adjusts the camera not to enter the ground.
Definition: camera.cpp:1680
bool m_cameraInvertX
X inversion in the edges?
Definition: camera.h:386
void SetRemotePan(float value)
Managing the triggering mode of the camera panning.
Definition: camera.cpp:423
void FixCamera()
Sets the soft movement of the camera.
Definition: camera.cpp:831
Management of mouse, keyboard and joystick.
Definition: input.h:71
Camera for dialog.
Definition: camera.h:67
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:1668