optimizedPolyList.h
Engine/source/collision/optimizedPolyList.h
Classes:
class
A concrete, renderable PolyList.
Public Defines
define
DEV() 0.01
Detailed Description
Public Defines
DEV() 0.01
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 _OPTIMIZEDPOLYLIST_H_ 25#define _OPTIMIZEDPOLYLIST_H_ 26 27#ifndef _ABSTRACTPOLYLIST_H_ 28#include "collision/abstractPolyList.h" 29#endif 30 31#ifndef _MPOLYHEDRON_H_ 32#include "math/mPolyhedron.h" 33#endif 34 35#define DEV 0.01 36 37/// A concrete, renderable PolyList 38/// 39/// This class is used to store geometry from a PolyList query. 40/// 41/// @see AbstractPolyList 42class OptimizedPolyList : public AbstractPolyList 43{ 44 public: 45 46 enum PolyType 47 { 48 TriangleFan, 49 TriangleStrip, 50 TriangleList 51 }; 52 53 struct VertIndex 54 { 55 S32 vertIdx; 56 S32 normalIdx; 57 S32 uv0Idx; 58 S32 uv1Idx; 59 60 VertIndex() 61 : vertIdx( -1 ), 62 normalIdx ( -1 ), 63 uv0Idx( -1 ), 64 uv1Idx( -1 ) 65 { 66 } 67 68 bool operator==(const VertIndex& _test) const 69 { 70 return ( vertIdx == _test.vertIdx && 71 normalIdx == _test.normalIdx && 72 uv0Idx == _test.uv0Idx && 73 uv1Idx == _test.uv1Idx ); 74 } 75 }; 76 77 struct Poly 78 { 79 S32 plane; 80 S32 material; 81 U32 vertexStart; 82 U32 vertexCount; 83 U32 surfaceKey; 84 85 SceneObject* object; 86 87 PolyType type; 88 89 Poly() 90 : plane( -1 ), 91 material( NULL ), 92 vertexCount( 0 ), 93 object( NULL ), 94 type( TriangleFan ) 95 { 96 } 97 }; 98 99 // Vertex data 100 Vector<Point3F> mPoints; 101 Vector<Point3F> mNormals; 102 Vector<Point2F> mUV0s; 103 Vector<Point2F> mUV1s; 104 105 // List of the VertIndex structure that puts 106 // all of the vertex data together 107 Vector<VertIndex> mVertexList; 108 109 // Polygon data 110 Vector<U32> mIndexList; 111 Vector<PlaneF> mPlaneList; 112 113 Vector<BaseMatInstance*> mMaterialList; 114 115 // The Polygon structure puts the vertex data 116 // and the polygon together 117 Vector<Poly> mPolyList; 118 119 public: 120 OptimizedPolyList(); 121 ~OptimizedPolyList(); 122 void clear(); 123 124 // Virtual methods 125 U32 addPoint(const Point3F& p); 126 U32 addPlane(const PlaneF& plane); 127 128 void begin(BaseMatInstance* material, U32 surfaceKey); 129 void begin(BaseMatInstance* material, U32 surfaceKey, PolyType type); 130 void plane(U32 v1, U32 v2, U32 v3); 131 void plane(const PlaneF& p); 132 void plane(const U32 index); 133 void vertex(U32 vi); 134 void vertex(const Point3F& p); 135 void vertex(const Point3F& p, 136 const Point3F& normal, 137 const Point2F& uv0 = Point2F(0.0f, 0.0f), 138 const Point2F& uv1 = Point2F(0.0f, 0.0f)); 139 void end(); 140 141 U32 insertPoint(const Point3F& point); 142 U32 insertNormal(const Point3F& normal); 143 U32 insertUV0(const Point2F& uv); 144 U32 insertUV1(const Point2F& uv); 145 U32 insertPlane(const PlaneF& plane); 146 U32 insertMaterial(BaseMatInstance* baseMat); 147 148 U32 insertVertex(const Point3F& point, 149 const Point3F& normal = Point3F(0.0f, 0.0f, 1.0f), 150 const Point2F& uv0 = Point2F(0.0f, 0.0f), 151 const Point2F& uv1 = Point2F(0.0f, 0.0f)); 152 153 bool isEmpty() const; 154 155 Polyhedron toPolyhedron() const; 156 157 protected: 158 const PlaneF& getIndexedPlane(const U32 index); 159}; 160 161#endif // _OPTIMIZEDPOLYLIST_H_ 162
