waterPlane.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _WATERPLANE_H_
  23. #define _WATERPLANE_H_
  24. #ifndef _GAMEBASE_H_
  25. #include "T3D/gameBase/gameBase.h"
  26. #endif
  27. #ifndef _GFXDEVICE_H_
  28. #include "gfx/gfxDevice.h"
  29. #endif
  30. #ifndef _SCENEDATA_H_
  31. #include "materials/sceneData.h"
  32. #endif
  33. #ifndef _MATINSTANCE_H_
  34. #include "materials/matInstance.h"
  35. #endif
  36. #ifndef _GFXPRIMITIVEBUFFER_H_
  37. #include "gfx/gfxPrimitiveBuffer.h"
  38. #endif
  39. #ifndef _RENDERPASSMANAGER_H_
  40. #include "renderInstance/renderPassManager.h"
  41. #endif
  42. #ifndef _MATHUTIL_FRUSTUM_H_
  43. #include "math/util/frustum.h"
  44. #endif
  45. #ifndef _WATEROBJECT_H_
  46. #include "environment/waterObject.h"
  47. #endif
  48. //*****************************************************************************
  49. // WaterPlane
  50. //*****************************************************************************
  51. class WaterPlane : public WaterObject
  52. {
  53. typedef WaterObject Parent;
  54. public:
  55. // LEGACY support
  56. enum EWaterType
  57. {
  58. eWater = 0,
  59. eOceanWater = 1,
  60. eRiverWater = 2,
  61. eStagnantWater = 3,
  62. eLava = 4,
  63. eHotLava = 5,
  64. eCrustyLava = 6,
  65. eQuicksand = 7,
  66. };
  67. private:
  68. enum MaskBits {
  69. UpdateMask = Parent::NextFreeMask,
  70. NextFreeMask = Parent::NextFreeMask << 1
  71. };
  72. // vertex / index buffers
  73. GFXVertexBufferHandle<GFXWaterVertex> mVertBuff;
  74. GFXPrimitiveBufferHandle mPrimBuff;
  75. // misc
  76. U32 mGridSize;
  77. U32 mGridSizeMinusOne;
  78. F32 mGridElementSize;
  79. U32 mVertCount;
  80. U32 mIndxCount;
  81. U32 mPrimCount;
  82. Frustum mFrustum;
  83. SceneData setupSceneGraphInfo( SceneRenderState *state );
  84. void setShaderParams( SceneRenderState *state, BaseMatInstance* mat, const WaterMatParams& paramHandles );
  85. void setupVBIB( SceneRenderState *state );
  86. virtual void prepRenderImage( SceneRenderState *state );
  87. virtual void innerRender( SceneRenderState *state );
  88. void setMultiPassProjection();
  89. protected:
  90. //-------------------------------------------------------
  91. // Standard engine functions
  92. //-------------------------------------------------------
  93. bool onAdd();
  94. void onRemove();
  95. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
  96. void unpackUpdate(NetConnection *conn, BitStream *stream);
  97. bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
  98. public:
  99. WaterPlane();
  100. virtual ~WaterPlane();
  101. DECLARE_CONOBJECT(WaterPlane);
  102. static void initPersistFields();
  103. void onStaticModified( const char* slotName, const char*newValue = NULL );
  104. virtual void inspectPostApply();
  105. virtual void setTransform( const MatrixF & mat );
  106. virtual F32 distanceTo( const Point3F& point ) const;
  107. virtual bool buildPolyList( PolyListContext context, AbstractPolyList* polyList, const Box3F& box, const SphereF& sphere );
  108. // WaterObject
  109. virtual F32 getWaterCoverage( const Box3F &worldBox ) const;
  110. virtual F32 getSurfaceHeight( const Point2F &pos ) const;
  111. virtual void onReflectionInfoChanged();
  112. virtual bool isUnderwater( const Point3F &pnt ) const;
  113. // WaterBlock
  114. bool isPointSubmerged ( const Point3F &pos, bool worldSpace = true ) const{ return true; }
  115. // WaterPlane
  116. void setGridSize( U32 inSize );
  117. void setGridElementSize( F32 inSize );
  118. // Protected Set'ers
  119. static bool protectedSetGridSize( void *object, const char *index, const char *data );
  120. static bool protectedSetGridElementSize( void *object, const char *index, const char *data );
  121. protected:
  122. // WaterObject
  123. virtual void _getWaterPlane( const Point3F &camPos, PlaneF &outPlane, Point3F &outPos );
  124. };
  125. #endif // _WATERPLANE_H_