extrudedPolyList.h
Engine/source/collision/extrudedPolyList.h
Classes:
class
Extruded Polytope PolyList.
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 _EXTRUDEDPOLYLIST_H_ 25#define _EXTRUDEDPOLYLIST_H_ 26 27#ifndef _MMATH_H_ 28#include "math/mMath.h" 29#endif 30 31#ifndef _MPOLYHEDRON_H_ 32#include "math/mPolyhedron.h" 33#endif 34 35#ifndef _TVECTOR_H_ 36#include "core/util/tVector.h" 37#endif 38 39#ifndef _ABSTRACTPOLYLIST_H_ 40#include "collision/abstractPolyList.h" 41#endif 42 43 44class CollisionList; 45 46 47//---------------------------------------------------------------------------- 48/// Extruded Polytope PolyList 49/// 50/// This class is used primarily for collision detection, by objects which need 51/// to check for obstructions along their path. You feed it a polytope to 52/// extrude along the direction of movement, and it gives you a list of collisions. 53/// 54/// @see AbstractPolyList 55class ExtrudedPolyList: public AbstractPolyList 56{ 57public: 58 struct Vertex { 59 Point3F point; 60 U32 mask = 0; 61 }; 62 63 struct Poly { 64 PlaneF plane; 65 SceneObject* object; 66 BaseMatInstance* material; 67 Poly() : object(NULL), material(NULL) {} 68 ~Poly() {} 69 }; 70 71 struct ExtrudedFace { 72 bool active; 73 PlaneF plane; 74 F32 maxDistance; 75 U32 planeMask; 76 F32 faceDot; 77 F32 faceShift; 78 F32 time; 79 Point3F point; 80 F32 height; 81 ExtrudedFace(): active(false), maxDistance(0.0f), planeMask(0), faceDot(0.0f), faceShift(0.0f), time(0.0f), height(0.0f) {} 82 ~ExtrudedFace() {} 83 }; 84 85 typedef Vector<ExtrudedFace> ExtrudedList; 86 typedef Vector<PlaneF> PlaneList; 87 typedef Vector<Vertex> VertexList; 88 typedef Vector<U32> IndexList; 89 90 static F32 EqualEpsilon; 91 static F32 FaceEpsilon; 92 93 // Internal data 94 VertexList mVertexList; 95 IndexList mIndexList; 96 ExtrudedList mExtrudedList; 97 PlaneList mPlaneList; 98 VectorF mVelocity; 99 VectorF mNormalVelocity; 100 Poly mPoly; 101 102 // Returned info 103 CollisionList* mCollisionList; 104 105 PlaneList mPolyPlaneList; 106 107 // 108private: 109 bool testPoly(ExtrudedFace&); 110 111public: 112 ExtrudedPolyList(); 113 ~ExtrudedPolyList(); 114 void extrude(const Polyhedron&, const VectorF& vec); 115 void setVelocity(const VectorF& velocity); 116 void setCollisionList(CollisionList*); 117 void adjustCollisionTime(); 118 119 // Virtual methods 120 bool isEmpty() const; 121 U32 addPoint(const Point3F& p); 122 U32 addPlane(const PlaneF& plane); 123 void begin(BaseMatInstance* material, U32 surfaceKey); 124 void plane(U32 v1,U32 v2,U32 v3); 125 void plane(const PlaneF& p); 126 void plane(const U32 index); 127 void vertex(U32 vi); 128 void end(); 129 130 protected: 131 const PlaneF& getIndexedPlane(const U32 index); 132}; 133 134#endif 135