bool RayBoxIntersection(Vector3 BoxMin, Vector3 BoxMax, Vector3 Origin, Vector3 End, out Vector3 hit ){}
Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 21 July 2007 - 02:11 PM
bool RayBoxIntersection(Vector3 BoxMin, Vector3 BoxMax, Vector3 Origin, Vector3 End, out Vector3 hit ){}
Posted 21 July 2007 - 03:40 PM
template <class T> bool Math3D<T>::IntersectLineAABB(
const Vector3<T>& O,
const Vector3<T>& D,
const Vector3<T>& C,
const Vector3<T>& e,
T t[],
T epsilon)
{
int parallel = 0;
bool found = false;
Vector3<T> d = C - O;
for (int i = 0; i < 3; ++i)
{
if (Math<T>::Fabs(D[i]) < epsilon)
parallel |= 1 << i;
else
{
T es = (D[i] > (T)0.0) ? e[i] : -e[i];
T invDi = (T)1.0 / D[i];
if (!found)
{
t[0] = (d[i] - es) * invDi;
t[1] = (d[i] + es) * invDi;
found = true;
}
else
{
T s = (d[i] - es) * invDi;
if (s > t[0])
t[0] = s;
s = (d[i] + es) * invDi;
if (s < t[1])
t[1] = s;
if (t[0] > t[1])
return false;
}
}
}
if (parallel)
for (int i = 0; i < 3; ++i)
if (parallel & (1 << i))
if (Math<T>::Fabs(d[i] - t[0] * D[i]) > e[i] || Math<T>::Fabs(d[i] - t[1] * D[i]) > e[i])
return false;
return true;
}
Posted 21 July 2007 - 11:44 PM
Posted 22 July 2007 - 04:50 AM
Quote:It's a function template. If you're not familiar with templates (or don't need to parameterize the function) just replace the T's with 'float' (or whatever).
Original post by Agwan
Also what's with the T's...
Before clipping:Next we clip against the 'y axis' slab:
| | /
| |/
| |
| /|
-----/-----
|/ |
-----------
/| |
/ | |
/ | |
After clipping:
| |
| |
| *
| /|
-----/-----
|/ |
---*-------
| |
| |
| |
Before clipping:If the line hasn't been completely clipped away at this point, the endpoints of whatever remains (indicated by the *'s in this case) are the intersection points.
| |
| |
| *
| /|
-----/-----
|/ |
---*-------
| |
| |
| |
After clipping:
| |
| |
| |
| |
-----*-----
|/ |
---*-------
| |
| |
| |
Leaving us with:
--*--
|/ |
*----
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.