clippedPolyList.h
Engine/source/collision/clippedPolyList.h
Classes:
class
The clipped polylist class takes the geometry passed to it and clips it against the PlaneList set.
Public Defines
define
Detailed Description
Public Defines
CLIPPEDPOLYLIST_FLAG_ALLOWCLIPPING() 0x01
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 _CLIPPEDPOLYLIST_H_ 25#define _CLIPPEDPOLYLIST_H_ 26 27#ifndef _MMATH_H_ 28#include "math/mMath.h" 29#endif 30#ifndef _TVECTORSPEC_H_ 31#include "core/util/tVectorSpecializations.h" 32#endif 33#ifndef _ABSTRACTPOLYLIST_H_ 34#include "collision/abstractPolyList.h" 35#endif 36 37 38#define CLIPPEDPOLYLIST_FLAG_ALLOWCLIPPING 0x01 39 40 41/// The clipped polylist class takes the geometry passed to it and clips 42/// it against the PlaneList set. 43/// 44/// It also contains helper functions for 45/// @see AbstractPolyList 46class ClippedPolyList : public AbstractPolyList 47{ 48 void memcpy(U32* d, U32* s,U32 size); 49 50public: 51 struct Vertex { 52 Point3F point; 53 U32 mask; 54 }; 55 56 struct Poly { 57 PlaneF plane; 58 SceneObject* object; 59 BaseMatInstance* material; 60 61 U32 vertexStart; 62 U32 vertexCount; 63 U32 surfaceKey; 64 U32 polyFlags; 65 }; 66 67 /// ??? 68 static bool allowClipping; 69 70 typedef Vector<PlaneF> PlaneList; 71 typedef Vector<Vertex> VertexList; 72 typedef Vector<Poly> PolyList; 73 typedef FastVector<U32> IndexList; 74 75 typedef PlaneList::iterator PlaneListIterator; 76 typedef VertexList::iterator VertexListIterator; 77 typedef PolyList::iterator PolyListIterator; 78 typedef IndexList::iterator IndexListIterator; 79 80 // Internal data 81 PolyList mPolyList; 82 VertexList mVertexList; 83 IndexList mIndexList; 84 85 // Temporary lists used by triangulate and kept 86 // here to reduce memory allocations. 87 PolyList mTempPolyList; 88 IndexList mTempIndexList; 89 90 const static U32 IndexListReserveSize = 128; 91 92 /// The per-vertex normals. 93 /// @see generateNormals() 94 Vector<VectorF> mNormalList; 95 96 PlaneList mPolyPlaneList; 97 98 /// The list of planes to clip against. 99 /// 100 /// This should be set before filling the polylist. 101 PlaneList mPlaneList; 102 103 /// If non-zero any poly facing away from this 104 /// normal is removed from the list. 105 /// 106 /// This should be set before filling the polylist. 107 VectorF mNormal; 108 109 /// If the dot product result between a poly's normal and mNormal is greater 110 /// than this value it will be rejected. 111 /// The default value is 0. 112 /// 90 degrees = mCos( mDegToRad( 90.0f ) = 0 113 F32 mNormalTolCosineRadians; 114 115 // 116 ClippedPolyList(); 117 ~ClippedPolyList(); 118 void clear(); 119 120 // AbstractPolyList 121 bool isEmpty() const; 122 U32 addPoint(const Point3F& p); 123 U32 addPointAndNormal(const Point3F& p, const Point3F& normal); 124 U32 addPlane(const PlaneF& plane); 125 void begin(BaseMatInstance* material,U32 surfaceKey); 126 void plane(U32 v1,U32 v2,U32 v3); 127 void plane(const PlaneF& p); 128 void plane(const U32 index); 129 void vertex(U32 vi); 130 void end(); 131 132 /// Often after clipping you'll end up with orphan verticies 133 /// that are unused by the poly list. This removes these unused 134 /// verts and updates the index list. 135 void cullUnusedVerts(); 136 137 /// This breaks all polys in the polylist into triangles. 138 void triangulate(); 139 140 /// Generates averaged normals from the poly normals. 141 /// @see mNormalList 142 void generateNormals(); 143 144 protected: 145 146 // AbstractPolyList 147 const PlaneF& getIndexedPlane(const U32 index); 148}; 149 150 151#endif 152
