AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
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)
 

Detailed Description

Member Function Documentation

◆ collisionLocationForMovingPointFixedAABox()

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

References IR.