polytope.h

Engine/source/collision/polytope.h

More...

Classes:

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 _POLYTOPE_H_
 25#define _POLYTOPE_H_
 26
 27#ifndef _TVECTOR_H_
 28#include "core/util/tVector.h"
 29#endif
 30
 31
 32//----------------------------------------------------------------------------
 33
 34class SimObject;
 35
 36
 37//----------------------------------------------------------------------------
 38
 39class Polytope
 40{
 41   // Convex Polyhedron
 42public:
 43   struct Vertex {
 44      Point3F point;
 45      /// Temp BSP clip info
 46      S32 side;
 47   };
 48   struct Edge {
 49      S32 vertex[2];
 50      S32 face[2];
 51      S32 next;
 52   };
 53   struct Face {
 54      PlaneF plane;
 55      S32 original;
 56      /// Temp BSP clip info
 57      S32 vertex;
 58   };
 59   struct Volume
 60   {
 61      S32 edgeList;
 62      S32 material;
 63      SimObject* object;
 64   };
 65   struct StackElement
 66   {
 67      S32 edgeList;
 68      const BSPNode *node;
 69   };
 70   struct Collision {
 71      SimObject* object;
 72      S32 material;
 73      PlaneF plane;
 74      Point3F point;
 75      F32 distance;
 76
 77      Collision()
 78      {
 79         object = NULL;
 80         material = NULL;
 81         distance = 0.0;
 82      }
 83   };
 84
 85   typedef Vector<Edge> EdgeList;
 86   typedef Vector<Face> FaceList;
 87   typedef Vector<Vertex> VertexList;
 88   typedef Vector<Volume> VolumeList;
 89   typedef Vector<StackElement> VolumeStack;
 90
 91   //
 92   S32 sideCount;
 93   EdgeList mEdgeList;
 94   FaceList mFaceList;
 95   VertexList mVertexList;
 96   VolumeList mVolumeList;
 97
 98private:
 99   bool intersect(const PlaneF& plane,const Point3F& sp,const Point3F& ep);
100
101public:
102   //
103   Polytope();
104   void buildBox(const MatrixF& transform,const Box3F& box);
105   void intersect(SimObject*, const BSPNode* node);
106   inline bool didIntersect()  { return mVolumeList.size() > 1; }
107   void extrudeFace(S32 fi,const VectorF& vec,Polytope* out);
108   bool findCollision(const VectorF& vec,Polytope::Collision *best);
109};
110
111
112
113
114#endif
115