groundPlane.h
Engine/source/T3D/groundPlane.h
Classes:
class
A virtually infinite XY ground plane primitive.
Public Variables
Detailed Description
Public Variables
const F32 GROUND_PLANE_BOX_EXTENT_HALF
const F32 GROUND_PLANE_BOX_HEIGHT_HALF
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 _TORQUE_T3D_GROUNDPLANE_H_ 25#define _TORQUE_T3D_GROUNDPLANE_H_ 26 27#ifndef _SCENEOBJECT_H_ 28#include "scene/sceneObject.h" 29#endif 30#ifndef _GFXVERTEXBUFFER_H_ 31#include "gfx/gfxVertexBuffer.h" 32#endif 33#ifndef _GFXPRIMITIVEBUFFER_H_ 34#include "gfx/gfxPrimitiveBuffer.h" 35#endif 36 37class PhysicsBody; 38class BaseMatInstance; 39 40 41/// A virtually infinite XY ground plane primitive. 42/// 43/// For rendering, a subset of the plane spanning the view frustum is generated 44/// and rendered. Tesselation is determined by the given squareSize property. 45/// 46/// For collision detection, a finite bounding box is used to deal with finite 47/// precision of floating-point operations (we can't use floating-point infinity 48/// as infinity*0 is undefined.) 49/// 50/// The ground plane can be textured like regular geometry by assigning a material 51/// name to its 'material' property. UVs mirror grid coordinates so that when 52/// using UV wrapping, textures will tile nicely. 53 54 55class GroundPlane : public SceneObject 56{ 57public: 58 59 typedef SceneObject Parent; 60 61 DECLARE_CONOBJECT( GroundPlane ); 62 63 GroundPlane(); 64 virtual ~GroundPlane(); 65 66 virtual bool onAdd(); 67 virtual void onRemove(); 68 virtual U32 packUpdate( NetConnection* connection, U32 mask, BitStream* stream ); 69 virtual void unpackUpdate( NetConnection* connection, BitStream* stream ); 70 virtual void prepRenderImage( SceneRenderState* state ); 71 virtual bool castRay( const Point3F& start, const Point3F& end, RayInfo* info ); 72 virtual void buildConvex( const Box3F& box, Convex* convex ); 73 virtual bool buildPolyList( PolyListContext context, AbstractPolyList* polyList, const Box3F& box, const SphereF& sphere ); 74 virtual void inspectPostApply(); 75 virtual void setTransform( const MatrixF &mat ); 76 virtual void setScale( const Point3F& scale ); 77 78 static void initPersistFields(); 79 80protected: 81 82 typedef GFXVertexPNTBT VertexType; 83 84 void _updateMaterial(); 85 86 void createGeometry( const Frustum& frustum ); 87 void projectFrustum( const Frustum& frustum, F32 squareSize, 88 Point2F& outMin, Point2F& outMax ); 89 void generateGrid( U32 width, U32 height, F32 squareSize, 90 const Point2F& min, const Point2F& max, 91 GFXVertexBufferHandle< VertexType>& outVertices, 92 GFXPrimitiveBufferHandle& outPrimitives ); 93 94 Box3F getPlaneBox(); 95 96private: 97 98 typedef GFXVertexBufferHandle< VertexType> VertexBuffer; 99 typedef GFXPrimitiveBufferHandle PrimitiveBuffer; 100 101 F32 mSquareSize; ///< World units per grid cell edge. 102 F32 mScaleU; ///< Scale factor for U texture coordinates. 103 F32 mScaleV; ///< Scale factor for V texture coordinates. 104 String mMaterialName; ///< Object name of material to use. 105 BaseMatInstance* mMaterial; ///< Instantiated material based on given material name. 106 107 PhysicsBody *mPhysicsRep; 108 109 /// @name Rendering State 110 /// @{ 111 112 Point2F mMin; 113 Point2F mMax; 114 VertexBuffer mVertexBuffer; 115 PrimitiveBuffer mPrimitiveBuffer; 116 GFXPrimitive mPrimitive; 117 118 /// @} 119 120 Convex* mConvexList; ///< List of collision convexes we have created; for cleanup. 121}; 122 123static const F32 GROUND_PLANE_BOX_HEIGHT_HALF = 1.0f; 124static const F32 GROUND_PLANE_BOX_EXTENT_HALF = 16000.0f; 125 126inline Box3F GroundPlane::getPlaneBox() 127{ 128 Box3F planeBox; 129 130 planeBox.minExtents = Point3F( - GROUND_PLANE_BOX_EXTENT_HALF, 131 - GROUND_PLANE_BOX_EXTENT_HALF, 132 - 0.05f ); 133 planeBox.maxExtents = Point3F( GROUND_PLANE_BOX_EXTENT_HALF, 134 GROUND_PLANE_BOX_EXTENT_HALF, 135 0.05f ); 136 return planeBox; 137} 138 139#endif // _TORQUE_T3D_GROUNDPLANE_H_ 140
