Daniele Bartolini 11 лет назад
Родитель
Сommit
967d5c802f
4 измененных файлов с 343 добавлено и 176 удалено
  1. 9 8
      engine/core/math/frustum.h
  2. 285 0
      engine/core/math/intersection.cpp
  3. 18 152
      engine/core/math/intersection.h
  4. 31 16
      engine/lua/lua_math.cpp

+ 9 - 8
engine/core/math/frustum.h

@@ -30,6 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "math_types.h"
 #include "vector3.h"
 #include "plane.h"
+#include "aabb.h"
 #include "intersection.h"
 
 namespace crown
@@ -95,14 +96,14 @@ namespace frustum
 
 		switch (index)
 		{
-			case 0: return plane_3_intersection(side[4], side[0], side[2], ip);
-			case 1: return plane_3_intersection(side[4], side[1], side[2], ip);
-			case 2: return plane_3_intersection(side[4], side[1], side[3], ip);
-			case 3: return plane_3_intersection(side[4], side[0], side[3], ip);
-			case 4: return plane_3_intersection(side[5], side[0], side[2], ip);
-			case 5: return plane_3_intersection(side[5], side[1], side[2], ip);
-			case 6: return plane_3_intersection(side[5], side[1], side[3], ip);
-			case 7: return plane_3_intersection(side[5], side[0], side[3], ip);
+			case 0: return math::plane_3_intersection(side[4], side[0], side[2], ip);
+			case 1: return math::plane_3_intersection(side[4], side[1], side[2], ip);
+			case 2: return math::plane_3_intersection(side[4], side[1], side[3], ip);
+			case 3: return math::plane_3_intersection(side[4], side[0], side[3], ip);
+			case 4: return math::plane_3_intersection(side[5], side[0], side[2], ip);
+			case 5: return math::plane_3_intersection(side[5], side[1], side[2], ip);
+			case 6: return math::plane_3_intersection(side[5], side[1], side[3], ip);
+			case 7: return math::plane_3_intersection(side[5], side[0], side[3], ip);
 			default: break;
 		}
 

+ 285 - 0
engine/core/math/intersection.cpp

@@ -0,0 +1,285 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "intersection.h"
+#include "aabb.h"
+#include "plane.h"
+#include "sphere.h"
+#include "vector3.h"
+
+namespace crown
+{
+namespace math
+{
+	/// Returns the distance along ray (from, dir) to intersection point with plane @a p.
+	/// -1.0f if no collision.
+	float ray_plane_intersection(const Vector3& from, const Vector3& dir, const Plane& p)
+	{
+		float nd = vector3::dot(dir, p.n);
+		float orpn = vector3::dot(from, p.n);
+		float dist = -1.0f;
+
+		if (nd < 0.0f)
+			dist = (-p.d - orpn) / nd;
+
+		return dist > 0.0f ? dist : -1.0f;
+	}
+
+	/// Returns the distance along ray (from, dir) to intersection point with sphere @a s.
+	/// -1.0f if no collision.
+	float ray_sphere_intersection(const Vector3& from, const Vector3& dir, const Sphere& s)
+	{
+		Vector3 v = s.center() - from;
+		float b = vector3::dot(v, dir);
+		float det = (s.radius() * s.radius()) - vector3::dot(v, v) + (b * b);
+
+		if (det < 0.0 || b < s.radius())
+		{
+			return -1.0f;
+		}
+
+		return b - math::sqrt(det);
+	}
+
+	// http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/picking-with-custom-ray-obb-function/
+	float ray_oobb_intersection(const Vector3& from, const Vector3& dir, const OBB& obb)
+	{
+		using namespace vector3;
+		
+		float tmin = 0.0f;
+		float tmax = 100000.0f;
+
+		Vector3 obb_pos(obb.tm.t.x, obb.tm.t.y, obb.tm.t.z);
+		Vector3 delta = obb_pos - from;
+
+		{
+			const Vector3 xaxis(obb.tm.x.x, obb.tm.x.y, obb.tm.x.z);
+			float e = dot(xaxis, delta);
+			float f = dot(dir, xaxis);
+
+			if (fabs(f) > 0.001f)
+			{
+				float t1 = (e+obb.aabb.min.x)/f;
+				float t2 = (e+obb.aabb.max.x)/f;
+
+				if (t1>t2){
+					float w=t1;t1=t2;t2=w;
+				}
+
+				if (t2 < tmax)
+					tmax = t2;
+				if (t1 > tmin)
+					tmin = t1;
+
+				if (tmax < tmin)
+					return -1.0f;
+
+			}
+			else
+			{
+				if(-e+obb.aabb.min.x > 0.0f || -e+obb.aabb.max.x < 0.0f)
+					return -1.0f;
+			}
+		}
+
+		{
+			const Vector3 yaxis(obb.tm.y.x, obb.tm.y.y, obb.tm.y.z);
+			float e = dot(yaxis, delta);
+			float f = dot(dir, yaxis);
+
+			if (fabs(f) > 0.001f){
+
+				float t1 = (e+obb.aabb.min.y)/f;
+				float t2 = (e+obb.aabb.max.y)/f;
+
+				if (t1>t2){float w=t1;t1=t2;t2=w;}
+
+				if (t2 < tmax)
+					tmax = t2;
+				if (t1 > tmin)
+					tmin = t1;
+
+				if (tmin > tmax)
+					return -1.0f;
+			}
+			else
+			{
+				if(-e+obb.aabb.min.y > 0.0f || -e+obb.aabb.max.y < 0.0f)
+					return -1.0f;
+			}
+		}
+
+		{
+			const Vector3 zaxis(obb.tm.z.x, obb.tm.z.y, obb.tm.z.z);
+			float e = dot(zaxis, delta);
+			float f = dot(dir, zaxis);
+
+			if (fabs(f) > 0.001f){
+
+				float t1 = (e+obb.aabb.min.z)/f;
+				float t2 = (e+obb.aabb.max.z)/f;
+
+				if (t1>t2){float w=t1;t1=t2;t2=w;}
+
+				if (t2 < tmax)
+					tmax = t2;
+				if (t1 > tmin)
+					tmin = t1;
+
+				if (tmin > tmax)
+					return -1.0f;
+
+			}
+			else
+			{
+				if(-e+obb.aabb.min.z > 0.0f || -e+obb.aabb.max.z < 0.0f)
+					return -1.0f;
+			}
+		}
+
+		return tmin;
+	}
+
+	bool plane_3_intersection(const Plane& p1, const Plane& p2, const Plane& p3, Vector3& ip)
+	{
+		const Vector3& n1 = p1.n;
+		const Vector3& n2 = p2.n;
+		const Vector3& n3 = p3.n;
+
+		float den = -vector3::dot(vector3::cross(n1, n2), n3);
+
+		if (math::equals(den, (float)0.0))
+		{
+			return false;
+		}
+
+		Vector3 res = p1.d * vector3::cross(n2, n3) + p2.d * vector3::cross(n3, n1) + p3.d * vector3::cross(n1, n2);
+		ip = res / den;
+
+		return true;
+	}
+
+	bool frustum_sphere_intersection(const Frustum& f, const Sphere& s)
+	{
+		if (plane::distance_to_point(f.left, s.center()) < -s.radius() ||
+			plane::distance_to_point(f.right, s.center()) < -s.radius())
+		{
+			return false;
+		}
+
+		if (plane::distance_to_point(f.bottom, s.center()) < -s.radius() ||
+			plane::distance_to_point(f.top, s.center()) < -s.radius())
+		{
+			return false;
+		}
+
+		if (plane::distance_to_point(f.near, s.center()) < -s.radius() ||
+			plane::distance_to_point(f.far, s.center()) < -s.radius())
+		{
+			return false;
+		}
+
+		return true;
+	}
+
+	bool frustum_box_intersection(const Frustum& f, const AABB& b)
+	{
+		uint8_t out;
+
+		out = 0;
+		if (plane::distance_to_point(f.left, aabb::vertex(b, 0)) < 0.0) out++;
+		if (plane::distance_to_point(f.left, aabb::vertex(b, 1)) < 0.0) out++;
+		if (plane::distance_to_point(f.left, aabb::vertex(b, 2)) < 0.0) out++;
+		if (plane::distance_to_point(f.left, aabb::vertex(b, 3)) < 0.0) out++;
+		if (plane::distance_to_point(f.left, aabb::vertex(b, 4)) < 0.0) out++;
+		if (plane::distance_to_point(f.left, aabb::vertex(b, 5)) < 0.0) out++;
+		if (plane::distance_to_point(f.left, aabb::vertex(b, 6)) < 0.0) out++;
+		if (plane::distance_to_point(f.left, aabb::vertex(b, 7)) < 0.0) out++;
+
+		// If all vertices are outside one face, then the box doesn't intersect the frustum
+		if (out == 8) return false;
+
+		out = 0;
+		if (plane::distance_to_point(f.right, aabb::vertex(b, 0)) < 0.0) out++;
+		if (plane::distance_to_point(f.right, aabb::vertex(b, 1)) < 0.0) out++;
+		if (plane::distance_to_point(f.right, aabb::vertex(b, 2)) < 0.0) out++;
+		if (plane::distance_to_point(f.right, aabb::vertex(b, 3)) < 0.0) out++;
+		if (plane::distance_to_point(f.right, aabb::vertex(b, 4)) < 0.0) out++;
+		if (plane::distance_to_point(f.right, aabb::vertex(b, 5)) < 0.0) out++;
+		if (plane::distance_to_point(f.right, aabb::vertex(b, 6)) < 0.0) out++;
+		if (plane::distance_to_point(f.right, aabb::vertex(b, 7)) < 0.0) out++;
+		if (out == 8) return false;
+
+		out = 0;
+		if (plane::distance_to_point(f.bottom, aabb::vertex(b, 0)) < 0.0) out++;
+		if (plane::distance_to_point(f.bottom, aabb::vertex(b, 1)) < 0.0) out++;
+		if (plane::distance_to_point(f.bottom, aabb::vertex(b, 2)) < 0.0) out++;
+		if (plane::distance_to_point(f.bottom, aabb::vertex(b, 3)) < 0.0) out++;
+		if (plane::distance_to_point(f.bottom, aabb::vertex(b, 4)) < 0.0) out++;
+		if (plane::distance_to_point(f.bottom, aabb::vertex(b, 5)) < 0.0) out++;
+		if (plane::distance_to_point(f.bottom, aabb::vertex(b, 6)) < 0.0) out++;
+		if (plane::distance_to_point(f.bottom, aabb::vertex(b, 7)) < 0.0) out++;
+		if (out == 8) return false;
+
+		out = 0;
+		if (plane::distance_to_point(f.top, aabb::vertex(b, 0)) < 0.0) out++;
+		if (plane::distance_to_point(f.top, aabb::vertex(b, 1)) < 0.0) out++;
+		if (plane::distance_to_point(f.top, aabb::vertex(b, 2)) < 0.0) out++;
+		if (plane::distance_to_point(f.top, aabb::vertex(b, 3)) < 0.0) out++;
+		if (plane::distance_to_point(f.top, aabb::vertex(b, 4)) < 0.0) out++;
+		if (plane::distance_to_point(f.top, aabb::vertex(b, 5)) < 0.0) out++;
+		if (plane::distance_to_point(f.top, aabb::vertex(b, 6)) < 0.0) out++;
+		if (plane::distance_to_point(f.top, aabb::vertex(b, 7)) < 0.0) out++;
+		if (out == 8) return false;
+
+		out = 0;
+		if (plane::distance_to_point(f.near, aabb::vertex(b, 0)) < 0.0) out++;
+		if (plane::distance_to_point(f.near, aabb::vertex(b, 1)) < 0.0) out++;
+		if (plane::distance_to_point(f.near, aabb::vertex(b, 2)) < 0.0) out++;
+		if (plane::distance_to_point(f.near, aabb::vertex(b, 3)) < 0.0) out++;
+		if (plane::distance_to_point(f.near, aabb::vertex(b, 4)) < 0.0) out++;
+		if (plane::distance_to_point(f.near, aabb::vertex(b, 5)) < 0.0) out++;
+		if (plane::distance_to_point(f.near, aabb::vertex(b, 6)) < 0.0) out++;
+		if (plane::distance_to_point(f.near, aabb::vertex(b, 7)) < 0.0) out++;
+		if (out == 8) return false;
+
+		out = 0;
+		if (plane::distance_to_point(f.far, aabb::vertex(b, 0)) < 0.0) out++;
+		if (plane::distance_to_point(f.far, aabb::vertex(b, 1)) < 0.0) out++;
+		if (plane::distance_to_point(f.far, aabb::vertex(b, 2)) < 0.0) out++;
+		if (plane::distance_to_point(f.far, aabb::vertex(b, 3)) < 0.0) out++;
+		if (plane::distance_to_point(f.far, aabb::vertex(b, 4)) < 0.0) out++;
+		if (plane::distance_to_point(f.far, aabb::vertex(b, 5)) < 0.0) out++;
+		if (plane::distance_to_point(f.far, aabb::vertex(b, 6)) < 0.0) out++;
+		if (plane::distance_to_point(f.far, aabb::vertex(b, 7)) < 0.0) out++;
+		if (out == 8) return false;
+
+		// If we are here, it is because either the box intersects or it is contained in the frustum
+		return true;
+	}
+
+} // namespace math
+} // namespace crown

+ 18 - 152
engine/core/math/intersection.h

@@ -26,161 +26,27 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "plane.h"
+#include "math_types.h"
 #include "sphere.h"
-#include "frustum.h"
-#include "math_utils.h"
-#include "types.h"
-#include "aabb.h"
 
 namespace crown
 {
-
-/// Returns the distance along ray (from, dir) to intersection point with plane @a p.
-/// -1.0f if no collision.
-inline float ray_plane_intersection(const Vector3& from, const Vector3& dir, const Plane& p)
-{
-	float nd = vector3::dot(dir, p.n);
-	float orpn = vector3::dot(from, p.n);
-	float dist = -1.0f;
-
-	if (nd < 0.0f)
-		dist = (-p.d - orpn) / nd;
-
-	return dist > 0.0f ? dist : -1.0f;
-}
-
-/// Returns the distance along ray (from, dir) to intersection point with sphere @a s.
-/// -1.0f if no collision.
-inline float ray_sphere_intersection(const Vector3& from, const Vector3& dir, const Sphere& s)
-{
-	Vector3 v = s.center() - from;
-	float b = vector3::dot(v, dir);
-	float det = (s.radius() * s.radius()) - vector3::dot(v, v) + (b * b);
-
-	if (det < 0.0 || b < s.radius())
-	{
-		return -1.0f;
-	}
-
-	return b - math::sqrt(det);
-}
-
-inline bool plane_3_intersection(const Plane& p1, const Plane& p2, const Plane& p3, Vector3& ip)
-{
-	const Vector3& n1 = p1.n;
-	const Vector3& n2 = p2.n;
-	const Vector3& n3 = p3.n;
-
-	float den = -vector3::dot(vector3::cross(n1, n2), n3);
-
-	if (math::equals(den, (float)0.0))
-	{
-		return false;
-	}
-
-	Vector3 res = p1.d * vector3::cross(n2, n3) + p2.d * vector3::cross(n3, n1) + p3.d * vector3::cross(n1, n2);
-	ip = res / den;
-
-	return true;
-}
-
-inline bool frustum_sphere_intersection(const Frustum& f, const Sphere& s)
+namespace math
 {
-	if (plane::distance_to_point(f.left, s.center()) < -s.radius() ||
-		plane::distance_to_point(f.right, s.center()) < -s.radius())
-	{
-		return false;
-	}
-
-	if (plane::distance_to_point(f.bottom, s.center()) < -s.radius() ||
-		plane::distance_to_point(f.top, s.center()) < -s.radius())
-	{
-		return false;
-	}
-
-	if (plane::distance_to_point(f.near, s.center()) < -s.radius() ||
-		plane::distance_to_point(f.far, s.center()) < -s.radius())
-	{
-		return false;
-	}
-
-	return true;
-}
-
-inline bool frustum_box_intersection(const Frustum& f, const AABB& b)
-{
-	uint8_t out;
-
-	out = 0;
-	if (plane::distance_to_point(f.left, aabb::vertex(b, 0)) < 0.0) out++;
-	if (plane::distance_to_point(f.left, aabb::vertex(b, 1)) < 0.0) out++;
-	if (plane::distance_to_point(f.left, aabb::vertex(b, 2)) < 0.0) out++;
-	if (plane::distance_to_point(f.left, aabb::vertex(b, 3)) < 0.0) out++;
-	if (plane::distance_to_point(f.left, aabb::vertex(b, 4)) < 0.0) out++;
-	if (plane::distance_to_point(f.left, aabb::vertex(b, 5)) < 0.0) out++;
-	if (plane::distance_to_point(f.left, aabb::vertex(b, 6)) < 0.0) out++;
-	if (plane::distance_to_point(f.left, aabb::vertex(b, 7)) < 0.0) out++;
-
-	// If all vertices are outside one face, then the box doesn't intersect the frustum
-	if (out == 8) return false;
-
-	out = 0;
-	if (plane::distance_to_point(f.right, aabb::vertex(b, 0)) < 0.0) out++;
-	if (plane::distance_to_point(f.right, aabb::vertex(b, 1)) < 0.0) out++;
-	if (plane::distance_to_point(f.right, aabb::vertex(b, 2)) < 0.0) out++;
-	if (plane::distance_to_point(f.right, aabb::vertex(b, 3)) < 0.0) out++;
-	if (plane::distance_to_point(f.right, aabb::vertex(b, 4)) < 0.0) out++;
-	if (plane::distance_to_point(f.right, aabb::vertex(b, 5)) < 0.0) out++;
-	if (plane::distance_to_point(f.right, aabb::vertex(b, 6)) < 0.0) out++;
-	if (plane::distance_to_point(f.right, aabb::vertex(b, 7)) < 0.0) out++;
-	if (out == 8) return false;
-
-	out = 0;
-	if (plane::distance_to_point(f.bottom, aabb::vertex(b, 0)) < 0.0) out++;
-	if (plane::distance_to_point(f.bottom, aabb::vertex(b, 1)) < 0.0) out++;
-	if (plane::distance_to_point(f.bottom, aabb::vertex(b, 2)) < 0.0) out++;
-	if (plane::distance_to_point(f.bottom, aabb::vertex(b, 3)) < 0.0) out++;
-	if (plane::distance_to_point(f.bottom, aabb::vertex(b, 4)) < 0.0) out++;
-	if (plane::distance_to_point(f.bottom, aabb::vertex(b, 5)) < 0.0) out++;
-	if (plane::distance_to_point(f.bottom, aabb::vertex(b, 6)) < 0.0) out++;
-	if (plane::distance_to_point(f.bottom, aabb::vertex(b, 7)) < 0.0) out++;
-	if (out == 8) return false;
-
-	out = 0;
-	if (plane::distance_to_point(f.top, aabb::vertex(b, 0)) < 0.0) out++;
-	if (plane::distance_to_point(f.top, aabb::vertex(b, 1)) < 0.0) out++;
-	if (plane::distance_to_point(f.top, aabb::vertex(b, 2)) < 0.0) out++;
-	if (plane::distance_to_point(f.top, aabb::vertex(b, 3)) < 0.0) out++;
-	if (plane::distance_to_point(f.top, aabb::vertex(b, 4)) < 0.0) out++;
-	if (plane::distance_to_point(f.top, aabb::vertex(b, 5)) < 0.0) out++;
-	if (plane::distance_to_point(f.top, aabb::vertex(b, 6)) < 0.0) out++;
-	if (plane::distance_to_point(f.top, aabb::vertex(b, 7)) < 0.0) out++;
-	if (out == 8) return false;
-
-	out = 0;
-	if (plane::distance_to_point(f.near, aabb::vertex(b, 0)) < 0.0) out++;
-	if (plane::distance_to_point(f.near, aabb::vertex(b, 1)) < 0.0) out++;
-	if (plane::distance_to_point(f.near, aabb::vertex(b, 2)) < 0.0) out++;
-	if (plane::distance_to_point(f.near, aabb::vertex(b, 3)) < 0.0) out++;
-	if (plane::distance_to_point(f.near, aabb::vertex(b, 4)) < 0.0) out++;
-	if (plane::distance_to_point(f.near, aabb::vertex(b, 5)) < 0.0) out++;
-	if (plane::distance_to_point(f.near, aabb::vertex(b, 6)) < 0.0) out++;
-	if (plane::distance_to_point(f.near, aabb::vertex(b, 7)) < 0.0) out++;
-	if (out == 8) return false;
-
-	out = 0;
-	if (plane::distance_to_point(f.far, aabb::vertex(b, 0)) < 0.0) out++;
-	if (plane::distance_to_point(f.far, aabb::vertex(b, 1)) < 0.0) out++;
-	if (plane::distance_to_point(f.far, aabb::vertex(b, 2)) < 0.0) out++;
-	if (plane::distance_to_point(f.far, aabb::vertex(b, 3)) < 0.0) out++;
-	if (plane::distance_to_point(f.far, aabb::vertex(b, 4)) < 0.0) out++;
-	if (plane::distance_to_point(f.far, aabb::vertex(b, 5)) < 0.0) out++;
-	if (plane::distance_to_point(f.far, aabb::vertex(b, 6)) < 0.0) out++;
-	if (plane::distance_to_point(f.far, aabb::vertex(b, 7)) < 0.0) out++;
-	if (out == 8) return false;
-
-	// If we are here, it is because either the box intersects or it is contained in the frustum
-	return true;
-}
+	/// Returns the distance along ray (from, dir) to intersection point with plane @a p
+	/// or -1.0 if no intersection.
+	float ray_plane_intersection(const Vector3& from, const Vector3& dir, const Plane& p);
+
+	/// Returns the distance along ray (from, dir) to intersection point with sphere @a s
+	/// or -1.0 if no intersection.
+	float ray_sphere_intersection(const Vector3& from, const Vector3& dir, const Sphere& s);
+
+	/// Returns the distance along ray (from, dir) to intersection point with @a obb
+	/// or -1.0 if no intersection.
+	float ray_oobb_intersection(const Vector3& from, const Vector3& dir, const OBB& obb);
+
+	bool plane_3_intersection(const Plane& p1, const Plane& p2, const Plane& p3, Vector3& ip);
+	bool frustum_sphere_intersection(const Frustum& f, const Sphere& s);
+	bool frustum_box_intersection(const Frustum& f, const AABB& b);
+} // namespace math
 } // namespace crown

+ 31 - 16
engine/lua/lua_math.cpp

@@ -25,6 +25,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "math_utils.h"
+#include "math_types.h"
+#include "aabb.h"
+#include "intersection.h"
 #include "lua_stack.h"
 #include "lua_environment.h"
 
@@ -143,24 +146,36 @@ static int math_fmod(lua_State* L)
 	return 1;
 }
 
+static int math_ray_oobb_intersection(lua_State* L)
+{
+	LuaStack stack(L);
+	OBB oobb;
+	oobb.tm = stack.get_matrix4x4(3);
+	oobb.aabb.min = stack.get_vector3(4) * -0.5;
+	oobb.aabb.max = stack.get_vector3(4) * 0.5;
+	stack.push_float(math::ray_oobb_intersection(stack.get_vector3(1), stack.get_vector3(2), oobb));
+	return 1;
+}
+
 void load_math(LuaEnvironment& env)
 {
-	env.load_module_function("Math", "to_rad",     math_to_rad);
-	env.load_module_function("Math", "to_deg",     math_to_deg);
-	env.load_module_function("Math", "next_pow_2", math_next_pow_2);
-	env.load_module_function("Math", "is_pow_2",   math_is_pow_2);
-	env.load_module_function("Math", "ceil",       math_ceil);
-	env.load_module_function("Math", "floor",      math_floor);
-	env.load_module_function("Math", "sqrt",       math_sqrt);
-	env.load_module_function("Math", "inv_sqrt",   math_inv_sqrt);
-	env.load_module_function("Math", "sin",        math_sin);
-	env.load_module_function("Math", "cos",        math_cos);
-	env.load_module_function("Math", "asin",       math_asin);
-	env.load_module_function("Math", "acos",       math_acos);
-	env.load_module_function("Math", "tan",        math_tan);
-	env.load_module_function("Math", "atan2",      math_atan2);
-	env.load_module_function("Math", "abs",        math_abs);
-	env.load_module_function("Math", "fmod",       math_fmod);
+	env.load_module_function("Math", "to_rad",                math_to_rad);
+	env.load_module_function("Math", "to_deg",                math_to_deg);
+	env.load_module_function("Math", "next_pow_2",            math_next_pow_2);
+	env.load_module_function("Math", "is_pow_2",              math_is_pow_2);
+	env.load_module_function("Math", "ceil",                  math_ceil);
+	env.load_module_function("Math", "floor",                 math_floor);
+	env.load_module_function("Math", "sqrt",                  math_sqrt);
+	env.load_module_function("Math", "inv_sqrt",              math_inv_sqrt);
+	env.load_module_function("Math", "sin",                   math_sin);
+	env.load_module_function("Math", "cos",                   math_cos);
+	env.load_module_function("Math", "asin",                  math_asin);
+	env.load_module_function("Math", "acos",                  math_acos);
+	env.load_module_function("Math", "tan",                   math_tan);
+	env.load_module_function("Math", "atan2",                 math_atan2);
+	env.load_module_function("Math", "abs",                   math_abs);
+	env.load_module_function("Math", "fmod",                  math_fmod);
+	env.load_module_function("Math", "ray_oobb_intersection", math_ray_oobb_intersection);
 }
 
 } // namespace crown