W3DMirror.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. #pragma once
  24. #ifndef __W3DMirror_H_
  25. #define __W3DMirror_H_
  26. #include "always.h"
  27. #include "rendobj.h"
  28. #include "w3d_file.h"
  29. #include "dx8vertexbuffer.h"
  30. #include "dx8indexbuffer.h"
  31. #include "shader.h"
  32. #include "vertmaterial.h"
  33. #include "Lib/BaseType.h"
  34. #include "Common/GameType.h"
  35. /// Custom render object that draws mirrors, water, and skies.
  36. /**
  37. This render object handles drawing reflected W3D scenes. It will only work
  38. with rectangular planar surfaces and was tuned with an emphasis on water.
  39. Since skies are only visible in reflections, this code will also
  40. render clouds and sky bodies.
  41. */
  42. class MirrorRenderObjClass : public RenderObjClass
  43. {
  44. public:
  45. MirrorRenderObjClass(void);
  46. ~MirrorRenderObjClass(void);
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Render Object Interface (W3D methods)
  49. /////////////////////////////////////////////////////////////////////////////
  50. virtual RenderObjClass * Clone(void) const;
  51. virtual int Class_ID(void) const;
  52. virtual void Render(RenderInfoClass & rinfo);
  53. /// @todo: Add methods for collision detection with mirror surface
  54. // virtual Bool Cast_Ray(RayCollisionTestClass & raytest);
  55. // virtual Bool Cast_AABox(AABoxCollisionTestClass & boxtest);
  56. // virtual Bool Cast_OBBox(OBBoxCollisionTestClass & boxtest);
  57. // virtual Bool Intersect_AABox(AABoxIntersectionTestClass & boxtest);
  58. // virtual Bool Intersect_OBBox(OBBoxIntersectionTestClass & boxtest);
  59. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  60. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & aabox) const;
  61. ///allocate W3D resources needed to render mirror
  62. Int init(Real waterLevel, Real dx, Real dy, SceneClass *parentScene);
  63. static void setTimeOfDay(TimeOfDay tod) {m_tod=tod;} ///<change sky/water for time of day
  64. void toggleCloudLayer(Bool state) { m_useCloudLayer=state;} ///<enables/disables the cloud layer
  65. protected:
  66. DX8IndexBufferClass *m_indexBuffer; ///<indices defining quad
  67. SceneClass *m_parentScene; ///<scene to be reflected
  68. ShaderClass m_shaderClass; ///<shader or rendering state for heightmap
  69. VertexMaterialClass *m_vertexMaterialClass; ///<vertex lighting material
  70. TextureClass *m_alphaClippingTexture; ///<used for faked clipping using alpha
  71. Real m_dx; ///<x extent of mirror surface (offset from local center)
  72. Real m_dy; ///<y extent of mirror surface (offset from local center)
  73. Vector3 m_planeNormal; ///<mirror plane normal
  74. Real m_planeDistance; ///<mirror plane distance
  75. Real m_level; ///<level of mirror (hack for water)
  76. Real m_uOffset; ///<current texture offset on u axis
  77. Real m_vOffset; ///<current texture offset on v axis
  78. Real m_uScrollPerMs; ///<texels per/ms scroll rate in u direction
  79. Real m_vScrollPerMs; ///<texels per/ms scroll rate in v direction
  80. Int m_LastUpdateTime; ///<time of last cloud update
  81. Bool m_useCloudLayer; ///<flag if clouds are on/off
  82. static TimeOfDay m_tod; ///<time of day setting for reflected cloud layer
  83. struct skySetting
  84. {
  85. TextureClass *skyTexture;
  86. TextureClass *waterTexture;
  87. Int waterRepeatCount;
  88. Int skyRepeatCount;
  89. DWORD vertex00Diffuse;
  90. DWORD vertex10Diffuse;
  91. DWORD vertex11Diffuse;
  92. DWORD vertex01Diffuse;
  93. DWORD waterDiffuse;
  94. Real uScrollPerMs;
  95. Real vScrollPerMs;
  96. };
  97. skySetting m_skySettings[TIME_OF_DAY_COUNT]; ///< settings for each time of day
  98. void renderSky(void); ///<draw the sky layer (clouds, stars, etc.)
  99. void renderSkyBody(Matrix3D *mat); ///<draw the sky body (sun, moon, etc.)
  100. void renderWater(void);
  101. void renderWaterMesh(void);
  102. };
  103. #endif // end __W3DMirror_H_