waterBlock.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 _WATERBLOCK_H_
  23. #define _WATERBLOCK_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 _WATEROBJECT_H_
  43. #include "waterObject.h"
  44. #endif
  45. //*****************************************************************************
  46. // WaterBlock
  47. //*****************************************************************************
  48. class WaterBlock : public WaterObject
  49. {
  50. typedef WaterObject Parent;
  51. public:
  52. // LEGACY support
  53. enum EWaterType
  54. {
  55. eWater = 0,
  56. eOceanWater = 1,
  57. eRiverWater = 2,
  58. eStagnantWater = 3,
  59. eLava = 4,
  60. eHotLava = 5,
  61. eCrustyLava = 6,
  62. eQuicksand = 7,
  63. };
  64. private:
  65. enum MaskBits {
  66. UpdateMask = Parent::NextFreeMask,
  67. NextFreeMask = Parent::NextFreeMask << 1
  68. };
  69. // vertex / index buffers
  70. Vector< GFXVertexBufferHandle<GFXWaterVertex>* > mVertBuffList;
  71. Vector<GFXPrimitiveBufferHandle*> mPrimBuffList;
  72. GFXVertexBufferHandle<GFXVertexPC> mRadialVertBuff;
  73. GFXPrimitiveBufferHandle mRadialPrimBuff;
  74. // misc
  75. F32 mGridElementSize;
  76. U32 mWidth;
  77. U32 mHeight;
  78. F32 mElapsedTime;
  79. GFXTexHandle mBumpTex;
  80. bool mGenerateVB;
  81. // reflect plane
  82. //ReflectPlane mReflectPlane;
  83. //Point3F mReflectPlaneWorldPos;
  84. GFXTexHandle mReflectTex;
  85. // Stateblocks
  86. GFXStateBlockRef mUnderwaterSB;
  87. void setupVertexBlock( U32 width, U32 height, U32 rowOffset );
  88. void setupPrimitiveBlock( U32 width, U32 height );
  89. void setMultiPassProjection();
  90. void clearVertBuffers();
  91. static bool setGridSizeProperty( void *object, const char *index, const char *data );
  92. protected:
  93. //-------------------------------------------------------
  94. // Standard engine functions
  95. //-------------------------------------------------------
  96. bool onAdd();
  97. void onRemove();
  98. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
  99. void unpackUpdate(NetConnection *conn, BitStream *stream);
  100. bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
  101. public:
  102. WaterBlock();
  103. virtual ~WaterBlock();
  104. DECLARE_CONOBJECT(WaterBlock);
  105. static void initPersistFields();
  106. void onStaticModified( const char* slotName, const char*newValue = NULL );
  107. virtual void inspectPostApply();
  108. virtual void setTransform( const MatrixF & mat );
  109. virtual void setScale( const Point3F &scale );
  110. virtual bool buildPolyList( PolyListContext context, AbstractPolyList* polyList, const Box3F& box, const SphereF& sphere );
  111. // WaterObject
  112. virtual F32 getWaterCoverage( const Box3F &worldBox ) const;
  113. virtual F32 getSurfaceHeight( const Point2F &pos ) const;
  114. virtual bool isUnderwater( const Point3F &pnt ) const;
  115. // WaterBlock
  116. bool isPointSubmerged ( const Point3F &pos, bool worldSpace = true ) const{ return true; }
  117. // SceneObject.
  118. virtual F32 distanceTo( const Point3F& pos ) const;
  119. protected:
  120. // WaterObject
  121. virtual void setShaderParams( SceneRenderState *state, BaseMatInstance *mat, const WaterMatParams &paramHandles );
  122. virtual SceneData setupSceneGraphInfo( SceneRenderState *state );
  123. virtual void setupVBIB();
  124. virtual void innerRender( SceneRenderState *state );
  125. virtual void _getWaterPlane( const Point3F &camPos, PlaneF &outPlane, Point3F &outPos );
  126. };
  127. #endif // _WATERBLOCK_H_