Explorar o código

Rename Box to AABB and port it to NMF

Daniele Bartolini %!s(int64=12) %!d(string=hai) anos
pai
achega
66945952f9

+ 2 - 2
engine/Crown.h

@@ -33,11 +33,12 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Log.h"
 
 // Core/Math
+#include "AABB.h"
 #include "Color4.h"
 #include "Intersection.h"
+#include "MathUtils.h"
 #include "Matrix3x3.h"
 #include "Matrix4x4.h"
-#include "MathUtils.h"
 #include "Plane.h"
 #include "Quaternion.h"
 #include "Random.h"
@@ -47,7 +48,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Vector4.h"
 
 // Core/Bv
-#include "Box.h"
 #include "Circle.h"
 #include "Frustum.h"
 #include "Rect.h"

+ 0 - 339
engine/core/bv/Box.h

@@ -1,339 +0,0 @@
-/*
-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.
-*/
-
-#pragma once
-
-#include "Assert.h"
-#include "Types.h"
-#include "Matrix4x4.h"
-#include "Vector3.h"
-#include "Sphere.h"
-
-namespace crown
-{
-
-/// Axially aligned bounding box.
-///
-/// Used mainly for collision detection and intersection tests.
-class Box
-{
-public:
-
-	/// Does nothing for efficiency.
-					Box();
-
-	/// Constructs from @a min and @a max.
-					Box(const Vector3& min, const Vector3& max);			
-					Box(const Box& box);
-
-	const Vector3&	min() const;
-	const Vector3&	max() const;
-	void			set_min(const Vector3& min);
-	void			set_max(const Vector3& max);
-
-	Vector3			center() const;
-	float			radius() const;
-	float			volume() const;
-
-	/// Adds @a count @a points expanding if necessary.
-	void			add_points(const Vector3* points, uint32_t count);
-
-	/// Adds @a count @a boxes expanding if necessay.
-	void			add_boxes(const Box* boxes, uint32_t count);
-
-	/// Returns whether point @a p is contained in the box.
-	bool			contains_point(const Vector3& p) const;
-
-	/// Returns the @a index -th vertex of the box.
-	Vector3			vertex(uint32_t index) const;		
-
-	/// Returns the box trasformed according to @a mat matrix into @a result.
-	void			transformed(const Matrix4x4& mat, Box& result) const;	
-
-	/// Returns the eight vertices of the box.
-	void			to_vertices(Vector3 v[8]) const;	
-
-	/// Returns as a sphere.						
-	Sphere			to_sphere() const;										
-
-	/// Sets min and max to zero.
-	void			zero();													
-
-private:
-
-	Vector3			m_min;
-	Vector3			m_max;
-};
-
-//-----------------------------------------------------------------------------
-inline Box::Box()
-{
-}
-
-//-----------------------------------------------------------------------------
-inline Box::Box(const Box& box) : m_min(box.m_min), m_max(box.m_max)
-{
-}
-
-//-----------------------------------------------------------------------------
-inline Box::Box(const Vector3& min, const Vector3& max) : m_min(min), m_max(max)
-{
-}
-
-//-----------------------------------------------------------------------------
-inline const Vector3& Box::min() const
-{
-	return m_min;
-}
-
-//-----------------------------------------------------------------------------
-inline void Box::set_min(const Vector3& min)
-{
-	m_min = min;
-}
-
-//-----------------------------------------------------------------------------
-inline const Vector3& Box::max() const
-{
-	return m_max;
-}
-
-//-----------------------------------------------------------------------------
-inline void Box::set_max(const Vector3& max)
-{
-	m_max = max;
-}
-
-//-----------------------------------------------------------------------------
-inline void Box::add_points(const Vector3* points, uint32_t count)
-{
-	for (uint32_t i = 0; i < count; i++)
-	{
-		const Vector3& p = points[i];
-
-		if (p.x < m_min.x)
-		{
-			m_min.x = p.x;
-		}
-
-		if (p.y < m_min.y)
-		{
-			m_min.y = p.y;
-		}
-
-		if (p.z < m_min.z)
-		{
-			m_min.z = p.z;
-		}
-
-		if (p.x > m_max.x)
-		{
-			m_max.x = p.x;
-		}
-
-		if (p.y > m_max.y)
-		{
-			m_max.y = p.y;
-		}
-
-		if (p.z > m_max.z)
-		{
-			m_max.z = p.z;
-		}
-	}
-}
-
-//-----------------------------------------------------------------------------
-inline void Box::add_boxes(const Box* boxes, uint32_t count)
-{
-	for (uint32_t i = 0; i < count; i++)
-	{
-		const Box& box = boxes[i];
-
-		if (box.m_min.x < m_min.x)
-		{
-			m_min.x = box.m_min.x;
-		}
-
-		if (box.m_min.y < m_min.y)
-		{
-			m_min.y = box.m_min.y;
-		}
-
-		if (box.m_min.z < m_min.z)
-		{
-			m_min.z = box.m_min.z;
-		}
-
-		if (box.m_max.x > m_max.x)
-		{
-			m_max.x = box.m_max.x;
-		}
-
-		if (box.m_max.y > m_max.y)
-		{
-			m_max.y = box.m_max.y;
-		}
-
-		if (box.m_max.z > m_max.z)
-		{
-			m_max.z = box.m_max.z;
-		}
-	}
-}
-
-//-----------------------------------------------------------------------------
-inline bool Box::contains_point(const Vector3& p) const
-{
-	return (p.x > m_min.x && p.y > m_min.y && p.z > m_min.z &&
-		p.x < m_max.x && p.y < m_max.y && p.z < m_max.z);
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3 Box::center() const
-{
-	return (m_min + m_max) * 0.5;
-}
-
-//-----------------------------------------------------------------------------
-inline float Box::radius() const
-{
-	return vector3::length(m_max - (m_min + m_max) * 0.5);
-}
-
-//-----------------------------------------------------------------------------
-inline void Box::to_vertices(Vector3 v[8]) const
-{
-	// 7 ---- 6
-	// |      |
-	// |      |  <--- Top face
-	// 4 ---- 5
-	//
-	// 3 ---- 2
-	// |      |
-	// |      |  <--- Bottom face
-	// 0 ---- 1
-	v[0].x = m_min.x;
-	v[0].y = m_min.y;
-	v[0].z = m_max.z;
-
-	v[1].x = m_max.x;
-	v[1].y = m_min.y;
-	v[1].z = m_max.z;
-
-	v[2].x = m_max.x;
-	v[2].y = m_min.y;
-	v[2].z = m_min.z;
-
-	v[3].x = m_min.x;
-	v[3].y = m_min.y;
-	v[3].z = m_min.z;
-
-	v[4].x = m_min.x;
-	v[4].y = m_max.y;
-	v[4].z = m_max.z;
-
-	v[5].x = m_max.x;
-	v[5].y = m_max.y;
-	v[5].z = m_max.z;
-
-	v[6].x = m_max.x;
-	v[6].y = m_max.y;
-	v[6].z = m_min.z;
-
-	v[7].x = m_min.x;
-	v[7].y = m_max.y;
-	v[7].z = m_min.z;
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3 Box::vertex(uint32_t index) const
-{
-	CE_ASSERT(index < 8, "Index must be < 8");
-
-	switch (index)
-	{
-		case 0:
-			return Vector3(m_min.x, m_min.y, m_min.z);
-		case 1:
-			return Vector3(m_max.x, m_min.y, m_min.z);
-		case 2:
-			return Vector3(m_max.x, m_min.y, m_max.z);
-		case 3:
-			return Vector3(m_min.x, m_min.y, m_max.z);
-		case 4:
-			return Vector3(m_min.x, m_max.y, m_min.z);
-		case 5:
-			return Vector3(m_max.x, m_max.y, m_min.z);
-		case 6:
-			return Vector3(m_max.x, m_max.y, m_max.z);
-		case 7:
-			return Vector3(m_min.x, m_max.y, m_max.z);
-	}
-}
-
-//-----------------------------------------------------------------------------
-inline void Box::transformed(const Matrix4x4& mat, Box& result) const
-{
-	Vector3 vertices[8];
-
-	to_vertices(vertices);
-
-	result.m_min = mat * vertices[0];
-	result.m_max = mat * vertices[0];
-
-	vertices[1] = mat * vertices[1];
-	vertices[2] = mat * vertices[2];
-	vertices[3] = mat * vertices[3];
-	vertices[4] = mat * vertices[4];
-	vertices[5] = mat * vertices[5];
-	vertices[6] = mat * vertices[6];
-	vertices[7] = mat * vertices[7];
-
-	result.add_points(&vertices[1], 7);
-}
-
-//-----------------------------------------------------------------------------
-inline float Box::volume() const
-{
-	return (m_max.x - m_min.x) * (m_max.y - m_min.y) * (m_max.z - m_min.z);
-}
-
-//-----------------------------------------------------------------------------
-inline void Box::zero()
-{
-	m_min = vector3::ZERO;
-	m_max = vector3::ZERO;
-}
-
-//-----------------------------------------------------------------------------
-inline Sphere Box::to_sphere() const
-{
-	return Sphere(center(), radius());
-}
-
-} // namespace crown
-

+ 5 - 4
engine/core/bv/Frustum.cpp

@@ -28,6 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Intersection.h"
 #include "Matrix4x4.h"
+#include "AABB.h"
 
 namespace crown
 {
@@ -150,10 +151,10 @@ void Frustum::from_matrix(const Matrix4x4& m)
 }
 
 //-----------------------------------------------------------------------------
-Box Frustum::to_box() const
+AABB Frustum::to_aabb() const
 {
-	Box tmp;
-	tmp.zero();
+	AABB tmp;
+	aabb::reset(tmp);
 
 	Vector3 vertices[8];
 	vertices[0] = vertex(0);
@@ -165,7 +166,7 @@ Box Frustum::to_box() const
 	vertices[6] = vertex(6);
 	vertices[7] = vertex(7);
 
-	tmp.add_points(vertices, 8);
+	aabb::add_points(tmp, 8, vertices);
 
 	return tmp;
 }

+ 2 - 2
engine/core/bv/Frustum.h

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Types.h"
-#include "Box.h"
+#include "MathTypes.h"
 #include "Vector3.h"
 #include "Plane.h"
 
@@ -70,7 +70,7 @@ struct Frustum
 	void		from_matrix(const Matrix4x4& m);				
 
 	/// Returns a Box containing the frustum volume.
-	Box			to_box() const;							
+	AABB		to_aabb() const;							
 
 public:
 

+ 246 - 0
engine/core/math/AABB.h

@@ -0,0 +1,246 @@
+/*
+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.
+*/
+
+#pragma once
+
+#include "Assert.h"
+#include "MathTypes.h"
+#include "Matrix4x4.h"
+#include "Sphere.h"
+#include "Types.h"
+#include "Vector3.h"
+
+namespace crown
+{
+
+namespace aabb
+{
+	void reset(AABB& b);
+
+	/// Returns the center of the box @a b.
+	Vector3 center(const AABB& b);
+
+	/// Returns the radius of the box @a b.
+	float radius(const AABB& b);
+
+	/// Returns the volume of the box @a b.
+	float volume(const AABB& b);
+
+	/// Adds @a num @a points to the box @a b, expanding its bounds if necessary.
+	void add_points(AABB& b, uint32_t num, const Vector3* points);
+
+	/// Adds @a num @a boxes to the box @a b, expanding its bounds if necessary.
+	void add_boxes(AABB& b, uint32_t num, const AABB* boxes);
+
+	/// Returns whether point @a p is contained in the box @a b.
+	bool contains_point(const AABB& b, const Vector3& p);
+
+	/// Returns the @a index -th vertex of the box.
+	Vector3 vertex(const AABB& b, uint32_t index);		
+
+	/// Returns the box enclosing @a b transformed by @a m.
+	AABB transformed(const AABB& b, const Matrix4x4& m);
+
+	/// Returns the eight vertices of the box @a b.
+	void to_vertices(const AABB& b, Vector3 v[8]);
+
+	/// Returns the sphere enclosing the box @a b.
+	Sphere to_sphere(const AABB& b);
+}
+
+namespace aabb
+{
+	//-----------------------------------------------------------------------------
+	inline void reset(AABB& b)
+	{
+		b.min = vector3::ZERO;
+		b.max = vector3::ZERO;
+	}
+
+	//-----------------------------------------------------------------------------
+	inline Vector3 center(const AABB& b)
+	{
+		return (b.min + b.max) * 0.5;
+	}
+
+	//-----------------------------------------------------------------------------
+	inline float radius(const AABB& b)
+	{
+		return vector3::length(b.max - (b.min + b.max) * 0.5);
+	}
+	//-----------------------------------------------------------------------------
+	inline float volume(const AABB& b)
+	{
+		return (b.max.x - b.min.x) * (b.max.y - b.min.y) * (b.max.z - b.min.z);
+	}
+
+	//-----------------------------------------------------------------------------
+	inline void add_points(AABB& b, uint32_t num, const Vector3* points)
+	{
+		for (uint32_t i = 0; i < num; i++)
+		{
+			const Vector3& p = points[i];
+
+			if (p.x < b.min.x) b.min.x = p.x;
+			if (p.y < b.min.y) b.min.y = p.y;
+			if (p.z < b.min.z) b.min.z = p.z;
+			if (p.x > b.max.x) b.max.x = p.x;
+			if (p.y > b.max.y) b.max.y = p.y;
+			if (p.z > b.max.z) b.max.z = p.z;
+		}
+	}
+
+	//-----------------------------------------------------------------------------
+	inline void add_boxes(AABB& b, uint32_t num, const AABB* boxes)
+	{
+		for (uint32_t i = 0; i < num; i++)
+		{
+			const AABB& box = boxes[i];
+
+			if (box.min.x < b.min.x) b.min.x = box.min.x;
+			if (box.min.y < b.min.y) b.min.y = box.min.y;
+			if (box.min.z < b.min.z) b.min.z = box.min.z;
+			if (box.max.x > b.max.x) b.max.x = box.max.x;
+			if (box.max.y > b.max.y) b.max.y = box.max.y;
+			if (box.max.z > b.max.z) b.max.z = box.max.z;
+		}
+	}
+
+	//-----------------------------------------------------------------------------
+	inline bool contains_point(const AABB& b, const Vector3& p)
+	{
+		return (p.x > b.min.x &&
+				p.y > b.min.y &&
+				p.z > b.min.z &&
+				p.x < b.max.x &&
+				p.y < b.max.y &&
+				p.z < b.max.z);
+	}
+
+	//-----------------------------------------------------------------------------
+	inline Vector3 vertex(const AABB& b, uint32_t index)
+	{
+		CE_ASSERT(index < 8, "Index must be < 8");
+
+		switch (index)
+		{
+			case 0: return Vector3(b.min.x, b.min.y, b.min.z);
+			case 1: return Vector3(b.max.x, b.min.y, b.min.z);
+			case 2: return Vector3(b.max.x, b.min.y, b.max.z);
+			case 3: return Vector3(b.min.x, b.min.y, b.max.z);
+			case 4: return Vector3(b.min.x, b.max.y, b.min.z);
+			case 5: return Vector3(b.max.x, b.max.y, b.min.z);
+			case 6: return Vector3(b.max.x, b.max.y, b.max.z);
+			case 7: return Vector3(b.min.x, b.max.y, b.max.z);
+		}
+	}
+
+	//-----------------------------------------------------------------------------
+	inline AABB transformed(const AABB& b, const Matrix4x4& m)
+	{
+		Vector3 vertices[8];
+		to_vertices(b, vertices);
+
+		vertices[0] = m * vertices[0];
+		vertices[1] = m * vertices[1];
+		vertices[2] = m * vertices[2];
+		vertices[3] = m * vertices[3];
+		vertices[4] = m * vertices[4];
+		vertices[5] = m * vertices[5];
+		vertices[6] = m * vertices[6];
+		vertices[7] = m * vertices[7];
+
+		AABB res;
+		reset(res);
+		add_points(res, 8, vertices);
+		return res;
+	}
+
+	//-----------------------------------------------------------------------------
+	inline void to_vertices(const AABB& b, Vector3 v[8])
+	{
+		// 7 ---- 6
+		// |      |
+		// |      |  <--- Top face
+		// 4 ---- 5
+		//
+		// 3 ---- 2
+		// |      |
+		// |      |  <--- Bottom face
+		// 0 ---- 1
+		v[0].x = b.min.x;
+		v[0].y = b.min.y;
+		v[0].z = b.max.z;
+
+		v[1].x = b.max.x;
+		v[1].y = b.min.y;
+		v[1].z = b.max.z;
+
+		v[2].x = b.max.x;
+		v[2].y = b.min.y;
+		v[2].z = b.min.z;
+
+		v[3].x = b.min.x;
+		v[3].y = b.min.y;
+		v[3].z = b.min.z;
+
+		v[4].x = b.min.x;
+		v[4].y = b.max.y;
+		v[4].z = b.max.z;
+
+		v[5].x = b.max.x;
+		v[5].y = b.max.y;
+		v[5].z = b.max.z;
+
+		v[6].x = b.max.x;
+		v[6].y = b.max.y;
+		v[6].z = b.min.z;
+
+		v[7].x = b.min.x;
+		v[7].y = b.max.y;
+		v[7].z = b.min.z;
+	}
+
+	//-----------------------------------------------------------------------------
+	inline Sphere to_sphere(const AABB& b)
+	{
+		return Sphere(center(b), radius(b));
+	}
+} // namespace aabb
+
+//-----------------------------------------------------------------------------
+inline AABB::AABB()
+{
+	// Do not initialize
+}
+
+//-----------------------------------------------------------------------------
+inline AABB::AABB(const Vector3& min, const Vector3& max)
+	: min(min), max(max)
+{
+}
+
+} // namespace crown

+ 30 - 29
engine/core/math/Intersection.h

@@ -34,6 +34,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Circle.h"
 #include "Rect.h"
+#include "AABB.h"
 
 namespace crown
 {
@@ -41,7 +42,7 @@ namespace crown
 /// Intersection test utils.
 /// Table of Intersection tests (3d)
 /// +----------+----------+----------+----------+----------+----------+
-/// |          | Ray      | Plane    | Sphere   | Box      | Frustum  |
+/// |          | Ray      | Plane    | Sphere   | AABB      | Frustum  |
 /// +----------+----------+----------+----------+----------+----------+
 /// | Ray      | No       | Yes      | Yes      | No       | No       |
 /// +----------+----------+----------+----------+----------+----------+
@@ -49,7 +50,7 @@ namespace crown
 /// +----------+----------+----------+----------+----------+----------+
 /// | Sphere   | -        | -        | Yes (+)  | No       | Yes      |
 /// +----------+----------+----------+----------+----------+----------+
-/// | Box      | -        | -        | -        | Yes (+)  | Yes      |
+/// | AABB      | -        | -        | -        | Yes (+)  | Yes      |
 /// +----------+----------+----------+----------+----------+----------+
 /// | Frustum  | -        | -        | -        | -        | No       |
 /// +----------+----------+----------+----------+----------+----------+
@@ -82,7 +83,7 @@ public:
 
 	static bool test_ray_plane(const Ray& r, const Plane& p, float& distance, Vector3& inttersectionPoint_t);
 	static bool test_ray_sphere(const Ray& r, const Sphere& s, float& distance, Vector3& intersectionPoint);
-	static bool test_ray_box(const Ray& r, const Box& b, float& distance, Vector3& intersectionPoint);
+	static bool test_ray_box(const Ray& r, const AABB& b, float& distance, Vector3& intersectionPoint);
 
 	static bool test_plane_3(const Plane& p1, const Plane& p2, const Plane& p3, Vector3& ip);
 
@@ -91,11 +92,11 @@ public:
 	static bool test_dynamic_sphere_plane(const Sphere& s, const Vector3& d, const Plane& p, float& it, Vector3& intersectionPoint);
 	static bool test_dynamic_sphere_sphere(const Sphere& s1, const Vector3& d1, const Sphere& s2, const Vector3& d2, float& it, Vector3& intersectionPoint);
 
-	static bool test_static_box_box(const Box& b1, const Box& b2);
-	static bool test_dynamic_box_box(const Box& b1, const Vector3& v1, const Box& b2, const Vector3& v2, float& it);
+	static bool test_static_box_box(const AABB& b1, const AABB& b2);
+	static bool test_dynamic_box_box(const AABB& b1, const Vector3& v1, const AABB& b2, const Vector3& v2, float& it);
 
 	static bool test_frustum_sphere(const Frustum& f, const Sphere& s);
-	static bool test_frustum_box(const Frustum& f, const Box& box);
+	static bool test_frustum_box(const Frustum& f, const AABB& box);
 
 	static bool test_circle_circle(const Circle& c1, const Circle& c2, Vector2& penetration);
 	static bool test_dynamic_circle_circle(const Circle& c1, const Vector2& d1, const Circle& c2, const Vector2& d2, float& it);
@@ -147,9 +148,9 @@ inline bool Intersection::test_ray_sphere(const Ray& r, const Sphere& s, float&
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::test_ray_box(const Ray& r, const Box& b, float& /*distance*/, Vector3& /*intersectionPoint*/)
+inline bool Intersection::test_ray_box(const Ray& r, const AABB& b, float& /*distance*/, Vector3& /*intersectionPoint*/)
 {
-	if (r.origin().x < b.min().x)
+	if (r.origin().x < b.min.x)
 	{
 		if (r.direction().x < 0.0)
 		{
@@ -157,7 +158,7 @@ inline bool Intersection::test_ray_box(const Ray& r, const Box& b, float& /*dist
 		}
 	}
 
-	if (r.origin().x > b.max().x)
+	if (r.origin().x > b.max.x)
 	{
 		if (r.direction().x > 0.0)
 		{
@@ -165,7 +166,7 @@ inline bool Intersection::test_ray_box(const Ray& r, const Box& b, float& /*dist
 		}
 	}
 
-	if (r.origin().y < b.min().y)
+	if (r.origin().y < b.min.y)
 	{
 		if (r.direction().y < 0.0)
 		{
@@ -173,7 +174,7 @@ inline bool Intersection::test_ray_box(const Ray& r, const Box& b, float& /*dist
 		}
 	}
 
-	if (r.origin().y > b.max().y)
+	if (r.origin().y > b.max.y)
 	{
 		if (r.direction().y > 0.0)
 		{
@@ -181,7 +182,7 @@ inline bool Intersection::test_ray_box(const Ray& r, const Box& b, float& /*dist
 		}
 	}
 
-	if (r.origin().z < b.min().z)
+	if (r.origin().z < b.min.z)
 	{
 		if (r.direction().z < 0.0)
 		{
@@ -189,7 +190,7 @@ inline bool Intersection::test_ray_box(const Ray& r, const Box& b, float& /*dist
 		}
 	}
 
-	if (r.origin().z > b.max().z)
+	if (r.origin().z > b.max.z)
 	{
 		if (r.direction().z > 0.0)
 		{
@@ -334,19 +335,19 @@ inline bool Intersection::test_dynamic_sphere_sphere(const Sphere& s1, const Vec
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::test_static_box_box(const Box& b1, const Box& b2)
+inline bool Intersection::test_static_box_box(const AABB& b1, const AABB& b2)
 {
-	if (b1.min().x > b2.max().x || b1.max().x < b2.min().x)
+	if (b1.min.x > b2.max.x || b1.max.x < b2.min.x)
 	{
 		return false;
 	}
 
-	if (b1.min().y > b2.max().y || b1.max().y < b2.min().y)
+	if (b1.min.y > b2.max.y || b1.max.y < b2.min.y)
 	{
 		return false;
 	}
 
-	if (b1.min().z > b2.max().z || b1.max().z < b2.min().z)
+	if (b1.min.z > b2.max.z || b1.max.z < b2.min.z)
 	{
 		return false;
 	}
@@ -355,7 +356,7 @@ inline bool Intersection::test_static_box_box(const Box& b1, const Box& b2)
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::test_dynamic_box_box(const Box& b1, const Vector3& v1, const Box& b2, const Vector3& v2, float& it)
+inline bool Intersection::test_dynamic_box_box(const AABB& b1, const Vector3& v1, const AABB& b2, const Vector3& v2, float& it)
 {
 	// b1 == static box
 	// b2 == moving box
@@ -369,7 +370,7 @@ inline bool Intersection::test_dynamic_box_box(const Box& b1, const Vector3& v1,
 	// If the resulting displacement equals zero, then fallback to static int32_tersection test
 	if (math::equals(d.x, (float)0.0))
 	{
-		if (b1.min().x > b2.max().x || b1.max().x < b2.min().x)
+		if (b1.min.x > b2.max.x || b1.max.x < b2.min.x)
 		{
 			return false;
 		}
@@ -377,7 +378,7 @@ inline bool Intersection::test_dynamic_box_box(const Box& b1, const Vector3& v1,
 
 	if (math::equals(d.y, (float)0.0))
 	{
-		if (b1.min().y > b2.max().y || b1.max().y < b2.min().y)
+		if (b1.min.y > b2.max.y || b1.max.y < b2.min.y)
 		{
 			return false;
 		}
@@ -385,7 +386,7 @@ inline bool Intersection::test_dynamic_box_box(const Box& b1, const Vector3& v1,
 
 	if (math::equals(d.z, (float)0.0))
 	{
-		if (b1.min().z > b2.max().z || b1.max().z < b2.min().z)
+		if (b1.min.z > b2.max.z || b1.max.z < b2.min.z)
 		{
 			return false;
 		}
@@ -393,16 +394,16 @@ inline bool Intersection::test_dynamic_box_box(const Box& b1, const Vector3& v1,
 
 	// Otherwise, compute the enter/leave times aint64_t each axis
 	float oneOverD = (float)(1.0 / d.x);
-	tEnterXYZ.x = (b1.min().x - b2.max().x) * oneOverD;
-	tLeaveXYZ.x = (b1.max().x - b2.min().x) * oneOverD;
+	tEnterXYZ.x = (b1.min.x - b2.max.x) * oneOverD;
+	tLeaveXYZ.x = (b1.max.x - b2.min.x) * oneOverD;
 
 	oneOverD = (float)(1.0 / d.y);
-	tEnterXYZ.y = (b1.min().y - b2.max().y) * oneOverD;
-	tLeaveXYZ.y = (b1.max().y - b2.min().y) * oneOverD;
+	tEnterXYZ.y = (b1.min.y - b2.max.y) * oneOverD;
+	tLeaveXYZ.y = (b1.max.y - b2.min.y) * oneOverD;
 
 	oneOverD = (float)(1.0 / d.z);
-	tEnterXYZ.z = (b1.min().z - b2.max().z) * oneOverD;
-	tLeaveXYZ.z = (b1.max().z - b2.min().z) * oneOverD;
+	tEnterXYZ.z = (b1.min.z - b2.max.z) * oneOverD;
+	tLeaveXYZ.z = (b1.max.z - b2.min.z) * oneOverD;
 
 	// We must ensure that enter time < leave time
 	if (tLeaveXYZ.x < tEnterXYZ.x)
@@ -457,7 +458,7 @@ inline bool Intersection::test_frustum_sphere(const Frustum& f, const Sphere& s)
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::test_frustum_box(const Frustum& f, const Box& b)
+inline bool Intersection::test_frustum_box(const Frustum& f, const AABB& b)
 {
 	uint32_t vertexOutCount;
 
@@ -467,7 +468,7 @@ inline bool Intersection::test_frustum_box(const Frustum& f, const Box& b)
 
 		for (uint32_t j = 0; j < 8; j++)
 		{
-			if (f.m_planes[i].distance_to_point(b.vertex(j)) < 0.0)
+			if (f.m_planes[i].distance_to_point(aabb::vertex(b, j)) < 0.0)
 			{
 				vertexOutCount++;
 			}

+ 11 - 0
engine/core/math/MathTypes.h

@@ -97,4 +97,15 @@ struct Quaternion
 	float x, y, z, w;
 };
 
+struct AABB
+{
+	AABB();
+
+	/// Constructs from @a min and @a max.
+	AABB(const Vector3& min, const Vector3& max);			
+
+	Vector3 min;
+	Vector3 max;
+};
+
 } // namespace crown