DrawObject.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. #ifndef __DRAW_OBJECT_H_
  19. #define __DRAW_OBJECT_H_
  20. #include "always.h"
  21. #include "rendobj.h"
  22. #include "w3d_file.h"
  23. #include "dx8vertexbuffer.h"
  24. #include "dx8indexbuffer.h"
  25. #include "shader.h"
  26. #include "vertmaterial.h"
  27. #include "Lib/BaseType.h"
  28. #include "Common/AsciiString.h"
  29. // The draw objects draw a circle of diameter 1.0 cells.
  30. #define THE_RADIUS (0.8f*MAP_XY_FACTOR)
  31. class MeshClass;
  32. class PolygonTrigger;
  33. class WaterRenderObjClass;
  34. class MapObject;
  35. class Render2DClass;
  36. //
  37. // DrawObject: Draws 3d feedback for tools & objects.
  38. //
  39. //
  40. class DrawObject : public RenderObjClass
  41. {
  42. public:
  43. DrawObject(void);
  44. DrawObject(const DrawObject & src);
  45. DrawObject & operator = (const DrawObject &);
  46. ~DrawObject(void);
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Render Object Interface
  49. /////////////////////////////////////////////////////////////////////////////
  50. virtual RenderObjClass * Clone(void) const;
  51. virtual int Class_ID(void) const;
  52. virtual void Render(RenderInfoClass & rinfo);
  53. // virtual void Special_Render(SpecialRenderInfoClass & rinfo);
  54. // virtual void Set_Transform(const Matrix3D &m);
  55. // virtual void Set_Position(const Vector3 &v);
  56. //TODO: MW: do these later - only needed for collision detection
  57. virtual Bool Cast_Ray(RayCollisionTestClass & raytest);
  58. // virtual Bool Cast_AABox(AABoxCollisionTestClass & boxtest);
  59. // virtual Bool Cast_OBBox(OBBoxCollisionTestClass & boxtest);
  60. // virtual Bool Intersect_AABox(AABoxIntersectionTestClass & boxtest);
  61. // virtual Bool Intersect_OBBox(OBBoxIntersectionTestClass & boxtest);
  62. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  63. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & aabox) const;
  64. // virtual int Get_Num_Polys(void) const;
  65. // virtual const char * Get_Name(void) const;
  66. // virtual void Set_Name(const char * name);
  67. // unsigned int Get_Flags(void) { return Flags; }
  68. // void Set_Flags(unsigned int flags) { Flags = flags; }
  69. // void Set_Flag(unsigned int flag, Bool onoff) { Flags &= (~flag); if (onoff) Flags |= flag; }
  70. Int freeMapResources(void);
  71. int initData(void);
  72. void setDrawObjects(Bool val, Bool waypoints, Bool poly, Bool bounding, Bool sight, Bool weapon, Bool sound, Bool testart, Bool letterbox) { m_drawObjects = val; m_drawWaypoints=waypoints; m_drawPolygonAreas = poly; m_drawBoundingBoxes = bounding; m_drawSightRanges = sight; m_drawWeaponRanges = weapon; m_drawSoundRanges = sound; m_drawTestArtHighlight = testart, m_drawLetterbox = letterbox;}
  73. static void setDoBrushFeedback(Bool val) { m_toolWantsFeedback = val; m_meshFeedback=false;}
  74. static void setDoMeshFeedback(Bool val) { m_meshFeedback = val; }
  75. static void setDoRampFeedback(Bool val) { m_rampFeedback = val; }
  76. static void setDoBoundaryFeedback(Bool val) { m_boundaryFeedback = val; }
  77. static void setDoAmbientSoundFeedback(Bool val) { m_ambientSoundFeedback = val; }
  78. static void setBrushFeedbackParms(Bool square, Int width, Int featherWidth)
  79. { m_squareFeedback = square; m_brushWidth=width;
  80. m_meshFeedback = false; m_brushFeatherWidth = featherWidth;}
  81. static void disableFeedback(void) {m_disableFeedback = true;};
  82. static void enableFeedback(void) {m_disableFeedback = false;};
  83. static Bool isFeedbackEnabled(void) { return !m_disableFeedback;};
  84. static void setFeedbackPos(Coord3D pos);
  85. static void setWaypointDragFeedback(const Coord3D &start, const Coord3D &end);
  86. static void setRampFeedbackParms(const Coord3D *start, const Coord3D *end, Real rampWidth);
  87. static void stopWaypointDragFeedback();
  88. MeshClass *peekMesh(void) {return m_moldMesh;};
  89. void getMeshBounds(SphereClass *pSphere) {*pSphere = m_moldMeshBounds;};
  90. protected:
  91. enum {MAX_RADIUS = 50, NUM_FEEDBACK_VERTEX = 201*201, NUM_FEEDBACK_INDEX = 101*101*6};
  92. Int m_numTriangles; //dimensions of list
  93. DX8IndexBufferClass *m_indexBuffer; ///< indices defining a object icon
  94. ShaderClass m_shaderClass; ///< shader or rendering state for heightmap
  95. VertexMaterialClass *m_vertexMaterialClass;
  96. DX8VertexBufferClass *m_vertexBufferTile1; ///< First vertex buffer.
  97. DX8VertexBufferClass *m_vertexBufferTile2; ///< Second vertex buffer.
  98. DX8VertexBufferClass *m_vertexBufferWater; ///< Vertex buffer for the water plane.
  99. DX8IndexBufferClass *m_indexWater; ///< indices defining a triangle strip for the water on terrain
  100. Int m_waterVertexCount;
  101. WaterRenderObjClass *m_waterDrawObject;
  102. Bool m_drawObjects;
  103. Bool m_drawWaypoints;
  104. Bool m_drawPolygonAreas;
  105. Bool m_drawBoundingBoxes;
  106. Bool m_drawSightRanges;
  107. Bool m_drawWeaponRanges;
  108. Bool m_drawSoundRanges;
  109. Bool m_drawTestArtHighlight;
  110. Bool m_drawLetterbox;
  111. DX8VertexBufferClass *m_vertexFeedback; ///< Vertex buffer for brush feedback.
  112. DX8IndexBufferClass *m_indexFeedback; ///< indices defining a triangle strip for the feedback on terrain
  113. Int m_feedbackIndexCount;
  114. Int m_feedbackVertexCount;
  115. AsciiString m_curMeshModelName; ///< Model name of m_moldMesh.
  116. MeshClass *m_moldMesh; ///< W3D mesh model for the mold.
  117. SphereClass m_moldMeshBounds; ///< Bounding sphere for mold mesh.
  118. Render2DClass *m_lineRenderer; //< Used to render 2D lines for bounding boxes.
  119. CPoint m_winSize; //< Holds the size of the window.
  120. protected: // static state vars.
  121. static Bool m_squareFeedback; ///< True for square brush feedback, false for round.
  122. static Int m_brushWidth; ///< Width of brush feedback.
  123. static Int m_brushFeatherWidth; ///< Width of brush feathered feedback.
  124. static Bool m_toolWantsFeedback; ///< True to display brush feedback.
  125. static Bool m_disableFeedback; ///< True to disable feedback.
  126. static Coord3D m_feedbackPoint; ///< Current brush feedback location.
  127. static CPoint m_cellCenter; ///< Cell to show feedback from.
  128. static Bool m_meshFeedback;
  129. static Bool m_rampFeedback; ///< should we be showing feedback for the ramp tool?
  130. static Bool m_boundaryFeedback;
  131. static Bool m_ambientSoundFeedback;
  132. static Bool m_dragWaypointFeedback; ///< True for the waypoint tool dragging.
  133. static Coord3D m_dragWayStart;///< Start drag waypoint feedback.
  134. static Coord3D m_dragWayEnd; ///< End drag waypoint.
  135. static Coord3D m_rampStartPoint; ///< Beginning ramp point
  136. static Coord3D m_rampEndPoint; ///< End ramp point
  137. static Real m_rampWidth;
  138. protected:
  139. void addCircleToLineRenderer( const Coord3D & center, Real radius, Real width, unsigned long color, CameraClass* camera );
  140. Int updateVB(DX8VertexBufferClass *vertexBufferTile, Int color, Bool doArrow, Bool doDiamond);
  141. void updatePolygonVB(PolygonTrigger *pTrig, Bool selected, Bool isOpen);
  142. void updateFeedbackVB(void);
  143. void updateMeshVB(void);
  144. void updateRampVB(void);
  145. void updateWaypointVB(void);
  146. void updateForWater(void);
  147. void updateBoundaryVB(void);
  148. void updateAmbientSoundVB(void);
  149. void updateVBWithBoundingBox(MapObject *pMapObj, CameraClass* camera);
  150. void updateVBWithSightRange(MapObject *pMapObj, CameraClass* camera);
  151. void updateVBWithWeaponRange(MapObject *pMapObj, CameraClass* camera);
  152. void updateVBWithTestArtHighlight(MapObject *pMapObj, CameraClass* camera);
  153. void updateVBWithSoundRanges(MapObject *pMapObj, CameraClass* camera);
  154. bool worldToScreen(const Coord3D *w, ICoord2D *s, CameraClass* camera);
  155. };
  156. void BuildRectFromSegmentAndWidth(const Coord3D* b, const Coord3D* t, Real width,
  157. Coord3D* outBL, Coord3D* outTL, Coord3D* outBR, Coord3D* outTR);
  158. #endif // end __DRAW_OBJECT_H_