summaryrefslogtreecommitdiffstats
path: root/src/old/camera.h
blob: 98e5420dfedfe7ec24e7eaa18357d641c7cdd9fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see  http://www.gnu.org/licenses/.

// camera.h

#pragma once


#include "common/event.h"
#include "math/point.h"
#include "old/d3dengine.h"


class CInstanceManager;
class CD3DEngine;
class CTerrain;
class CWater;
class CObject;


enum CameraType
{
    CAMERA_NULL     = 0,    // camera undefined
    CAMERA_FREE     = 1,    // camera free (never in principle)
    CAMERA_EDIT     = 2,    // camera while editing a program
    CAMERA_ONBOARD      = 3,    // camera on board a robot
    CAMERA_BACK     = 4,    // camera behind a robot
    CAMERA_FIX      = 5,    // static camera following robot
    CAMERA_EXPLO        = 6,    // camera steady after explosion
    CAMERA_SCRIPT       = 7,    // camera during a film script
    CAMERA_INFO     = 8,    // camera for displaying information
    CAMERA_VISIT        = 9,    // visit instead of an error
    CAMERA_DIALOG       = 10,   // camera for dialogue
    CAMERA_PLANE        = 11,   // static camera height
};

enum CameraSmooth
{
    CS_NONE         = 0,    // sharp
    CS_NORM         = 1,    // normal
    CS_HARD         = 2,    // hard
    CS_SPEC         = 3,    // special
};

enum CenteringPhase
{
    CP_NULL         = 0,
    CP_START        = 1,
    CP_WAIT         = 2,
    CP_STOP         = 3,
};

enum CameraEffect
{
    CE_NULL         = 0,    // no effect
    CE_TERRAFORM        = 1,    // digging in
    CE_CRASH        = 2,    // Vehicle driving is severely
    CE_EXPLO        = 3,    // explosion
    CE_SHOT         = 4,    // not mortal shot
    CE_VIBRATION        = 5,    // vibration during construction
    CE_PET          = 6,    // spleen reactor
};

enum OverEffect
{
    OE_NULL         = 0,    // no effect
    OE_BLOOD        = 1,    // flash red
    OE_FADEINw      = 2,    // white -> nothing
    OE_FADEOUTw     = 3,    // nothing -> white
    OE_FADEOUTb     = 4,    // nothing -> blue
    OE_BLITZ        = 5,    // lightning
};



class CCamera
{
public:
    CCamera(CInstanceManager* iMan);
    ~CCamera();

    bool        EventProcess(const Event &event);

    void        Init(Math::Vector eye, Math::Vector lookat, float delay);

    void        SetObject(CObject* object);
    CObject*    RetObject();

    void        SetType(CameraType type);
    CameraType  RetType();

    void        SetSmooth(CameraSmooth type);
    CameraSmooth RetSmoth();

    void        SetDist(float dist);
    float       RetDist();

    void        SetFixDirection(float angle);
    float       RetFixDirection();

    void        SetRemotePan(float value);
    float       RetRemotePan();

    void        SetRemoteZoom(float value);
    float       RetRemoteZoom();

    void        StartVisit(Math::Vector goal, float dist);
    void        StopVisit();

    void        RetCamera(Math::Vector &eye, Math::Vector &lookat);

    bool        StartCentering(CObject *object, float angleH, float angleV, float dist, float time);
    bool        StopCentering(CObject *object, float time);
    void        AbortCentering();

    void        FlushEffect();
    void        StartEffect(CameraEffect effect, Math::Vector pos, float force);

    void        FlushOver();
    void        SetOverBaseColor(D3DCOLORVALUE color);
    void        StartOver(OverEffect effect, Math::Vector pos, float force);

    void        FixCamera();
    void        SetScriptEye(Math::Vector eye);
    void        SetScriptLookat(Math::Vector lookat);

    void        SetEffect(bool bEnable);
    void        SetCameraScroll(bool bScroll);
    void        SetCameraInvertX(bool bInvert);
    void        SetCameraInvertY(bool bInvert);

    float       RetMotorTurn();
    D3DMouse    RetMouseDef(Math::Point pos);

protected:
    bool        EventMouseMove(const Event &event);
    void        EventMouseWheel(int dir);
    bool        EventFrame(const Event &event);
    bool        EventFrameFree(const Event &event);
    bool        EventFrameEdit(const Event &event);
    bool        EventFrameDialog(const Event &event);
    bool        EventFrameBack(const Event &event);
    bool        EventFrameFix(const Event &event);
    bool        EventFrameExplo(const Event &event);
    bool        EventFrameOnBoard(const Event &event);
    bool        EventFrameInfo(const Event &event);
    bool        EventFrameVisit(const Event &event);
    bool        EventFrameScript(const Event &event);

    void        SetViewTime(const Math::Vector &vEyePt, const Math::Vector &vLookatPt, float rTime);
    bool        IsCollision(Math::Vector &eye, Math::Vector lookat);
    bool        IsCollisionBack(Math::Vector &eye, Math::Vector lookat);
    bool        IsCollisionFix(Math::Vector &eye, Math::Vector lookat);

    Math::Vector    ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
    Math::Vector    ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);

    void        SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up);
    void        EffectFrame(const Event &event);
    void        OverFrame(const Event &event);

protected:
    CInstanceManager* m_iMan;
    CD3DEngine* m_engine;
    CTerrain*   m_terrain;
    CWater*     m_water;

    CameraType  m_type;         // the type of camera (CAMERA *)
    CameraSmooth    m_smooth;       // type of smoothing
    CObject*    m_cameraObj;        // object linked to the camera

    float       m_eyeDistance;      // distance between the eyes
    float       m_initDelay;        // time of initial centering

    Math::Vector    m_actualEye;        // current eye
    Math::Vector    m_actualLookat;     // aim current
    Math::Vector    m_finalEye;     // final eye
    Math::Vector    m_finalLookat;      // aim final
    Math::Vector    m_normEye;      // normal eye
    Math::Vector    m_normLookat;       // aim normal
    float       m_focus;

    bool        m_bRightDown;
    Math::Point     m_rightPosInit;
    Math::Point     m_rightPosCenter;
    Math::Point     m_rightPosMove;

    Math::Vector    m_eyePt;        // CAMERA_FREE: eye
    float       m_directionH;       // CAMERA_FREE: horizontal direction
    float       m_directionV;       // CAMERA_FREE: vertical direction
    float       m_heightEye;        // CAMERA_FREE: height above the ground
    float       m_heightLookat;     // CAMERA_FREE: height above the ground
    float       m_speed;        // CAMERA_FREE: speed of movement

    float       m_backDist;     // CAMERA_BACK: distance
    float       m_backMin;      // CAMERA_BACK: distance minimal
    float       m_addDirectionH;    // CAMERA_BACK: additional direction
    float       m_addDirectionV;    // CAMERA_BACK: additional direction
    bool        m_bTransparency;

    float       m_fixDist;      // CAMERA_FIX: distance
    float       m_fixDirectionH;    // CAMERA_FIX: direction
    float       m_fixDirectionV;    // CAMERA_FIX: direction

    Math::Vector    m_visitGoal;        // CAMERA_VISIT: target position
    float       m_visitDist;        // CAMERA_VISIT: distance
    float       m_visitTime;        // CAMERA_VISIT: relative time
    CameraType  m_visitType;        // CAMERA_VISIT: initial type
    float       m_visitDirectionH;  // CAMERA_VISIT: direction
    float       m_visitDirectionV;  // CAMERA_VISIT: direction

    float       m_editHeight;       // CAMERA_EDIT: height

    float       m_remotePan;
    float       m_remoteZoom;

    Math::Point     m_mousePos;
    float       m_mouseDirH;
    float       m_mouseDirV;
    float       m_mouseMarging;

    float       m_motorTurn;

    CenteringPhase m_centeringPhase;
    float       m_centeringAngleH;
    float       m_centeringAngleV;
    float       m_centeringDist;
    float       m_centeringCurrentH;
    float       m_centeringCurrentV;
    float       m_centeringTime;
    float       m_centeringProgress;

    CameraEffect m_effectType;
    Math::Vector    m_effectPos;
    float       m_effectForce;
    float       m_effectProgress;
    Math::Vector    m_effectOffset;

    OverEffect  m_overType;
    float       m_overForce;
    float       m_overTime;
    D3DCOLORVALUE m_overColorBase;
    D3DCOLORVALUE m_overColor;
    int         m_overMode;
    float       m_overFadeIn;
    float       m_overFadeOut;

    Math::Vector    m_scriptEye;
    Math::Vector    m_scriptLookat;

    bool        m_bEffect;      // shocks if explosion?
    bool        m_bCameraScroll;    // scroll in the edges?
    bool        m_bCameraInvertX;   // X inversion in the edges?
    bool        m_bCameraInvertY;   // Y inversion in the edges?
};