planeExtractor.cpp
Engine/source/collision/planeExtractor.cpp
Public Variables
Detailed Description
Public Variables
F32 DistanceEpsilon
F32 NormalEpsilon
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#include "platform/platform.h" 25#include "math/mMath.h" 26#include "console/console.h" 27#include "collision/planeExtractor.h" 28 29//---------------------------------------------------------------------------- 30// Plane matching parameters 31static F32 NormalEpsilon = 0.93969f; // 20 deg. 32static F32 DistanceEpsilon = 100.0f; 33 34 35//---------------------------------------------------------------------------- 36 37PlaneExtractorPolyList::PlaneExtractorPolyList() 38{ 39 VECTOR_SET_ASSOCIATION(mVertexList); 40 VECTOR_SET_ASSOCIATION(mPolyPlaneList); 41 mPlaneList = NULL; 42} 43 44PlaneExtractorPolyList::~PlaneExtractorPolyList() 45{ 46} 47 48 49//---------------------------------------------------------------------------- 50 51void PlaneExtractorPolyList::clear() 52{ 53 mVertexList.clear(); 54 mPolyPlaneList.clear(); 55} 56 57U32 PlaneExtractorPolyList::addPoint(const Point3F& p) 58{ 59 mVertexList.increment(); 60 Point3F& v = mVertexList.last(); 61 v.x = p.x * mScale.x; 62 v.y = p.y * mScale.y; 63 v.z = p.z * mScale.z; 64 mMatrix.mulP(v); 65 return mVertexList.size() - 1; 66} 67 68U32 PlaneExtractorPolyList::addPlane(const PlaneF& plane) 69{ 70 mPolyPlaneList.increment(); 71 mPlaneTransformer.transform(plane, mPolyPlaneList.last()); 72 73 return mPolyPlaneList.size() - 1; 74} 75 76 77//---------------------------------------------------------------------------- 78 79void PlaneExtractorPolyList::plane(U32 v1,U32 v2,U32 v3) 80{ 81 mPlaneList->last().set(mVertexList[v1], 82 mVertexList[v2],mVertexList[v3]); 83} 84 85void PlaneExtractorPolyList::plane(const PlaneF& p) 86{ 87 mPlaneTransformer.transform(p, mPlaneList->last()); 88} 89 90void PlaneExtractorPolyList::plane(const U32 index) 91{ 92 AssertFatal(index < mPolyPlaneList.size(), "Out of bounds index!"); 93 mPlaneList->last() = mPolyPlaneList[index]; 94} 95 96const PlaneF& PlaneExtractorPolyList::getIndexedPlane(const U32 index) 97{ 98 AssertFatal(index < mPolyPlaneList.size(), "Out of bounds index!"); 99 return mPolyPlaneList[index]; 100} 101 102 103//---------------------------------------------------------------------------- 104 105bool PlaneExtractorPolyList::isEmpty() const 106{ 107 return true; 108} 109 110void PlaneExtractorPolyList::begin(BaseMatInstance*,U32) 111{ 112 mPlaneList->increment(); 113} 114 115void PlaneExtractorPolyList::end() 116{ 117 // See if there are any duplicate planes 118 PlaneF &plane = mPlaneList->last(); 119 PlaneF *ptr = mPlaneList->begin(); 120 for (; ptr != &plane; ptr++) 121 if (mFabs(ptr->d - plane.d) < DistanceEpsilon && 122 mDot(*ptr,plane) > NormalEpsilon) { 123 mPlaneList->decrement(); 124 return; 125 } 126} 127 128void PlaneExtractorPolyList::vertex(U32) 129{ 130} 131 132