gjk.h

Engine/source/collision/gjk.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 _GJK_H_
25#define _GJK_H_
26
27#ifndef _MMATH_H_
28#include "math/mMath.h"
29#endif
30#ifndef _TVECTOR_H_
31#include "core/util/tVector.h"
32#endif
33#ifndef _CONVEX_H_
34#include "collision/convex.h"
35#endif
36
37class Convex;
38struct CollisionStateList;
39struct Collision;
40
41//----------------------------------------------------------------------------
42
43struct GjkCollisionState: public CollisionState
44{
45   /// @name Temporary values
46   /// @{
47   Point3F mP[4];     ///< support points of object A in local coordinates
48   Point3F mQ[4];     ///< support points of object B in local coordinates
49   VectorF mY[4];     ///< support points of A - B in world coordinates
50
51   S32 mBits;         ///< identifies current simplex
52   S32 mAll_bits;     ///< all_bits = bits | last_bit
53   F32 mDet[16][4];   ///< cached sub-determinants
54   F32 mDP[4][4];     ///< cached dot products
55
56   S32 mLast;         ///< identifies last found support point
57   S32 mLast_bit;     ///< last_bit = 1<<last
58   /// @}
59
60   ///
61   void compute_det();
62   bool valid(S32 s);
63   void compute_vector(S32 bits, VectorF& v);
64   bool closest(VectorF& v);
65   bool degenerate(const VectorF& w);
66   void nextBit();
67   void swap();
68   void reset(const MatrixF& a2w, const MatrixF& b2w);
69
70   GjkCollisionState();
71   ~GjkCollisionState();
72
73   void set(Convex* a,Convex* b,const MatrixF& a2w, const MatrixF& b2w);
74
75   void getCollisionInfo(const MatrixF& mat, Collision* info);
76   void getClosestPoints(Point3F& p1, Point3F& p2);
77   bool intersect(const MatrixF& a2w, const MatrixF& b2w);
78   F32 distance(const MatrixF& a2w, const MatrixF& b2w, const F32 dontCareDist,
79                       const MatrixF* w2a = NULL, const MatrixF* _w2b = NULL);
80};
81
82
83#endif
84