Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  };
80 
82  {
83  public:
88 
89  sword mCenter[3];
90  uword mExtents[3];
91  };
92 
94  inline_ void TransformPoint(Point& dest, const Point& source, const Matrix3x3& rot, const Point& trans)
95  {
96  dest.x = trans.x + source.x * rot.m[0][0] + source.y * rot.m[1][0] + source.z * rot.m[2][0];
97  dest.y = trans.y + source.x * rot.m[0][1] + source.y * rot.m[1][1] + source.z * rot.m[2][1];
98  dest.z = trans.z + source.x * rot.m[0][2] + source.y * rot.m[1][2] + source.z * rot.m[2][2];
99  }
100 
101 #endif //__OPC_COMMON_H__