waterBlock.h

Engine/source/environment/waterBlock.h

More...

Classes:

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