abstractPolyList.cpp
Engine/source/collision/abstractPolyList.cpp
Detailed Description
Public Variables
U32 PolyFace [6][4]
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 "collision/abstractPolyList.h" 25 26 27//---------------------------------------------------------------------------- 28 29AbstractPolyList::~AbstractPolyList() 30{ 31 mInterestNormalRegistered = false; 32} 33 34static U32 PolyFace[6][4] = { 35 { 3, 2, 1, 0 }, 36 { 7, 4, 5, 6 }, 37 { 0, 5, 4, 3 }, 38 { 6, 5, 0, 1 }, 39 { 7, 6, 1, 2 }, 40 { 4, 7, 2, 3 }, 41}; 42 43void AbstractPolyList::addBox(const Box3F &box, BaseMatInstance* material) 44{ 45 Point3F pos = box.minExtents; 46 F32 dx = box.maxExtents.x - box.minExtents.x; 47 F32 dy = box.maxExtents.y - box.minExtents.y; 48 F32 dz = box.maxExtents.z - box.minExtents.z; 49 50 U32 base = addPoint(pos); 51 pos.y += dy; addPoint(pos); 52 pos.x += dx; addPoint(pos); 53 pos.y -= dy; addPoint(pos); 54 pos.z += dz; addPoint(pos); 55 pos.x -= dx; addPoint(pos); 56 pos.y += dy; addPoint(pos); 57 pos.x += dx; addPoint(pos); 58 59 for (S32 i = 0; i < 6; i++) { 60 S32 v1 = base + PolyFace[i][0]; 61 S32 v2 = base + PolyFace[i][1]; 62 S32 v3 = base + PolyFace[i][2]; 63 S32 v4 = base + PolyFace[i][3]; 64 // First triangle 65 begin(material, i); 66 vertex(v1); 67 vertex(v2); 68 vertex(v3); 69 plane(v1, v2, v3); 70 end(); 71 // Second triangle 72 begin(material, i); 73 vertex(v3); 74 vertex(v4); 75 vertex(v1); 76 plane(v3, v4, v1); 77 end(); 78 } 79} 80 81bool AbstractPolyList::getMapping(MatrixF *, Box3F *) 82{ 83 // return list transform and bounds in list space...optional 84 return false; 85} 86 87 88bool AbstractPolyList::isInterestedInPlane(const PlaneF& plane) 89{ 90 if (mInterestNormalRegistered == false) { 91 return true; 92 } 93 else { 94 PlaneF xformed; 95 mPlaneTransformer.transform(plane, xformed); 96 if (mDot(xformed, mInterestNormal) >= 0.0f) 97 return false; 98 else 99 return true; 100 } 101} 102 103bool AbstractPolyList::isInterestedInPlane(const U32 index) 104{ 105 if (mInterestNormalRegistered == false) { 106 return true; 107 } 108 else { 109 const PlaneF& rPlane = getIndexedPlane(index); 110 if (mDot(rPlane, mInterestNormal) >= 0.0f) 111 return false; 112 else 113 return true; 114 } 115} 116 117void AbstractPolyList::setInterestNormal(const Point3F& normal) 118{ 119 mInterestNormalRegistered = true; 120 mInterestNormal = normal; 121} 122 123