2
0
Эх сурвалжийг харах

Merge branch 'master' of github.com:taylor001/crown

Daniele Bartolini 10 жил өмнө
parent
commit
9f5831563e

+ 13 - 6
docs/lua_api.txt

@@ -48,9 +48,6 @@ Vector3
 	**multiply** (a, k) : Vector3
 		Multiplies the vector *a* by the scalar *k* and returns the result.
 
-	**divide** (a, k) : Vector3
-		Divides the vector *a* by the scalar *k* and returns the result.
-
 	**dot** (a, b) : float
 		Returns the dot product between the vectors *a* and *b*.
 
@@ -63,7 +60,7 @@ Vector3
 	**length** (a) : float
 		Returns the lenght of *a*.
 
-	**squared_length** (a) : float
+	**length_squared** (a) : float
 		Returns the squared length of *a*.
 
 	**set_length** (a, len)
@@ -75,6 +72,9 @@ Vector3
 	**distance** (a, b) : float
 		Returns the distance between the points *a* and *b*.
 
+	**distance_squared** (a, b) : float
+		Returns the squared distance between the points *a* and *b*.
+
 	**angle** (a, b) : float
 		Returns the angle between the vectors *a* and *b*.
 
@@ -84,6 +84,9 @@ Vector3
 	**min** (a, b) : Vector3
 		Returns a vector that contains the smallest value for each component from *a* and *b*.
 
+	**lerp** (a, b, t) : Vector3
+		Returns the linearly interpolated vector between *a* and *b* at time *t* in [0, 1].
+
 	**forward** () : Vector3
 
 	**backward** () : Vector3
@@ -101,6 +104,9 @@ Vector3
 	**zero** () : Vector3
 		Returns a vector with all values set to zero.
 
+	**to_string** (v) : string
+		Returns a string representing the vector *v*.
+
 Vector3Box
 ----------
 
@@ -267,8 +273,8 @@ Matrix4x4
 	**transform** (m, v) : Vector3
 		Transforms the vector *v* by the matrix *m* and returns the result.
 
-	**to_string** (a)
-		Returns a string representing the matrix.
+	**to_string** (m) : string
+		Returns a string representing the matrix *m*.
 
 Matrix4x4Box
 ------------
@@ -730,6 +736,7 @@ Device
 
 	**platform** () : string
 		Returns a string identifying what platform the engine is running on.
+		It can be either ``android``, ``linux`` or ``windows``
 
 	**architecture** () : string
 		Returns a string identifying what architecture the engine is running on.

+ 3 - 3
src/core/math/aabb.h

@@ -8,7 +8,7 @@
 #include "math_types.h"
 #include "vector3.h"
 #include "matrix4x4.h"
-#include "sphere.h"
+#include "error.h"
 
 namespace crown
 {
@@ -115,13 +115,13 @@ namespace aabb
 
 	inline bool contains_point(const AABB& b, const Vector3& p)
 	{
-		return (p.x > b.min.x
+		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)

+ 50 - 54
src/core/math/frustum.h

@@ -6,7 +6,6 @@
 #pragma once
 
 #include "math_types.h"
-#include "vector3.h"
 #include "plane.h"
 #include "aabb.h"
 #include "intersection.h"
@@ -19,6 +18,9 @@ namespace crown
 /// @ingroup Math
 namespace frustum
 {
+	/// Builds the frustum @a f from the view matrix @a m.
+	void from_matrix(Frustum& f, const Matrix4x4& m);
+
 	/// Returns whether the frustum @a f contains the point @a p.
 	bool contains_point(const Frustum& f, const Vector3& p);
 
@@ -35,59 +37,12 @@ namespace frustum
 	/// 7 = Far top left
 	Vector3 vertex(const Frustum& f, uint32_t index);
 
-	/// Builds the frustum @a f from the view matrix @a m.
-	void from_matrix(Frustum& f, const Matrix4x4& m);
-
 	/// Returns the AABB enclosing the frustum @a f.
 	AABB to_aabb(const Frustum& f);
 } // namespace frustum
 
 namespace frustum
 {
-	inline bool contains_point(const Frustum& f, const Vector3& p)
-	{
-		if (plane::distance_to_point(f.left, p) < 0.0) return false;
-		if (plane::distance_to_point(f.right, p) < 0.0) return false;
-		if (plane::distance_to_point(f.bottom, p) < 0.0) return false;
-		if (plane::distance_to_point(f.top, p) < 0.0) return false;
-		if (plane::distance_to_point(f.near, p) < 0.0) return false;
-		if (plane::distance_to_point(f.far, p) < 0.0) return false;
-
-		return true;
-	}
-
-	inline Vector3 vertex(const Frustum& f, uint32_t index)
-	{
-		CE_ASSERT(index < 8, "Index must be < 8");
-
-		// 0 = Near bottom left
-		// 1 = Near bottom right
-		// 2 = Near top right
-		// 3 = Near top left
-		// 4 = Far bottom left
-		// 5 = Far bottom right
-		// 6 = Far top right
-		// 7 = Far top left
-
-		const Plane* side = &f.left;
-		Vector3 ip;
-
-		switch (index)
-		{
-			case 0: plane_3_intersection(side[4], side[0], side[2], ip); break;
-			case 1: plane_3_intersection(side[4], side[1], side[2], ip); break;
-			case 2: plane_3_intersection(side[4], side[1], side[3], ip); break;
-			case 3: plane_3_intersection(side[4], side[0], side[3], ip); break;
-			case 4: plane_3_intersection(side[5], side[0], side[2], ip); break;
-			case 5: plane_3_intersection(side[5], side[1], side[2], ip); break;
-			case 6: plane_3_intersection(side[5], side[1], side[3], ip); break;
-			case 7: plane_3_intersection(side[5], side[0], side[3], ip); break;
-			default: break;
-		}
-
-		return ip;
-	}
-
 	inline void from_matrix(Frustum& f, const Matrix4x4& m)
 	{
 		f.left.n.x   = m.x.w + m.x.x;
@@ -128,11 +83,51 @@ namespace frustum
 		plane::normalize(f.far);
 	}
 
-	inline AABB to_aabb(const Frustum& f)
+	inline bool contains_point(const Frustum& f, const Vector3& p)
+	{
+		return !(plane::distance_to_point(f.left, p) < 0.0f
+			|| plane::distance_to_point(f.right, p) < 0.0f
+			|| plane::distance_to_point(f.bottom, p) < 0.0f
+			|| plane::distance_to_point(f.top, p) < 0.0f
+			|| plane::distance_to_point(f.near, p) < 0.0f
+			|| plane::distance_to_point(f.far, p) < 0.0f
+			);
+	}
+
+	inline Vector3 vertex(const Frustum& f, uint32_t index)
 	{
-		AABB tmp;
-		aabb::reset(tmp);
+		CE_ASSERT(index < 8, "Index out of bounds");
+
+		// 0 = Near bottom left
+		// 1 = Near bottom right
+		// 2 = Near top right
+		// 3 = Near top left
+		// 4 = Far bottom left
+		// 5 = Far bottom right
+		// 6 = Far top right
+		// 7 = Far top left
+
+		const Plane* side = &f.left;
+		Vector3 ip;
 
+		switch (index)
+		{
+			case 0: plane_3_intersection(side[4], side[0], side[2], ip); break;
+			case 1: plane_3_intersection(side[4], side[1], side[2], ip); break;
+			case 2: plane_3_intersection(side[4], side[1], side[3], ip); break;
+			case 3: plane_3_intersection(side[4], side[0], side[3], ip); break;
+			case 4: plane_3_intersection(side[5], side[0], side[2], ip); break;
+			case 5: plane_3_intersection(side[5], side[1], side[2], ip); break;
+			case 6: plane_3_intersection(side[5], side[1], side[3], ip); break;
+			case 7: plane_3_intersection(side[5], side[0], side[3], ip); break;
+			default: break;
+		}
+
+		return ip;
+	}
+
+	inline AABB to_aabb(const Frustum& f)
+	{
 		Vector3 vertices[8];
 		vertices[0] = vertex(f, 0);
 		vertices[1] = vertex(f, 1);
@@ -143,9 +138,10 @@ namespace frustum
 		vertices[6] = vertex(f, 6);
 		vertices[7] = vertex(f, 7);
 
-		aabb::add_points(tmp, 8, vertices);
-
-		return tmp;
+		AABB aabb;
+		aabb::reset(aabb);
+		aabb::add_points(aabb, 8, vertices);
+		return aabb;
 	}
 } // namespace frustum
 

+ 4 - 3
src/core/math/intersection.cpp

@@ -152,14 +152,15 @@ bool plane_3_intersection(const Plane& p1, const Plane& p2, const Plane& p3, Vec
 	const Vector3& n1 = p1.n;
 	const Vector3& n2 = p2.n;
 	const Vector3& n3 = p3.n;
-
-	float den = -dot(cross(n1, n2), n3);
+	const float den = -dot(cross(n1, n2), n3);
 
 	if (fequal(den, 0.0f))
 		return false;
 
+	const float inv_den = 1.0f / den;
+
 	Vector3 res = p1.d * cross(n2, n3) + p2.d * cross(n3, n1) + p3.d * cross(n1, n2);
-	ip = res / den;
+	ip = res * inv_den;
 
 	return true;
 }

+ 2 - 2
src/core/math/math_utils.h

@@ -67,9 +67,9 @@ inline bool is_pow_2(uint32_t x)
 }
 
 /// Returns the linear interpolated value between @a p0 and @a p1 at time @a t
-inline float linear(const float p0, const float p1, float t)
+inline float lerp(const float p0, const float p1, float t)
 {
-	return p0 + t * (p1 - p0);
+	return (1.0f - t) * p0 + t * p1;
 }
 
 /// Returns the cosine interpolated value between @a p0 and @a p1 at time @a t

+ 1 - 1
src/core/math/matrix4x4.h

@@ -274,7 +274,7 @@ inline Matrix4x4 operator*(Matrix4x4 a, const Matrix4x4& b)
 /// Sets the matrix @a m to perspective.
 inline void set_perspective(Matrix4x4& m, float fovy, float aspect, float near, float far)
 {
-	const float height = 1.0f / tanf(fovy * ((float) PI / 180.0f) * 0.5f);
+	const float height = 1.0f / tanf(to_rad(fovy) * 0.5f);
 	const float width = height * 1.0f / aspect;
 	const float aa = far / (far - near);
 	const float bb = -near * aa;

+ 1 - 0
src/core/math/quaternion.cpp

@@ -4,6 +4,7 @@
  */
 
 #include "quaternion.h"
+#include "error.h"
 
 namespace crown
 {

+ 3 - 3
src/core/math/sphere.h

@@ -49,7 +49,7 @@ namespace sphere
 		{
 			const Vector3* p = (const Vector3*)points;
 
-			const float dist = squared_length(*p - s.c);
+			const float dist = length_squared(*p - s.c);
 			if (dist > s.r*s.r)
 				s.r = sqrtf(dist);
 
@@ -66,7 +66,7 @@ namespace sphere
 	{
 		for (uint32_t i = 0; i < num; ++i)
 		{
-			const float dist = squared_length(spheres[i].c - s.c);
+			const float dist = length_squared(spheres[i].c - s.c);
 
 			if (dist < (spheres[i].r + s.r) * (spheres[i].r + s.r))
 			{
@@ -78,7 +78,7 @@ namespace sphere
 
 	inline bool contains_point(const Sphere& s, const Vector3& p)
 	{
-		float dist = squared_length(p - s.c);
+		float dist = length_squared(p - s.c);
 		return dist < s.r*s.r;
 	}
 } // namespace sphere

+ 24 - 25
src/core/math/vector2.h

@@ -7,7 +7,6 @@
 
 #include "math_types.h"
 #include "math_utils.h"
-#include "error.h"
 
 namespace crown
 {
@@ -43,15 +42,6 @@ inline Vector2& operator*=(Vector2& a, float k)
 	return a;
 }
 
-inline Vector2& operator/=(Vector2& a, float k)
-{
-	CE_ASSERT(k != 0.0f, "Division by zero");
-	float inv = 1.0f / k;
-	a.x *= inv;
-	a.y *= inv;
-	return a;
-}
-
 /// Negates @a a and returns the result.
 inline Vector2 operator-(const Vector2& a)
 {
@@ -89,13 +79,6 @@ inline Vector2 operator*(float k, Vector2 a)
 	return a;
 }
 
-/// Divides the vector @a a by the scalar @a k and returns the result.
-inline Vector2 operator/(Vector2 a, float k)
-{
-	a /= k;
-	return a;
-}
-
 /// Returns true whether the vectors @a a and @a b are equal.
 inline bool operator==(const Vector2& a, const Vector2& b)
 {
@@ -108,28 +91,29 @@ inline float dot(const Vector2& a, const Vector2& b)
 	return a.x * b.x + a.y * b.y;
 }
 
-/// Returns the lenght of @a a.
-inline float length(const Vector2& a)
+/// Returns the squared length of @a a.
+inline float length_squared(const Vector2& a)
 {
-	return sqrtf(a.x * a.x + a.y * a.y);
+	return dot(a, a);
 }
 
-/// Returns the squared length of @a a.
-inline float squared_length(const Vector2& a)
+/// Returns the length of @a a.
+inline float length(const Vector2& a)
 {
-	return a.x * a.x + a.y * a.y;
+	return sqrtf(length_squared(a));
 }
 
 /// Normalizes @a a and returns the result.
 inline Vector2 normalize(Vector2& a)
 {
-	float inv_len = 1.0f / length(a);
+	const float len = length(a);
+	const float inv_len = 1.0f / len;
 	a.x *= inv_len;
 	a.y *= inv_len;
 	return a;
 }
 
-/// Sets the lenght of @a a to @a len.
+/// Sets the length of @a a to @a len.
 inline void set_length(Vector2& a, float len)
 {
 	normalize(a);
@@ -137,6 +121,12 @@ inline void set_length(Vector2& a, float len)
 	a.y *= len;
 }
 
+/// Returns the squared distance between the points @a a and @a b.
+inline float distance_squared(const Vector2& a, const Vector2& b)
+{
+	return length_squared(b - a);
+}
+
 /// Returns the distance between the points @a a and @a b.
 inline float distance(const Vector2& a, const Vector2& b)
 {
@@ -167,6 +157,15 @@ inline Vector2 min(const Vector2& a, const Vector2& b)
 	return v;
 }
 
+/// Returns the linearly interpolated vector between @a and @b at time @a t in [0, 1].
+inline Vector2 lerp(const Vector2& a, const Vector2& b, float t)
+{
+	Vector2 v;
+	v.x = lerp(a.x, b.x, t);
+	v.y = lerp(a.y, b.y, t);
+	return v;
+}
+
 /// Returns the pointer to the data of @a a.
 inline float* to_float_ptr(Vector2& a)
 {

+ 25 - 26
src/core/math/vector3.h

@@ -7,7 +7,6 @@
 
 #include "math_types.h"
 #include "math_utils.h"
-#include "error.h"
 
 namespace crown
 {
@@ -47,16 +46,6 @@ inline Vector3& operator*=(Vector3& a, float k)
 	return a;
 }
 
-inline Vector3& operator/=(Vector3& a, float k)
-{
-	CE_ASSERT(k != 0.0f, "Division by zero");
-	float inv = 1.0f / k;
-	a.x *= inv;
-	a.y *= inv;
-	a.z *= inv;
-	return a;
-}
-
 /// Negates @a a and returns the result.
 inline Vector3 operator-(const Vector3& a)
 {
@@ -95,13 +84,6 @@ inline Vector3 operator*(float k, Vector3 a)
 	return a;
 }
 
-/// Divides the vector @a a by the scalar @a k and returns the result.
-inline Vector3 operator/(Vector3 a, float k)
-{
-	a /= k;
-	return a;
-}
-
 /// Returns true whether the vectors @a a and @a b are equal.
 inline bool operator==(const Vector3& a, const Vector3& b)
 {
@@ -120,29 +102,30 @@ inline Vector3 cross(const Vector3& a, const Vector3& b)
 	return vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
 }
 
-/// Returns the lenght of @a a.
-inline float length(const Vector3& a)
+/// Returns the squared length of @a a.
+inline float length_squared(const Vector3& a)
 {
-	return sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
+	return dot(a, a);
 }
 
-/// Returns the squared length of @a a.
-inline float squared_length(const Vector3& a)
+/// Returns the length of @a a.
+inline float length(const Vector3& a)
 {
-	return a.x * a.x + a.y * a.y + a.z * a.z;
+	return sqrtf(length_squared(a));
 }
 
 /// Normalizes @a a and returns the result.
 inline Vector3 normalize(Vector3& a)
 {
-	float inv_len = 1.0f / length(a);
+	const float len = length(a);
+	const float inv_len = 1.0f / len;
 	a.x *= inv_len;
 	a.y *= inv_len;
 	a.z *= inv_len;
 	return a;
 }
 
-/// Sets the lenght of @a a to @a len.
+/// Sets the length of @a a to @a len.
 inline void set_length(Vector3& a, float len)
 {
 	normalize(a);
@@ -151,6 +134,12 @@ inline void set_length(Vector3& a, float len)
 	a.z *= len;
 }
 
+/// Returns the squared distance between the points @a a and @a b.
+inline float distance_squared(const Vector3& a, const Vector3& b)
+{
+	return length_squared(b - a);
+}
+
 /// Returns the distance between the points @a a and @a b.
 inline float distance(const Vector3& a, const Vector3& b)
 {
@@ -183,6 +172,16 @@ inline Vector3 min(const Vector3& a, const Vector3& b)
 	return v;
 }
 
+/// Returns the linearly interpolated vector between @a and @b at time @a t in [0, 1].
+inline Vector3 lerp(const Vector3& a, const Vector3& b, float t)
+{
+	Vector3 v;
+	v.x = lerp(a.x, b.x, t);
+	v.y = lerp(a.y, b.y, t);
+	v.z = lerp(a.z, b.z, t);
+	return v;
+}
+
 /// Returns the pointer to the data of @a a.
 inline float* to_float_ptr(Vector3& a)
 {

+ 27 - 30
src/core/math/vector4.h

@@ -7,16 +7,12 @@
 
 #include "math_types.h"
 #include "math_utils.h"
-#include "error.h"
 
 namespace crown
 {
 /// @addtogroup Math
 /// @{
 
-/// Returns the Vector3 portion of @a a. (i.e. truncates w)
-Vector3 to_vector3(const Vector4& a);
-
 inline Vector4 vector4(float x, float y, float z, float w)
 {
 	Vector4 v;
@@ -64,17 +60,6 @@ inline Vector4& operator*=(Vector4& a, float k)
 	return a;
 }
 
-inline Vector4& operator/=(Vector4& a, float k)
-{
-	CE_ASSERT(k != 0.0f, "Division by zero");
-	float inv = 1.0f / k;
-	a.x *= inv;
-	a.y *= inv;
-	a.z *= inv;
-	a.w *= inv;
-	return a;
-}
-
 /// Negates @a a and returns the result.
 inline Vector4 operator-(const Vector4& a)
 {
@@ -114,13 +99,6 @@ inline Vector4 operator*(float k, Vector4 a)
 	return a;
 }
 
-/// Divides the vector @a a by the scalar @a k and returns the result.
-inline Vector4 operator/(Vector4 a, float k)
-{
-	a /= k;
-	return a;
-}
-
 /// Returns true whether the vectors @a a and @a b are equal.
 inline bool operator==(const Vector4& a, const Vector4& b)
 {
@@ -136,22 +114,23 @@ inline float dot(const Vector4& a, const Vector4& b)
 	return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
 }
 
-/// Returns the lenght of @a a.
-inline float length(const Vector4& a)
+/// Returns the squared length of @a a.
+inline float length_squared(const Vector4& a)
 {
-	return sqrtf(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
+	return dot(a, a);
 }
 
-/// Returns the squared length of @a a.
-inline float squared_length(const Vector4& a)
+/// Returns the length of @a a.
+inline float length(const Vector4& a)
 {
-	return a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w;
+	return sqrtf(length_squared(a));
 }
 
 /// Normalizes @a a and returns the result.
 inline Vector4 normalize(Vector4& a)
 {
-	float inv_len = 1.0f / length(a);
+	const float len = length(a);
+	const float inv_len = 1.0f / len;
 	a.x *= inv_len;
 	a.y *= inv_len;
 	a.z *= inv_len;
@@ -159,7 +138,7 @@ inline Vector4 normalize(Vector4& a)
 	return a;
 }
 
-/// Sets the lenght of @a a to @a len.
+/// Sets the length of @a a to @a len.
 inline void set_length(Vector4& a, float len)
 {
 	normalize(a);
@@ -169,6 +148,12 @@ inline void set_length(Vector4& a, float len)
 	a.w *= len;
 }
 
+/// Returns the squared distance between the points @a a and @a b.
+inline float distance_squared(const Vector4& a, const Vector4& b)
+{
+	return length_squared(b - a);
+}
+
 /// Returns the distance between the points @a a and @a b.
 inline float distance(const Vector4& a, const Vector4& b)
 {
@@ -203,6 +188,17 @@ inline Vector4 min(const Vector4& a, const Vector4& b)
 	return v;
 }
 
+/// Returns the linearly interpolated vector between @a and @b at time @a t in [0, 1].
+inline Vector4 lerp(const Vector4& a, const Vector4& b, float t)
+{
+	Vector4 v;
+	v.x = lerp(a.x, b.x, t);
+	v.y = lerp(a.y, b.y, t);
+	v.z = lerp(a.z, b.z, t);
+	v.w = lerp(a.w, b.w, t);
+	return v;
+}
+
 /// Returns the pointer to the data of @a a.
 inline float* to_float_ptr(Vector4& a)
 {
@@ -215,6 +211,7 @@ inline const float* to_float_ptr(const Vector4& a)
 	return &a.x;
 }
 
+/// Returns the Vector3 portion of @a a. (i.e. truncates w)
 inline Vector3 to_vector3(const Vector4& a)
 {
 	Vector3 v;

+ 48 - 50
src/lua/lua_math.cpp

@@ -157,13 +157,6 @@ static int vector3_multiply(lua_State* L)
 	return 1;
 }
 
-static int vector3_divide(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.push_vector3(stack.get_vector3(1) / stack.get_float(2));
-	return 1;
-}
-
 static int vector3_dot(lua_State* L)
 {
 	LuaStack stack(L);
@@ -192,10 +185,10 @@ static int vector3_length(lua_State* L)
 	return 1;
 }
 
-static int vector3_squared_length(lua_State* L)
+static int vector3_length_squared(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(squared_length(stack.get_vector3(1)));
+	stack.push_float(length_squared(stack.get_vector3(1)));
 	return 1;
 }
 
@@ -220,6 +213,13 @@ static int vector3_distance(lua_State* L)
 	return 1;
 }
 
+static int vector3_distance_squared(lua_State* L)
+{
+	LuaStack stack(L);
+	stack.push_float(distance_squared(stack.get_vector3(1), stack.get_vector3(2)));
+	return 1;
+}
+
 static int vector3_angle(lua_State* L)
 {
 	LuaStack stack(L);
@@ -241,6 +241,13 @@ static int vector3_min(lua_State* L)
 	return 1;
 }
 
+static int vector3_lerp(lua_State* L)
+{
+	LuaStack stack(L);
+	stack.push_vector3(lerp(stack.get_vector3(1), stack.get_vector3(2), stack.get_float(3)));
+	return 1;
+}
+
 static int vector3_forward(lua_State* L)
 {
 	LuaStack stack(L);
@@ -830,15 +837,6 @@ static int lightuserdata_mul(lua_State* L)
 	return 1;
 }
 
-static int lightuserdata_div(lua_State* L)
-{
-	LuaStack stack(L);
-	const Vector3& a = stack.get_vector3(1);
-	const float b = stack.get_float(2);
-	stack.push_vector3(a / b);
-	return 1;
-}
-
 static int lightuserdata_unm(lua_State* L)
 {
 	LuaStack stack(L);
@@ -888,37 +886,38 @@ void load_math(LuaEnvironment& env)
 	env.load_module_function("Math", "ray_sphere_intersection", math_ray_sphere_intersection);
 	env.load_module_function("Math", "ray_obb_intersection",    math_ray_obb_intersection);
 
-	env.load_module_function("Vector3", "new",            vector3_new);
-	env.load_module_function("Vector3", "x",              vector3_x);
-	env.load_module_function("Vector3", "y",              vector3_y);
-	env.load_module_function("Vector3", "z",              vector3_z);
-	env.load_module_function("Vector3", "set_x",          vector3_set_x);
-	env.load_module_function("Vector3", "set_y",          vector3_set_y);
-	env.load_module_function("Vector3", "set_z",          vector3_set_z);
-	env.load_module_function("Vector3", "values",         vector3_values);
-	env.load_module_function("Vector3", "add",            vector3_add);
-	env.load_module_function("Vector3", "subtract",       vector3_subtract);
-	env.load_module_function("Vector3", "multiply",       vector3_multiply);
-	env.load_module_function("Vector3", "divide",         vector3_divide);
-	env.load_module_function("Vector3", "dot",            vector3_dot);
-	env.load_module_function("Vector3", "cross",          vector3_cross);
-	env.load_module_function("Vector3", "equal",          vector3_equal);
-	env.load_module_function("Vector3", "length",         vector3_length);
-	env.load_module_function("Vector3", "squared_length", vector3_squared_length);
-	env.load_module_function("Vector3", "set_length",     vector3_set_length);
-	env.load_module_function("Vector3", "normalize",      vector3_normalize);
-	env.load_module_function("Vector3", "distance",       vector3_distance);
-	env.load_module_function("Vector3", "angle",          vector3_angle);
-	env.load_module_function("Vector3", "max",            vector3_max);
-	env.load_module_function("Vector3", "min",            vector3_min);
-	env.load_module_function("Vector3", "forward",        vector3_forward);
-	env.load_module_function("Vector3", "backward",       vector3_backward);
-	env.load_module_function("Vector3", "left",           vector3_left);
-	env.load_module_function("Vector3", "right",          vector3_right);
-	env.load_module_function("Vector3", "up",             vector3_up);
-	env.load_module_function("Vector3", "down",           vector3_down);
-	env.load_module_function("Vector3", "zero",           vector3_zero);
-	env.load_module_function("Vector3", "to_string",      vector3_to_string);
+	env.load_module_function("Vector3", "new",              vector3_new);
+	env.load_module_function("Vector3", "x",                vector3_x);
+	env.load_module_function("Vector3", "y",                vector3_y);
+	env.load_module_function("Vector3", "z",                vector3_z);
+	env.load_module_function("Vector3", "set_x",            vector3_set_x);
+	env.load_module_function("Vector3", "set_y",            vector3_set_y);
+	env.load_module_function("Vector3", "set_z",            vector3_set_z);
+	env.load_module_function("Vector3", "values",           vector3_values);
+	env.load_module_function("Vector3", "add",              vector3_add);
+	env.load_module_function("Vector3", "subtract",         vector3_subtract);
+	env.load_module_function("Vector3", "multiply",         vector3_multiply);
+	env.load_module_function("Vector3", "dot",              vector3_dot);
+	env.load_module_function("Vector3", "cross",            vector3_cross);
+	env.load_module_function("Vector3", "equal",            vector3_equal);
+	env.load_module_function("Vector3", "length",           vector3_length);
+	env.load_module_function("Vector3", "length_squared",   vector3_length_squared);
+	env.load_module_function("Vector3", "set_length",       vector3_set_length);
+	env.load_module_function("Vector3", "normalize",        vector3_normalize);
+	env.load_module_function("Vector3", "distance",         vector3_distance);
+	env.load_module_function("Vector3", "distance_squared", vector3_distance_squared);
+	env.load_module_function("Vector3", "angle",            vector3_angle);
+	env.load_module_function("Vector3", "max",              vector3_max);
+	env.load_module_function("Vector3", "min",              vector3_min);
+	env.load_module_function("Vector3", "lerp",             vector3_lerp);
+	env.load_module_function("Vector3", "forward",          vector3_forward);
+	env.load_module_function("Vector3", "backward",         vector3_backward);
+	env.load_module_function("Vector3", "left",             vector3_left);
+	env.load_module_function("Vector3", "right",            vector3_right);
+	env.load_module_function("Vector3", "up",               vector3_up);
+	env.load_module_function("Vector3", "down",             vector3_down);
+	env.load_module_function("Vector3", "zero",             vector3_zero);
+	env.load_module_function("Vector3", "to_string",        vector3_to_string);
 
 	env.load_module_constructor("Vector3", vector3_ctor);
 
@@ -1001,7 +1000,6 @@ void load_math(LuaEnvironment& env)
 	env.load_module_function("Lightuserdata_mt", "__add",      lightuserdata_add);
 	env.load_module_function("Lightuserdata_mt", "__sub",      lightuserdata_sub);
 	env.load_module_function("Lightuserdata_mt", "__mul",      lightuserdata_mul);
-	env.load_module_function("Lightuserdata_mt", "__div",      lightuserdata_div);
 	env.load_module_function("Lightuserdata_mt", "__unm",      lightuserdata_unm);
 	env.load_module_function("Lightuserdata_mt", "__index",    lightuserdata_index);
 	env.load_module_function("Lightuserdata_mt", "__newindex", lightuserdata_newindex);

+ 5 - 5
src/platform.h

@@ -126,15 +126,15 @@
 #endif
 
 #if CROWN_PLATFORM_ANDROID
-	#define CROWN_PLATFORM_NAME "Android"
+	#define CROWN_PLATFORM_NAME "android"
 #elif CROWN_PLATFORM_IOS
-	#define CROWN_PLATFORM_NAME "iOS"
+	#define CROWN_PLATFORM_NAME "ios"
 #elif CROWN_PLATFORM_LINUX
-	#define CROWN_PLATFORM_NAME "Linux"
+	#define CROWN_PLATFORM_NAME "linux"
 #elif CROWN_PLATFORM_OSX
-	#define CROWN_PLATFORM_NAME "OSX"
+	#define CROWN_PLATFORM_NAME "osx"
 #elif CROWN_PLATFORM_WINDOWS
-	#define CROWN_PLATFORM_NAME "Windows"
+	#define CROWN_PLATFORM_NAME "windows"
 #endif // CROWN_PLATFORM_
 
 #if CROWN_CPU_ARM

+ 1 - 0
src/renderers/debug_line.cpp

@@ -8,6 +8,7 @@
 #include "color4.h"
 #include "vector3.h"
 #include "matrix4x4.h"
+#include "error.h"
 #include <string.h> // memcpy
 #include <bgfx/bgfx.h>