OPC_Common.h
Go to the documentation of this file.
00001 
00002 /*
00003  *      OPCODE - Optimized Collision Detection
00004  *      Copyright (C) 2001 Pierre Terdiman
00005  *      Homepage: http://www.codercorner.com/Opcode.htm
00006  */
00008 
00010 
00016 
00017 
00019 // Include Guard
00020 #ifndef __OPC_COMMON_H__
00021 #define __OPC_COMMON_H__
00022 
00023 // [GOTTFRIED]: Just a small change for readability.
00024 #ifdef OPC_CPU_COMPARE
00025         #define GREATER(x, y)   AIR(x) > IR(y)
00026 #else
00027         #define GREATER(x, y)   fabsf(x) > (y)
00028 #endif
00029 
00030         class OPCODE_API CollisionAABB
00031         {
00032                 public:
00034                 inline_                         CollisionAABB()                                         {}
00036                 inline_                         CollisionAABB(const AABB& b)            { b.GetCenter(mCenter); b.GetExtents(mExtents); }
00038                 inline_                         ~CollisionAABB()                                        {}
00039 
00041                 inline_ void            GetMin(Point& min)              const           { min = mCenter - mExtents;                                     }
00043                 inline_ void            GetMax(Point& max)              const           { max = mCenter + mExtents;                                     }
00044 
00046                 inline_ float           GetMin(udword axis)             const           { return mCenter[axis] - mExtents[axis];        }
00048                 inline_ float           GetMax(udword axis)             const           { return mCenter[axis] + mExtents[axis];        }
00049 
00051 
00056 
00057                 inline_ void            SetMinMax(const Point& min, const Point& max)           { mCenter = (max + min)*0.5f; mExtents = (max - min)*0.5f; }
00058 
00060 
00065 
00066                 inline_ BOOL            IsInside(const CollisionAABB& box) const
00067                                                         {
00068                                                                 if(box.GetMin(0)>GetMin(0))     return FALSE;
00069                                                                 if(box.GetMin(1)>GetMin(1))     return FALSE;
00070                                                                 if(box.GetMin(2)>GetMin(2))     return FALSE;
00071                                                                 if(box.GetMax(0)<GetMax(0))     return FALSE;
00072                                                                 if(box.GetMax(1)<GetMax(1))     return FALSE;
00073                                                                 if(box.GetMax(2)<GetMax(2))     return FALSE;
00074                                                                 return TRUE;
00075                                                         }
00076 
00077                                 Point           mCenter;                                
00078                                 Point           mExtents;                               
00079 #if 1 // Added by AIST
00080                                 typedef enum {SSV_PSS, SSV_LSS} ssv_type;
00081                                 ssv_type        mType; 
00082                                 float           mRadius;
00083                                 Point           mPoint0, mPoint1; 
00084                                 void CreateSSV(){
00085                                     PointComponent maxAxis, minAxis;
00086                                     maxAxis = mExtents.LargestAxis();
00087                                     minAxis = mExtents.SmallestAxis();
00088                                     if (mExtents[minAxis] > 0 && mExtents[maxAxis]/mExtents[minAxis] > 2){
00089                                         mType = SSV_LSS;
00090                                         mPoint0 = mCenter;
00091                                         mPoint0[maxAxis] -= mExtents[maxAxis];
00092                                         mPoint1 = mCenter;
00093                                         mPoint1[maxAxis] += mExtents[maxAxis];
00094                                         Point p = mExtents;
00095                                         p[maxAxis] = 0;
00096                                         mRadius = p.Magnitude();
00097                                     }else{
00098                                         mType = SSV_PSS;
00099                                         mRadius = mExtents.Magnitude();
00100                                     }
00101                                 }
00102 #endif
00103         };
00104 
00105         class OPCODE_API QuantizedAABB
00106         {
00107                 public:
00109                 inline_                         QuantizedAABB()                 {}
00111                 inline_                         ~QuantizedAABB()                {}
00112 
00113                                 sword           mCenter[3];                             
00114                                 uword           mExtents[3];                    
00115         };
00116 
00118         inline_ void TransformPoint(Point& dest, const Point& source, const Matrix3x3& rot, const Point& trans)
00119         {
00120                 dest.x = trans.x + source.x * rot.m[0][0] + source.y * rot.m[1][0] + source.z * rot.m[2][0];
00121                 dest.y = trans.y + source.x * rot.m[0][1] + source.y * rot.m[1][1] + source.z * rot.m[2][1];
00122                 dest.z = trans.z + source.x * rot.m[0][2] + source.y * rot.m[1][2] + source.z * rot.m[2][2];
00123         }
00124 
00125 #endif //__OPC_COMMON_H__


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:55