W3DView.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  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. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: W3DView.h ////////////////////////////////////////////////////////////////////////////////
  24. //
  25. // W3D implementation of the game view window. View windows are literally
  26. // a window into the game world that have width, height, and camera
  27. // controls for what to look at
  28. //
  29. // Author: Colin Day, April 2001
  30. //
  31. ///////////////////////////////////////////////////////////////////////////////////////////////////
  32. #pragma once
  33. #ifndef __W3DVIEW_H_
  34. #define __W3DVIEW_H_
  35. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////////////////////////
  36. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  37. #include "Common/STLTypedefs.h"
  38. #include "GameClient/ParabolicEase.h"
  39. #include "GameClient/View.h"
  40. #include "WW3D2/Camera.h"
  41. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  42. class Drawable;
  43. ///////////////////////////////////////////////////////////////////////////////////////////////////
  44. enum {MAX_WAYPOINTS=25};
  45. // ------------------------------------------------------------------------------------------------
  46. // ------------------------------------------------------------------------------------------------
  47. typedef struct
  48. {
  49. Int numWaypoints;
  50. Coord3D waypoints[MAX_WAYPOINTS+2]; // We pad first & last for interpolation.
  51. Real waySegLength[MAX_WAYPOINTS+2]; // Length of each segment;
  52. Real cameraAngle[MAX_WAYPOINTS+2]; // Camera Angle;
  53. Int timeMultiplier[MAX_WAYPOINTS+2]; // Time speedup factor.
  54. Real groundHeight[MAX_WAYPOINTS+1]; // Ground height.
  55. Int totalTimeMilliseconds; // Num of ms to do this movement.
  56. Int elapsedTimeMilliseconds; // Time since start.
  57. Real totalDistance; // Total length of paths.
  58. Real curSegDistance; // How far we are along the current seg.
  59. Int shutter;
  60. Int curSegment; // The current segment.
  61. Int curShutter; // The current shutter.
  62. Int rollingAverageFrames; // Number of frames to roll.
  63. ParabolicEase ease; // Ease in/out function.
  64. } TMoveAlongWaypointPathInfo;
  65. // ------------------------------------------------------------------------------------------------
  66. // ------------------------------------------------------------------------------------------------
  67. typedef struct
  68. {
  69. Int numFrames; ///< Number of frames to rotate.
  70. Int curFrame; ///< Current frame.
  71. Int startTimeMultiplier;
  72. Int endTimeMultiplier;
  73. Int numHoldFrames; ///< Number of frames to hold the camera before finishing the movement
  74. ParabolicEase ease;
  75. Bool trackObject; ///< Are we tracking an object or just rotating?
  76. struct Target {
  77. ObjectID targetObjectID; ///< Target if we are tracking an object instead of just rotating
  78. Coord3D targetObjectPos; ///< Target's position (so we can stay looking at that spot if he dies)
  79. };
  80. struct Angle {
  81. Real startAngle;
  82. Real endAngle;
  83. };
  84. union {
  85. Target target;
  86. Angle angle;
  87. };
  88. } TRotateCameraInfo;
  89. // ------------------------------------------------------------------------------------------------
  90. // ------------------------------------------------------------------------------------------------
  91. typedef struct
  92. {
  93. Int numFrames; ///< Number of frames to pitch.
  94. Int curFrame; ///< Current frame.
  95. Real angle;
  96. Real startPitch;
  97. Real endPitch;
  98. Int startTimeMultiplier;
  99. Int endTimeMultiplier;
  100. ParabolicEase ease;
  101. } TPitchCameraInfo;
  102. // ------------------------------------------------------------------------------------------------
  103. // ------------------------------------------------------------------------------------------------
  104. typedef struct
  105. {
  106. Int numFrames; ///< Number of frames to zoom.
  107. Int curFrame; ///< Current frame.
  108. Real startZoom;
  109. Real endZoom;
  110. Int startTimeMultiplier;
  111. Int endTimeMultiplier;
  112. ParabolicEase ease;
  113. } TZoomCameraInfo;
  114. // ------------------------------------------------------------------------------------------------
  115. /** W3DView implementation of the game view class. This allows us to create
  116. * a "window" into the game world that can be sized and contains controls
  117. * for manipulating the camera */
  118. // ------------------------------------------------------------------------------------------------
  119. class W3DView : public View, public SubsystemInterface
  120. {
  121. public:
  122. W3DView();
  123. ~W3DView();
  124. virtual void init( void ); ///< init/re-init the W3DView
  125. virtual void reset( void );
  126. virtual void drawView( void ); ///< draw this view
  127. virtual void updateView(void); ///<called once per frame to determine the final camera and object transforms
  128. virtual void draw( ); ///< draw this view
  129. virtual void update( ); ///<called once per frame to determine the final camera and object transforms
  130. virtual Drawable *pickDrawable( const ICoord2D *screen, Bool forceAttack, PickType pickType ); ///< pick drawable given the screen pixel coords. If force attack, picks bridges.
  131. /// all drawables in the 2D screen region will call the 'callback'
  132. virtual Int iterateDrawablesInRegion( IRegion2D *screenRegion,
  133. Bool (*callback)( Drawable *draw, void *userData ),
  134. void *userData );
  135. virtual void setWidth( Int width );
  136. virtual void setHeight( Int height );
  137. virtual void setOrigin( Int x, Int y); ///< Sets location of top-left view corner on display
  138. virtual void scrollBy( Coord2D *delta ); ///< Shift the view by the given delta
  139. virtual void forceRedraw();
  140. virtual void setAngle( Real angle ); ///< Rotate the view around the up axis by the given angle
  141. virtual void setPitch( Real angle ); ///< Rotate the view around the horizontal axis to the given angle
  142. virtual void setAngleAndPitchToDefault( void ); ///< Set the view angle back to default
  143. virtual void lookAt( const Coord3D *o ); ///< Center the view on the given coordinate
  144. virtual void initHeightForMap( void ); ///< Init the camera height for the map at the current position.
  145. virtual void moveCameraTo(const Coord3D *o, Int miliseconds, Int shutter, Bool orient, Real easeIn, Real easeOut);
  146. virtual void moveCameraAlongWaypointPath(Waypoint *pWay, Int frames, Int shutter, Bool orient, Real easeIn, Real easeOut);
  147. virtual Bool isCameraMovementFinished(void);
  148. virtual Bool isCameraMovementAtWaypointAlongPath(void);
  149. virtual void resetCamera(const Coord3D *location, Int frames, Real easeIn, Real easeOut); ///< Move camera to location, and reset to default angle & zoom.
  150. virtual void rotateCamera(Real rotations, Int frames, Real easeIn, Real easeOut); ///< Rotate camera about current viewpoint.
  151. virtual void rotateCameraTowardObject(ObjectID id, Int milliseconds, Int holdMilliseconds, Real easeIn, Real easeOut); ///< Rotate camera to face an object, and hold on it
  152. virtual void rotateCameraTowardPosition(const Coord3D *pLoc, Int milliseconds, Real easeIn, Real easeOut, Bool reverseRotation); ///< Rotate camera to face a location.
  153. virtual void cameraModFreezeTime(void){ m_freezeTimeForCameraMovement = true;} ///< Freezes time during the next camera movement.
  154. virtual void cameraModFreezeAngle(void); ///< Freezes time during the next camera movement.
  155. virtual Bool isTimeFrozen(void){ return m_freezeTimeForCameraMovement;} ///< Freezes time during the next camera movement.
  156. virtual void cameraModFinalZoom(Real finalZoom, Real easeIn, Real easeOut); ///< Final zoom for current camera movement.
  157. virtual void cameraModRollingAverage(Int framesToAverage); ///< Number of frames to average movement for current camera movement.
  158. virtual void cameraModFinalTimeMultiplier(Int finalMultiplier); ///< Final time multiplier for current camera movement.
  159. virtual void cameraModFinalPitch(Real finalPitch, Real easeIn, Real easeOut); ///< Final pitch for current camera movement.
  160. virtual void cameraModLookToward(Coord3D *pLoc); ///< Sets a look at point during camera movement.
  161. virtual void cameraModFinalLookToward(Coord3D *pLoc); ///< Sets a look at point during camera movement.
  162. virtual void cameraModFinalMoveTo(Coord3D *pLoc); ///< Sets a final move to.
  163. // (gth) C&C3 animation controlled camera feature
  164. virtual void cameraEnableSlaveMode(const AsciiString & thingtemplateName, const AsciiString & boneName);
  165. virtual void cameraDisableSlaveMode(void);
  166. virtual void cameraEnableRealZoomMode(void); //WST 10.18.2002
  167. virtual void cameraDisableRealZoomMode(void);
  168. virtual void Add_Camera_Shake(const Coord3D & position,float radius, float duration, float power); //WST 10.18.2002
  169. virtual Int getTimeMultiplier(void) {return m_timeMultiplier;};///< Get the time multiplier.
  170. virtual void setTimeMultiplier(Int multiple) {m_timeMultiplier = multiple;}; ///< Set the time multiplier.
  171. virtual void setDefaultView(Real pitch, Real angle, Real maxHeight);
  172. virtual void zoomCamera( Real finalZoom, Int milliseconds, Real easeIn, Real easeOut );
  173. virtual void pitchCamera( Real finalPitch, Int milliseconds, Real easeIn, Real easeOut );
  174. virtual void setHeightAboveGround(Real z);
  175. virtual void setZoom(Real z);
  176. virtual void setZoomToDefault( void ); ///< Set zoom to default value
  177. virtual void setFieldOfView( Real angle ); ///< Set the horizontal field of view angle
  178. virtual WorldToScreenReturn worldToScreenTriReturn( const Coord3D *w, ICoord2D *s ); ///< Transform world coordinate "w" into screen coordinate "s"
  179. virtual void screenToWorld( const ICoord2D *s, Coord3D *w ); ///< Transform screen coordinate "s" into world coordinate "w"
  180. virtual void screenToTerrain( const ICoord2D *screen, Coord3D *world ); ///< transform screen coord to a point on the 3D terrain
  181. virtual void screenToWorldAtZ( const ICoord2D *s, Coord3D *w, Real z ); ///< transform screen point to world point at the specified world Z value
  182. CameraClass *get3DCamera() const { return m_3DCamera; }
  183. virtual const Coord3D& get3DCameraPosition() const;
  184. virtual void setCameraLock(ObjectID id);
  185. virtual void setSnapMode( CameraLockType lockType, Real lockDist );
  186. /// Add an impulse force to shake the camera
  187. virtual void shake( const Coord3D *epicenter, CameraShakeType shakeType );
  188. virtual Real getFXPitch( void ) const { return m_FXPitch; } ///< returns the FX pitch angle
  189. virtual Bool setViewFilterMode(enum FilterModes filterMode); ///< Turns on viewport special effect (black & white mode)
  190. virtual Bool setViewFilter(enum FilterTypes filter); ///< Turns on viewport special effect (black & white mode)
  191. virtual void setViewFilterPos(const Coord3D *pos); ///< Passes a position to the special effect filter.
  192. virtual enum FilterModes getViewFilterMode(void) {return m_viewFilterMode;} ///< Turns on viewport special effect (black & white mode)
  193. virtual enum FilterTypes getViewFilterType(void) {return m_viewFilter;} ///< Turns on viewport special effect (black & white mode)
  194. virtual void setFadeParameters(Int fadeFrames, Int direction);
  195. virtual void set3DWireFrameMode(Bool enable); ///<enables custom wireframe rendering of 3D viewport
  196. Bool updateCameraMovements(void);
  197. virtual void forceCameraConstraintRecalc(void) { calcCameraConstraints(); }
  198. virtual void setGuardBandBias( const Coord2D *gb ) { m_guardBandBias.x = gb->x; m_guardBandBias.y = gb->y; }
  199. private:
  200. CameraClass *m_3DCamera; ///< camera representation for 3D scene
  201. CameraClass *m_2DCamera; ///< camera for UI overlayed on top of 3D scene
  202. enum FilterModes m_viewFilterMode;
  203. enum FilterTypes m_viewFilter;
  204. Bool m_isWireFrameEnabled;
  205. Bool m_nextWireFrameEnabled; ///< used to delay wireframe changes by 1 frame (needed for transitions).
  206. Coord2D m_shakeOffset; ///< the offset to add to the camera position
  207. Real m_shakeAngleCos; ///< the cosine of the orientation of the oscillation
  208. Real m_shakeAngleSin; ///< the sine of the orientation of the oscillation
  209. Real m_shakeIntensity; ///< the intensity of the oscillation
  210. Vector3 m_shakerAngles; //WST 11/12/2002 new multiple instance camera shaker system
  211. TRotateCameraInfo m_rcInfo;
  212. Bool m_doingRotateCamera; ///< True if we are doing a camera rotate.
  213. TPitchCameraInfo m_pcInfo;
  214. Bool m_doingPitchCamera;
  215. TZoomCameraInfo m_zcInfo;
  216. Bool m_doingZoomCamera;
  217. Bool m_doingScriptedCameraLock; ///< True if we are following a unit via script
  218. Real m_FXPitch; ///< Camera effects pitch. 0 = flat, infinite = look down, 1 = normal.
  219. TMoveAlongWaypointPathInfo m_mcwpInfo; ///< Move camera along waypoint path info.
  220. Bool m_doingMoveCameraOnWaypointPath; ///< If true, moving camera along waypoint path.
  221. Bool m_CameraArrivedAtWaypointOnPathFlag;
  222. Bool m_freezeTimeForCameraMovement;
  223. Int m_timeMultiplier; ///< Time speedup multiplier.
  224. Bool m_cameraHasMovedSinceRequest; ///< If true, throw out all saved locations
  225. VecPosRequests m_locationRequests; ///< These are cached. New requests are added here
  226. Coord3D m_cameraOffset; ///< offset for camera from view center
  227. Coord3D m_previousLookAtPosition; ///< offset for camera from view center
  228. Coord2D m_scrollAmount; ///< scroll speed
  229. Real m_scrollAmountCutoff; ///< scroll speed at which we do not adjust height
  230. Real m_groundLevel; ///< height of ground.
  231. Region2D m_cameraConstraint; ///< m_pos should be constrained to be within this area
  232. Bool m_cameraConstraintValid; ///< if f, recalc cam constraints
  233. void setCameraTransform( void ); ///< set the transform matrix of m_3DCamera, based on m_pos & m_angle
  234. void buildCameraTransform( Matrix3D *transform ) ; ///< calculate (but do not set) the transform matrix of m_3DCamera, based on m_pos & m_angle
  235. void calcCameraConstraints() ; ///< recalc m_cameraConstraint
  236. void moveAlongWaypointPath(Int milliseconds); ///< Move camera along path.
  237. void getPickRay(const ICoord2D *screen, Vector3 *rayStart, Vector3 *rayEnd); ///<returns a line segment (ray) originating at the given screen position
  238. void setupWaypointPath(Bool orient); ///< Calculates distances & angles for moving along a waypoint path.
  239. void rotateCameraOneFrame(void); ///< Do one frame of a rotate camera movement.
  240. void zoomCameraOneFrame(void); ///< Do one frame of a zoom camera movement.
  241. void pitchCameraOneFrame(void); ///< Do one frame of a pitch camera movement.
  242. void getAxisAlignedViewRegion(Region3D &axisAlignedRegion); ///< Find 3D Region enclosing all possible drawables.
  243. void calcDeltaScroll(Coord2D &screenDelta);
  244. // (gth) C&C3 animation controlled camera feature
  245. Bool m_isCameraSlaved;
  246. Bool m_useRealZoomCam;
  247. AsciiString m_cameraSlaveObjectName;
  248. AsciiString m_cameraSlaveObjectBoneName;
  249. }; // end class W3DView
  250. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  251. extern Int TheW3DFrameLengthInMsec; // default is 33msec/frame == 30fps. but we may change it depending on sys config.
  252. #endif // end __W3DVIEW_H_