TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
VMAP::MyCollisionDetection Class Reference

#include <VMapTools.h>

Static Public Member Functions

static bool collisionLocationForMovingPointFixedAABox (const G3D::Vector3 &origin, const G3D::Vector3 &dir, const G3D::AABox &box, G3D::Vector3 &location, bool &Inside)
 

Member Function Documentation

static bool VMAP::MyCollisionDetection::collisionLocationForMovingPointFixedAABox ( const G3D::Vector3 origin,
const G3D::Vector3 dir,
const G3D::AABox box,
G3D::Vector3 location,
bool Inside 
)
inlinestatic
64  {
65 
66  // Integer representation of a floating-point value.
67 #define IR(x) (reinterpret_cast<G3D::uint32 const&>(x))
68 
69  Inside = true;
70  const G3D::Vector3& MinB = box.low();
71  const G3D::Vector3& MaxB = box.high();
72  G3D::Vector3 MaxT(-1.0f, -1.0f, -1.0f);
73 
74  // Find candidate planes.
75  for (int i = 0; i < 3; ++i)
76  {
77  if (origin[i] < MinB[i])
78  {
79  location[i] = MinB[i];
80  Inside = false;
81 
82  // Calculate T distances to candidate planes
83  if (IR(dir[i]))
84  {
85  MaxT[i] = (MinB[i] - origin[i]) / dir[i];
86  }
87  }
88  else if (origin[i] > MaxB[i])
89  {
90  location[i] = MaxB[i];
91  Inside = false;
92 
93  // Calculate T distances to candidate planes
94  if (IR(dir[i]))
95  {
96  MaxT[i] = (MaxB[i] - origin[i]) / dir[i];
97  }
98  }
99  }
100 
101  if (Inside)
102  {
103  // definite hit
104  location = origin;
105  return true;
106  }
107 
108  // Get largest of the maxT's for final choice of intersection
109  int WhichPlane = 0;
110  if (MaxT[1] > MaxT[WhichPlane])
111  {
112  WhichPlane = 1;
113  }
114 
115  if (MaxT[2] > MaxT[WhichPlane])
116  {
117  WhichPlane = 2;
118  }
119 
120  // Check final candidate actually inside box
121  if (IR(MaxT[WhichPlane]) & 0x80000000)
122  {
123  // Miss the box
124  return false;
125  }
126 
127  for (int i = 0; i < 3; ++i)
128  {
129  if (i != WhichPlane)
130  {
131  location[i] = origin[i] + MaxT[WhichPlane] * dir[i];
132  if ((location[i] < MinB[i]) ||
133  (location[i] > MaxB[i]))
134  {
135  // On this plane we're outside the box extents, so
136  // we miss the box
137  return false;
138  }
139  }
140  }
141  /*
142  // Choose the normal to be the plane normal facing into the ray
143  normal = G3D::Vector3::zero();
144  normal[WhichPlane] = (dir[WhichPlane] > 0) ? -1.0 : 1.0;
145  */
146  return true;
147 
148 #undef IR
149  }
const Point3 & low() const
Definition: AABox.h:136
#define IR(x)
Definition: Vector3.h:58
const Point3 & high() const
Definition: AABox.h:141

+ Here is the call graph for this function:


The documentation for this class was generated from the following file: