forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathW3DView.h
More file actions
311 lines (257 loc) · 15.9 KB
/
W3DView.h
File metadata and controls
311 lines (257 loc) · 15.9 KB
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: W3DView.h ////////////////////////////////////////////////////////////////////////////////
//
// W3D implementation of the game view window. View windows are literally
// a window into the game world that have width, height, and camera
// controls for what to look at
//
// Author: Colin Day, April 2001
//
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////////////////////////
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "Common/STLTypedefs.h"
#include "GameClient/ParabolicEase.h"
#include "GameClient/View.h"
#include "WW3D2/camera.h"
// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
class Drawable;
///////////////////////////////////////////////////////////////////////////////////////////////////
enum {MAX_WAYPOINTS=25};
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
typedef struct
{
Int numWaypoints;
Coord3D waypoints[MAX_WAYPOINTS+2]; // We pad first & last for interpolation.
Real waySegLength[MAX_WAYPOINTS+2]; // Length of each segment;
Real cameraAngle[MAX_WAYPOINTS+2]; // Camera Angle;
Int timeMultiplier[MAX_WAYPOINTS+2]; // Time speedup factor.
Real groundHeight[MAX_WAYPOINTS+1]; // Ground height.
Real totalTimeMilliseconds; // Num of ms to do this movement.
Real elapsedTimeMilliseconds; // Time since start.
Real totalDistance; // Total length of paths.
Real curSegDistance; // How far we are along the current seg.
Int shutter;
Int curSegment; // The current segment.
Int curShutter; // The current shutter.
Int rollingAverageFrames; // Number of frames to roll.
ParabolicEase ease; // Ease in/out function.
} TMoveAlongWaypointPathInfo;
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
typedef struct
{
Int numFrames; ///< Number of frames to rotate.
Int curFrame; ///< Current frame.
Int startTimeMultiplier;
Int endTimeMultiplier;
Int numHoldFrames; ///< Number of frames to hold the camera before finishing the movement
ParabolicEase ease;
Bool trackObject; ///< Are we tracking an object or just rotating?
struct Target {
ObjectID targetObjectID; ///< Target if we are tracking an object instead of just rotating
Coord3D targetObjectPos; ///< Target's position (so we can stay looking at that spot if he dies)
};
struct Angle {
Real startAngle;
Real endAngle;
};
union {
Target target;
Angle angle;
};
} TRotateCameraInfo;
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
typedef struct
{
Int numFrames; ///< Number of frames to pitch.
Int curFrame; ///< Current frame.
Real angle;
Real startPitch;
Real endPitch;
Int startTimeMultiplier;
Int endTimeMultiplier;
ParabolicEase ease;
} TPitchCameraInfo;
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
typedef struct
{
Int numFrames; ///< Number of frames to zoom.
Int curFrame; ///< Current frame.
Real startZoom;
Real endZoom;
Int startTimeMultiplier;
Int endTimeMultiplier;
ParabolicEase ease;
} TZoomCameraInfo;
// ------------------------------------------------------------------------------------------------
/** W3DView implementation of the game view class. This allows us to create
* a "window" into the game world that can be sized and contains controls
* for manipulating the camera */
// ------------------------------------------------------------------------------------------------
class W3DView : public View, public SubsystemInterface
{
public:
W3DView();
~W3DView();
virtual void init( void ); ///< init/re-init the W3DView
virtual void reset( void );
virtual void drawView( void ); ///< draw this view
virtual void updateView(void); ///<called once per frame to determine the final camera and object transforms
virtual void stepView(); ///< Update view for every fixed time step
virtual void draw( ); ///< draw this view
virtual void update( ); ///<called once per frame to determine the final camera and object transforms
virtual Drawable *pickDrawable( const ICoord2D *screen, Bool forceAttack, PickType pickType ); ///< pick drawable given the screen pixel coords. If force attack, picks bridges.
/// all drawables in the 2D screen region will call the 'callback'
virtual Int iterateDrawablesInRegion( IRegion2D *screenRegion,
Bool (*callback)( Drawable *draw, void *userData ),
void *userData );
virtual void setWidth( Int width );
virtual void setHeight( Int height );
virtual void setOrigin( Int x, Int y); ///< Sets location of top-left view corner on display
virtual void scrollBy( Coord2D *delta ); ///< Shift the view by the given delta
virtual void forceRedraw();
virtual void setAngle( Real angle ); ///< Rotate the view around the up axis by the given angle
virtual void setPitch( Real angle ); ///< Rotate the view around the horizontal axis to the given angle
virtual void setAngleAndPitchToDefault( void ); ///< Set the view angle back to default
virtual void lookAt( const Coord3D *o ); ///< Center the view on the given coordinate
virtual void initHeightForMap( void ); ///< Init the camera height for the map at the current position.
virtual void moveCameraTo(const Coord3D *o, Int miliseconds, Int shutter, Bool orient, Real easeIn, Real easeOut);
virtual void moveCameraAlongWaypointPath(Waypoint *pWay, Int frames, Int shutter, Bool orient, Real easeIn, Real easeOut);
virtual Bool isCameraMovementFinished(void);
virtual Bool isCameraMovementAtWaypointAlongPath(void);
virtual void resetCamera(const Coord3D *location, Int frames, Real easeIn, Real easeOut); ///< Move camera to location, and reset to default angle & zoom.
virtual void rotateCamera(Real rotations, Int frames, Real easeIn, Real easeOut); ///< Rotate camera about current viewpoint.
virtual void rotateCameraTowardObject(ObjectID id, Int milliseconds, Int holdMilliseconds, Real easeIn, Real easeOut); ///< Rotate camera to face an object, and hold on it
virtual void rotateCameraTowardPosition(const Coord3D *pLoc, Int milliseconds, Real easeIn, Real easeOut, Bool reverseRotation); ///< Rotate camera to face a location.
virtual void cameraModFreezeTime(void){ m_freezeTimeForCameraMovement = true;} ///< Freezes time during the next camera movement.
virtual void cameraModFreezeAngle(void); ///< Freezes time during the next camera movement.
virtual Bool isTimeFrozen(void){ return m_freezeTimeForCameraMovement;} ///< Freezes time during the next camera movement.
virtual void cameraModFinalZoom(Real finalZoom, Real easeIn, Real easeOut); ///< Final zoom for current camera movement.
virtual void cameraModRollingAverage(Int framesToAverage); ///< Number of frames to average movement for current camera movement.
virtual void cameraModFinalTimeMultiplier(Int finalMultiplier); ///< Final time multiplier for current camera movement.
virtual void cameraModFinalPitch(Real finalPitch, Real easeIn, Real easeOut); ///< Final pitch for current camera movement.
virtual void cameraModLookToward(Coord3D *pLoc); ///< Sets a look at point during camera movement.
virtual void cameraModFinalLookToward(Coord3D *pLoc); ///< Sets a look at point during camera movement.
virtual void cameraModFinalMoveTo(Coord3D *pLoc); ///< Sets a final move to.
// (gth) C&C3 animation controlled camera feature
virtual void cameraEnableSlaveMode(const AsciiString & thingtemplateName, const AsciiString & boneName);
virtual void cameraDisableSlaveMode(void);
virtual void cameraEnableRealZoomMode(void); //WST 10.18.2002
virtual void cameraDisableRealZoomMode(void);
virtual void Add_Camera_Shake(const Coord3D & position,float radius, float duration, float power); //WST 10.18.2002
virtual Int getTimeMultiplier(void) {return m_timeMultiplier;};///< Get the time multiplier.
virtual void setTimeMultiplier(Int multiple) {m_timeMultiplier = multiple;}; ///< Set the time multiplier.
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight);
virtual void zoomCamera( Real finalZoom, Int milliseconds, Real easeIn, Real easeOut );
virtual void pitchCamera( Real finalPitch, Int milliseconds, Real easeIn, Real easeOut );
virtual void setHeightAboveGround(Real z);
virtual void setZoom(Real z);
virtual void setZoomToDefault( void ); ///< Set zoom to default value
virtual void setFieldOfView( Real angle ); ///< Set the horizontal field of view angle
virtual WorldToScreenReturn worldToScreenTriReturn( const Coord3D *w, ICoord2D *s ); ///< Transform world coordinate "w" into screen coordinate "s"
virtual void screenToWorld( const ICoord2D *s, Coord3D *w ); ///< Transform screen coordinate "s" into world coordinate "w"
virtual void screenToTerrain( const ICoord2D *screen, Coord3D *world ); ///< transform screen coord to a point on the 3D terrain
virtual void screenToWorldAtZ( const ICoord2D *s, Coord3D *w, Real z ); ///< transform screen point to world point at the specified world Z value
CameraClass *get3DCamera() const { return m_3DCamera; }
virtual const Coord3D& get3DCameraPosition() const;
virtual void setCameraLock(ObjectID id);
virtual void setSnapMode( CameraLockType lockType, Real lockDist );
/// Add an impulse force to shake the camera
virtual void shake( const Coord3D *epicenter, CameraShakeType shakeType );
virtual Real getFXPitch( void ) const { return m_FXPitch; } ///< returns the FX pitch angle
virtual Bool setViewFilterMode(FilterModes filterMode); ///< Turns on viewport special effect (black & white mode)
virtual Bool setViewFilter(FilterTypes filter); ///< Turns on viewport special effect (black & white mode)
virtual void setViewFilterPos(const Coord3D *pos); ///< Passes a position to the special effect filter.
virtual FilterModes getViewFilterMode(void) {return m_viewFilterMode;} ///< Turns on viewport special effect (black & white mode)
virtual FilterTypes getViewFilterType(void) {return m_viewFilter;} ///< Turns on viewport special effect (black & white mode)
virtual void setFadeParameters(Int fadeFrames, Int direction);
virtual void set3DWireFrameMode(Bool enable); ///<enables custom wireframe rendering of 3D viewport
Bool updateCameraMovements(void);
virtual void forceCameraConstraintRecalc(void) { calcCameraConstraints(); }
virtual void setGuardBandBias( const Coord2D *gb ) { m_guardBandBias.x = gb->x; m_guardBandBias.y = gb->y; }
#if !RETAIL_COMPATIBLE_DRAWUPDATE
virtual void setUpdateEfficient(void) { m_updateEfficient = TRUE; }
#endif
private:
CameraClass *m_3DCamera; ///< camera representation for 3D scene
CameraClass *m_2DCamera; ///< camera for UI overlayed on top of 3D scene
FilterModes m_viewFilterMode;
FilterTypes m_viewFilter;
Bool m_isWireFrameEnabled;
Bool m_nextWireFrameEnabled; ///< used to delay wireframe changes by 1 frame (needed for transitions).
Coord2D m_shakeOffset; ///< the offset to add to the camera position
Real m_shakeAngleCos; ///< the cosine of the orientation of the oscillation
Real m_shakeAngleSin; ///< the sine of the orientation of the oscillation
Real m_shakeIntensity; ///< the intensity of the oscillation
Vector3 m_shakerAngles; //WST 11/12/2002 new multiple instance camera shaker system
TRotateCameraInfo m_rcInfo;
Bool m_doingRotateCamera; ///< True if we are doing a camera rotate.
TPitchCameraInfo m_pcInfo;
Bool m_doingPitchCamera;
TZoomCameraInfo m_zcInfo;
Bool m_doingZoomCamera;
Bool m_doingScriptedCameraLock; ///< True if we are following a unit via script
Real m_FXPitch; ///< Camera effects pitch. 0 = flat, infinite = look down, 1 = normal.
TMoveAlongWaypointPathInfo m_mcwpInfo; ///< Move camera along waypoint path info.
Bool m_doingMoveCameraOnWaypointPath; ///< If true, moving camera along waypoint path.
Bool m_CameraArrivedAtWaypointOnPathFlag;
Bool m_freezeTimeForCameraMovement;
Int m_timeMultiplier; ///< Time speedup multiplier.
Bool m_cameraHasMovedSinceRequest; ///< If true, throw out all saved locations
VecPosRequests m_locationRequests; ///< These are cached. New requests are added here
Coord3D m_cameraOffset; ///< offset for camera from view center
Coord3D m_previousLookAtPosition; ///< offset for camera from view center
Coord2D m_scrollAmount; ///< scroll speed
Real m_scrollAmountCutoff; ///< scroll speed at which we do not adjust height
Real m_groundLevel; ///< height of ground.
Region2D m_cameraConstraint; ///< m_pos should be constrained to be within this area
Bool m_cameraConstraintValid; ///< if f, recalc cam constraints
void setCameraTransform( void ); ///< set the transform matrix of m_3DCamera, based on m_pos & m_angle
void buildCameraTransform( Matrix3D *transform ) ; ///< calculate (but do not set) the transform matrix of m_3DCamera, based on m_pos & m_angle
void calcCameraConstraints() ; ///< recalc m_cameraConstraint
void moveAlongWaypointPath(Real milliseconds); ///< Move camera along path.
void getPickRay(const ICoord2D *screen, Vector3 *rayStart, Vector3 *rayEnd); ///<returns a line segment (ray) originating at the given screen position
void setupWaypointPath(Bool orient); ///< Calculates distances & angles for moving along a waypoint path.
void rotateCameraOneFrame(void); ///< Do one frame of a rotate camera movement.
void zoomCameraOneFrame(void); ///< Do one frame of a zoom camera movement.
void pitchCameraOneFrame(void); ///< Do one frame of a pitch camera movement.
void getAxisAlignedViewRegion(Region3D &axisAlignedRegion); ///< Find 3D Region enclosing all possible drawables.
void calcDeltaScroll(Coord2D &screenDelta);
// (gth) C&C3 animation controlled camera feature
Bool m_isCameraSlaved;
Bool m_useRealZoomCam;
AsciiString m_cameraSlaveObjectName;
AsciiString m_cameraSlaveObjectBoneName;
#if !RETAIL_COMPATIBLE_DRAWUPDATE
// Efficient Draw Update
Bool m_updateEfficient;
#endif
};
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
extern Real TheW3DFrameLengthInMsec;