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 = 0; 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 Poly() :object(NULL), material(NULL), vertexStart(0), vertexCount(0), surfaceKey(0), polyFlags(0) {} 66 ~Poly() {} 67 }; 68 69 /// ??? 70 static bool allowClipping; 71 72 typedef Vector<PlaneF> PlaneList; 73 typedef Vector<Vertex> VertexList; 74 typedef Vector<Poly> PolyList; 75 typedef FastVector<U32> IndexList; 76 77 typedef PlaneList::iterator PlaneListIterator; 78 typedef VertexList::iterator VertexListIterator; 79 typedef PolyList::iterator PolyListIterator; 80 typedef IndexList::iterator IndexListIterator; 81 82 // Internal data 83 PolyList mPolyList; 84 VertexList mVertexList; 85 IndexList mIndexList; 86 87 // Temporary lists used by triangulate and kept 88 // here to reduce memory allocations. 89 PolyList mTempPolyList; 90 IndexList mTempIndexList; 91 92 const static U32 IndexListReserveSize = 128; 93 94 /// The per-vertex normals. 95 /// @see generateNormals() 96 Vector<VectorF> mNormalList; 97 98 PlaneList mPolyPlaneList; 99 100 /// The list of planes to clip against. 101 /// 102 /// This should be set before filling the polylist. 103 PlaneList mPlaneList; 104 105 /// If non-zero any poly facing away from this 106 /// normal is removed from the list. 107 /// 108 /// This should be set before filling the polylist. 109 VectorF mNormal; 110 111 /// If the dot product result between a poly's normal and mNormal is greater 112 /// than this value it will be rejected. 113 /// The default value is 0. 114 /// 90 degrees = mCos( mDegToRad( 90.0f ) = 0 115 F32 mNormalTolCosineRadians; 116 117 // 118 ClippedPolyList(); 119 ~ClippedPolyList(); 120 void clear(); 121 122 // AbstractPolyList 123 bool isEmpty() const; 124 U32 addPoint(const Point3F& p); 125 U32 addPointAndNormal(const Point3F& p, const Point3F& normal); 126 U32 addPlane(const PlaneF& plane); 127 void begin(BaseMatInstance* material,U32 surfaceKey); 128 void plane(U32 v1,U32 v2,U32 v3); 129 void plane(const PlaneF& p); 130 void plane(const U32 index); 131 void vertex(U32 vi); 132 void end(); 133 134 /// Often after clipping you'll end up with orphan verticies 135 /// that are unused by the poly list. This removes these unused 136 /// verts and updates the index list. 137 void cullUnusedVerts(); 138 139 /// This breaks all polys in the polylist into triangles. 140 void triangulate(); 141 142 /// Generates averaged normals from the poly normals. 143 /// @see mNormalList 144 void generateNormals(); 145 146 protected: 147 148 // AbstractPolyList 149 const PlaneF& getIndexedPlane(const U32 index); 150}; 151 152 153#endif 154