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