DrawObject.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. ** Command & Conquer Generals(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. //
  35. // DrawObject: Draws 3d feedback for tools & objects.
  36. //
  37. //
  38. class DrawObject : public RenderObjClass
  39. {
  40. public:
  41. DrawObject(void);
  42. DrawObject(const DrawObject & src);
  43. DrawObject & operator = (const DrawObject &);
  44. ~DrawObject(void);
  45. /////////////////////////////////////////////////////////////////////////////
  46. // Render Object Interface
  47. /////////////////////////////////////////////////////////////////////////////
  48. virtual RenderObjClass * Clone(void) const;
  49. virtual int Class_ID(void) const;
  50. virtual void Render(RenderInfoClass & rinfo);
  51. // virtual void Special_Render(SpecialRenderInfoClass & rinfo);
  52. // virtual void Set_Transform(const Matrix3D &m);
  53. // virtual void Set_Position(const Vector3 &v);
  54. //TODO: MW: do these later - only needed for collision detection
  55. virtual Bool Cast_Ray(RayCollisionTestClass & raytest);
  56. // virtual Bool Cast_AABox(AABoxCollisionTestClass & boxtest);
  57. // virtual Bool Cast_OBBox(OBBoxCollisionTestClass & boxtest);
  58. // virtual Bool Intersect_AABox(AABoxIntersectionTestClass & boxtest);
  59. // virtual Bool Intersect_OBBox(OBBoxIntersectionTestClass & boxtest);
  60. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  61. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & aabox) const;
  62. // virtual int Get_Num_Polys(void) const;
  63. // virtual const char * Get_Name(void) const;
  64. // virtual void Set_Name(const char * name);
  65. // unsigned int Get_Flags(void) { return Flags; }
  66. // void Set_Flags(unsigned int flags) { Flags = flags; }
  67. // void Set_Flag(unsigned int flag, Bool onoff) { Flags &= (~flag); if (onoff) Flags |= flag; }
  68. Int freeMapResources(void);
  69. void setDrawObjects(Bool val, Bool waypoints, Bool poly) { m_drawObjects = val; m_drawWaypoints=waypoints; m_drawPolygonAreas = poly;}
  70. static void setDoBrushFeedback(Bool val) { m_toolWantsFeedback = val; m_meshFeedback=false;}
  71. static void setDoMeshFeedback(Bool val) { m_meshFeedback = val; }
  72. static void setDoRampFeedback(Bool val) { m_rampFeedback = val; }
  73. static void setDoBoundaryFeedback(Bool val) { m_boundaryFeedback = val; }
  74. static void setDoAmbientSoundFeedback(Bool val) { m_ambientSoundFeedback = val; }
  75. static void setBrushFeedbackParms(Bool square, Int width, Int featherWidth)
  76. { m_squareFeedback = square; m_brushWidth=width;
  77. m_meshFeedback = false; m_brushFeatherWidth = featherWidth;}
  78. static void disableFeedback(void) {m_disableFeedback = true;};
  79. static void enableFeedback(void) {m_disableFeedback = false;};
  80. static Bool isFeedbackEnabled(void) { return !m_disableFeedback;};
  81. static void setFeedbackPos(Coord3D pos);
  82. static void setWaypointDragFeedback(const Coord3D &start, const Coord3D &end);
  83. static void setRampFeedbackParms(const Coord3D *start, const Coord3D *end, Real rampWidth);
  84. static void stopWaypointDragFeedback();
  85. MeshClass *peekMesh(void) {return m_moldMesh;};
  86. void getMeshBounds(SphereClass *pSphere) {*pSphere = m_moldMeshBounds;};
  87. protected:
  88. enum {MAX_RADIUS = 50, NUM_FEEDBACK_VERTEX = 201*201, NUM_FEEDBACK_INDEX = 101*101*6};
  89. Int m_numTriangles; //dimensions of list
  90. DX8IndexBufferClass *m_indexBuffer; ///< indices defining a object icon
  91. ShaderClass m_shaderClass; ///< shader or rendering state for heightmap
  92. VertexMaterialClass *m_vertexMaterialClass;
  93. DX8VertexBufferClass *m_vertexBufferTile1; ///< First vertex buffer.
  94. DX8VertexBufferClass *m_vertexBufferTile2; ///< Second vertex buffer.
  95. DX8VertexBufferClass *m_vertexBufferWater; ///< Vertex buffer for the water plane.
  96. DX8IndexBufferClass *m_indexWater; ///< indices defining a triangle strip for the water on terrain
  97. Int m_waterVertexCount;
  98. WaterRenderObjClass *m_waterDrawObject;
  99. Bool m_drawObjects;
  100. Bool m_drawWaypoints;
  101. Bool m_drawPolygonAreas;
  102. DX8VertexBufferClass *m_vertexFeedback; ///< Vertex buffer for brush feedback.
  103. DX8IndexBufferClass *m_indexFeedback; ///< indices defining a triangle strip for the feedback on terrain
  104. Int m_feedbackIndexCount;
  105. Int m_feedbackVertexCount;
  106. AsciiString m_curMeshModelName; ///< Model name of m_moldMesh.
  107. MeshClass *m_moldMesh; ///< W3D mesh model for the mold.
  108. SphereClass m_moldMeshBounds; ///< Bounding sphere for mold mesh.
  109. protected: // static state vars.
  110. static Bool m_squareFeedback; ///< True for square brush feedback, false for round.
  111. static Int m_brushWidth; ///< Width of brush feedback.
  112. static Int m_brushFeatherWidth; ///< Width of brush feathered feedback.
  113. static Bool m_toolWantsFeedback; ///< True to display brush feedback.
  114. static Bool m_disableFeedback; ///< True to disable feedback.
  115. static Coord3D m_feedbackPoint; ///< Current brush feedback location.
  116. static CPoint m_cellCenter; ///< Cell to show feedback from.
  117. static Bool m_meshFeedback;
  118. static Bool m_rampFeedback; ///< should we be showing feedback for the ramp tool?
  119. static Bool m_boundaryFeedback;
  120. static Bool m_ambientSoundFeedback;
  121. static Bool m_dragWaypointFeedback; ///< True for the waypoint tool dragging.
  122. static Coord3D m_dragWayStart;///< Start drag waypoint feedback.
  123. static Coord3D m_dragWayEnd; ///< End drag waypoint.
  124. static Coord3D m_rampStartPoint; ///< Beginning ramp point
  125. static Coord3D m_rampEndPoint; ///< End ramp point
  126. static Real m_rampWidth;
  127. protected:
  128. int initData(void);
  129. Int updateVB(DX8VertexBufferClass *vertexBufferTile, Int color, Bool doArrow, Bool doDiamond);
  130. void updatePolygonVB(PolygonTrigger *pTrig, Bool selected, Bool isOpen);
  131. void updateFeedbackVB(void);
  132. void updateMeshVB(void);
  133. void updateRampVB(void);
  134. void updateWaypointVB(void);
  135. void updateForWater(void);
  136. void updateBoundaryVB(void);
  137. void updateAmbientSoundVB(void);
  138. };
  139. void BuildRectFromSegmentAndWidth(const Coord3D* b, const Coord3D* t, Real width,
  140. Coord3D* outBL, Coord3D* outTL, Coord3D* outBR, Coord3D* outTR);
  141. #endif // end __DRAW_OBJECT_H_