OPC_Common.h
Go to the documentation of this file.
1 /*
3  * OPCODE - Optimized Collision Detection
4  * Copyright (C) 2001 Pierre Terdiman
5  * Homepage: http://www.codercorner.com/Opcode.htm
6  */
8 
10 
16 
19 // Include Guard
20 #ifndef __OPC_COMMON_H__
21 #define __OPC_COMMON_H__
22 
23 // [GOTTFRIED]: Just a small change for readability.
24 #ifdef OPC_CPU_COMPARE
25  #define GREATER(x, y) AIR(x) > IR(y)
26 #else
27  #define GREATER(x, y) fabsf(x) > (y)
28 #endif
29 
31  {
32  public:
36  inline_ CollisionAABB(const AABB& b) { b.GetCenter(mCenter); b.GetExtents(mExtents); }
39 
41  inline_ void GetMin(Point& min) const { min = mCenter - mExtents; }
43  inline_ void GetMax(Point& max) const { max = mCenter + mExtents; }
44 
46  inline_ float GetMin(udword axis) const { return mCenter[axis] - mExtents[axis]; }
48  inline_ float GetMax(udword axis) const { return mCenter[axis] + mExtents[axis]; }
49 
51 
56  inline_ void SetMinMax(const Point& min, const Point& max) { mCenter = (max + min)*0.5f; mExtents = (max - min)*0.5f; }
58 
60 
65  inline_ BOOL IsInside(const CollisionAABB& box) const
67  {
68  if(box.GetMin(0)>GetMin(0)) return FALSE;
69  if(box.GetMin(1)>GetMin(1)) return FALSE;
70  if(box.GetMin(2)>GetMin(2)) return FALSE;
71  if(box.GetMax(0)<GetMax(0)) return FALSE;
72  if(box.GetMax(1)<GetMax(1)) return FALSE;
73  if(box.GetMax(2)<GetMax(2)) return FALSE;
74  return TRUE;
75  }
76 
79 #if 1 // Added by AIST
80  typedef enum {SSV_PSS, SSV_LSS} ssv_type;
81  ssv_type mType;
82  float mRadius;
83  Point mPoint0, mPoint1;
84  void CreateSSV(){
85  PointComponent maxAxis, minAxis;
86  maxAxis = mExtents.LargestAxis();
87  minAxis = mExtents.SmallestAxis();
88  if (mExtents[minAxis] > 0 && mExtents[maxAxis]/mExtents[minAxis] > 2){
89  mType = SSV_LSS;
90  mPoint0 = mCenter;
91  mPoint0[maxAxis] -= mExtents[maxAxis];
92  mPoint1 = mCenter;
93  mPoint1[maxAxis] += mExtents[maxAxis];
94  Point p = mExtents;
95  p[maxAxis] = 0;
96  mRadius = p.Magnitude();
97  }else{
98  mType = SSV_PSS;
99  mRadius = mExtents.Magnitude();
100  }
101  }
102 #endif
103  };
104 
106  {
107  public:
112 
113  sword mCenter[3];
114  uword mExtents[3];
115  };
116 
118  inline_ void TransformPoint(Point& dest, const Point& source, const Matrix3x3& rot, const Point& trans)
119  {
120  dest.x = trans.x + source.x * rot.m[0][0] + source.y * rot.m[1][0] + source.z * rot.m[2][0];
121  dest.y = trans.y + source.x * rot.m[0][1] + source.y * rot.m[1][1] + source.z * rot.m[2][1];
122  dest.z = trans.z + source.x * rot.m[0][2] + source.y * rot.m[1][2] + source.z * rot.m[2][2];
123  }
124 
125 #endif //__OPC_COMMON_H__
PointComponent
Definition: IceAxes.h:15
inline_ QuantizedAABB()
Constructor.
Definition: OPC_Common.h:109
Point mPoint1
End points of line segment.
Definition: OPC_Common.h:83
#define FALSE
Definition: OPC_IceHook.h:9
unsigned short uword
sizeof(uword) must be 2
Definition: IceTypes.h:63
inline_ void GetExtents(Point &extents) const
Get box extents.
Definition: IceAABB.h:355
float m[3][3]
Definition: IceMatrix3x3.h:492
static int min(int a, int b)
#define TRUE
Definition: OPC_IceHook.h:13
#define inline_
inline_ CollisionAABB(const AABB &b)
Constructor.
Definition: OPC_Common.h:36
float z
Definition: IcePoint.h:524
Definition: IcePoint.h:25
inline_ float GetMin(udword axis) const
Get component of the box&#39;s min point along a given axis.
Definition: OPC_Common.h:46
long b
Definition: jpegint.h:371
Point mExtents
Box extents.
Definition: OPC_Common.h:78
inline_ void GetMax(Point &max) const
Get max point of the box.
Definition: OPC_Common.h:43
#define OPCODE_API
Definition: Opcode.h:68
png_infop png_bytep * trans
Definition: png.h:2435
int BOOL
Another boolean type.
Definition: IceTypes.h:102
float x
Definition: IcePoint.h:524
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
float mRadius
Definition: OPC_Common.h:82
inline_ ~QuantizedAABB()
Destructor.
Definition: OPC_Common.h:111
inline_ float Magnitude() const
Computes magnitude.
Definition: IcePoint.h:219
Point mCenter
Box center.
Definition: OPC_Common.h:77
Definition: IceAABB.h:267
void CreateSSV()
Definition: OPC_Common.h:84
inline_ PointComponent LargestAxis() const
Returns largest axis.
Definition: IcePoint.h:341
inline_ float GetMax(udword axis) const
Get component of the box&#39;s max point along a given axis.
Definition: OPC_Common.h:48
inline_ CollisionAABB()
Constructor.
Definition: OPC_Common.h:34
inline_ PointComponent SmallestAxis() const
Returns smallest axis.
Definition: IcePoint.h:362
float y
Definition: IcePoint.h:524
ssv_type mType
Type of SSV.
Definition: OPC_Common.h:81
inline_ void TransformPoint(Point &dest, const Point &source, const Matrix3x3 &rot, const Point &trans)
Quickly rotates & translates a vector.
Definition: OPC_Common.h:118
signed short sword
sizeof(sword) must be 2
Definition: IceTypes.h:62
inline_ void GetCenter(Point &center) const
Get box center.
Definition: IceAABB.h:353
inline_ void GetMin(Point &min) const
Get min point of the box.
Definition: OPC_Common.h:41
static int max(int a, int b)
inline_ ~CollisionAABB()
Destructor.
Definition: OPC_Common.h:38
Definition: jquant2.c:258


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:04