Torque3D Documentation / _generateds / depthSortList.h

depthSortList.h

Engine/source/collision/depthSortList.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 _DEPTHSORTLIST_H_
 25#define _DEPTHSORTLIST_H_
 26
 27#ifndef _CLIPPEDPOLYLIST_H_
 28#include "collision/clippedPolyList.h"
 29#endif
 30
 31
 32//----------------------------------------------------------------------------
 33
 34class DepthSortList : public ClippedPolyList
 35{
 36   typedef ClippedPolyList Parent;
 37  public:
 38   struct PolyExtents
 39   {
 40      // extents of poly on each coordinate axis
 41      F32 xMin;
 42      F32 xMax;
 43      F32 yMin;
 44      F32 yMax;
 45      F32 zMin;
 46      F32 zMax;
 47   };
 48
 49   typedef Vector<PolyExtents> PolyExtentsList;
 50   typedef Vector<U32> PolyIndexList;
 51
 52   // Internal data
 53   PolyExtentsList mPolyExtentsList;
 54   PolyIndexList mPolyIndexList;
 55   Point3F mExtent; // dimensions of the sort area
 56   S32 mBase; // base position in the list...everything before this is sorted correctly
 57   Poly * mBasePoly; // poly currently in base position
 58   Point3F * mBaseNormal; // normal of poly currently in base position
 59   F32 mBaseDot; // dot of basePoly with baseNormal
 60   F32 mBaseYMax; // max y extent of base poly
 61   S32 mMaxTouched; // highest index swapped into thus far...y-extents may be improperly sorted before this index
 62   PolyExtents * mBaseExtents; // x,y,z extents of basePoly
 63
 64   // set the base position -- everything before this point should be correctly sorted
 65   void setBase(S32);
 66
 67   // some utilities used for sorting
 68   bool splitPoly(const Poly & sourcePoly, Point3F & normal, F32 k, Poly & front, Poly & back);
 69   bool overlap(Poly *, Poly *);
 70   void handleOverlap(Poly * testPoly, Point3F & testNormal, F32 testDot, S32 & testOffset, bool & switched);
 71   void sortByYExtents();
 72   void setExtents(Poly &, PolyExtents &);
 73
 74   // one iteration of the sort routine -- finds a poly to fill current base position
 75   bool sortNext();
 76
 77   // used by depthPartition
 78   void cookieCutter(Poly & cutter, Poly & cuttee,
 79                     Vector<Poly> & scraps,
 80                     Vector<Poly> & cookies, Vector<Point3F> & cookieVerts);
 81
 82  public:
 83
 84   //
 85   DepthSortList();
 86   ~DepthSortList();
 87   void set(const MatrixF & mat, Point3F & extents);
 88   void clear();
 89   void clearSort();
 90
 91   // the point of this class
 92   void sort();
 93   void depthPartition(const Point3F * sourceVerts, U32 numVerts, Vector<Poly> & partition, Vector<Point3F> & partitionVerts);
 94
 95   // Virtual methods
 96   void end();
 97   // U32  addPoint(const Point3F& p);
 98   // bool isEmpty() const;
 99   // void begin(U32 material,U32 surfaceKey);
100   // void plane(U32 v1,U32 v2,U32 v3);
101   // void plane(const PlaneF& p);
102   // void vertex(U32 vi);
103   bool getMapping(MatrixF *, Box3F *);
104
105   // access to the polys in order (note: returned pointers are volatile, may change if polys added).
106   void getOrderedPoly(U32 ith, Poly ** poly, PolyExtents ** polyExtent);
107
108   // unordered access
109   PolyExtents & getExtents(U32 idx) { return mPolyExtentsList[idx]; }
110   Poly & getPoly(U32 idx) { return mPolyList[idx]; }
111};
112
113inline void DepthSortList::getOrderedPoly(U32 ith, Poly ** poly, PolyExtents ** polyExtent)
114{
115   *poly = &mPolyList[mPolyIndexList[ith]];
116   *polyExtent = &mPolyExtentsList[mPolyIndexList[ith]];
117}
118
119#endif
120