瀏覽代碼

Port Vector3 to NMF

Daniele Bartolini 12 年之前
父節點
當前提交
f1cccd7f36

+ 0 - 1
engine/CMakeLists.txt

@@ -150,7 +150,6 @@ set (MATH_SRC
 	core/math/Matrix4x4.cpp
 	core/math/Plane.cpp
 	core/math/Quaternion.cpp
-	core/math/Vector3.cpp
 	core/math/Vector4.cpp
 )
 

+ 1 - 1
engine/audio/backend/ALSoundWorld.cpp

@@ -195,7 +195,7 @@ struct SoundInstance
 
 	void set_position(const Vector3& pos)
 	{
-		AL_CHECK(alSourcefv(m_source, AL_POSITION, pos.to_float_ptr()));
+		AL_CHECK(alSourcefv(m_source, AL_POSITION, vector3::to_float_ptr(pos)));
 	}
 
 	void set_range(float range)

+ 5 - 5
engine/core/bv/Box.h

@@ -49,8 +49,8 @@ public:
 					Box(const Vector3& min, const Vector3& max);			
 					Box(const Box& box);
 
-	const Vector3&		min() const;
-	const Vector3&		max() const;
+	const Vector3&	min() const;
+	const Vector3&	max() const;
 	void			set_min(const Vector3& min);
 	void			set_max(const Vector3& max);
 
@@ -221,7 +221,7 @@ inline Vector3 Box::center() const
 //-----------------------------------------------------------------------------
 inline float Box::radius() const
 {
-	return (m_max - (m_min + m_max) * 0.5).length();
+	return vector3::length(m_max - (m_min + m_max) * 0.5);
 }
 
 //-----------------------------------------------------------------------------
@@ -325,8 +325,8 @@ inline float Box::volume() const
 //-----------------------------------------------------------------------------
 inline void Box::zero()
 {
-	m_min.zero();
-	m_max.zero();
+	m_min = vector3::ZERO;
+	m_max = vector3::ZERO;
 }
 
 //-----------------------------------------------------------------------------

+ 4 - 4
engine/core/bv/Sphere.h

@@ -48,7 +48,7 @@ public:
 					Sphere(const Vector3& center, float radius);
 					Sphere(const Sphere& a);
 
-	const Vector3&		center() const;		
+	const Vector3&	center() const;		
 	float			radius() const;	
 	float			volume() const;	
 
@@ -122,7 +122,7 @@ inline void Sphere::add_points(const Vector3* points, uint32_t count)
 	{
 		const Vector3& p = points[i];
 
-		float dist = (p - m_center).squared_length();
+		float dist = vector3::squared_length(p - m_center);
 
 		if (dist >= m_radius * m_radius)
 		{
@@ -138,7 +138,7 @@ inline void Sphere::add_spheres(const Sphere* spheres, uint32_t count)
 	{
 		const Sphere& s = spheres[i];
 
-		float dist = (s.m_center - m_center).squared_length();
+		float dist = vector3::squared_length(s.m_center - m_center);
 
 		if (dist < (s.m_radius + m_radius) * (s.m_radius + m_radius))
 		{
@@ -153,7 +153,7 @@ inline void Sphere::add_spheres(const Sphere* spheres, uint32_t count)
 //-----------------------------------------------------------------------------
 inline bool Sphere::contains_point(const Vector3& p) const
 {
-	float dist = (p - m_center).squared_length();
+	float dist = vector3::squared_length(p - m_center);
 	return (dist < m_radius * m_radius);
 }
 

+ 36 - 36
engine/core/math/Intersection.h

@@ -115,8 +115,8 @@ private:
 //-----------------------------------------------------------------------------
 inline bool Intersection::test_ray_plane(const Ray& r, const Plane& p, float& distance, Vector3& intersectionPoint)
 {
-	float nd = r.direction().dot(p.n);
-	float orpn = r.origin().dot(p.n);
+	float nd = vector3::dot(r.direction(), p.n);
+	float orpn = vector3::dot(r.origin(), p.n);
 
 	if (nd < 0.0)
 	{
@@ -136,8 +136,8 @@ inline bool Intersection::test_ray_plane(const Ray& r, const Plane& p, float& di
 inline bool Intersection::test_ray_sphere(const Ray& r, const Sphere& s, float& distance, Vector3& intersectionPoint)
 {
 	Vector3 v = s.center() - r.origin();
-	float b = v.dot(r.direction());
-	float det = (s.radius() * s.radius()) - v.dot(v) + (b * b);
+	float b = vector3::dot(v, r.direction());
+	float det = (s.radius() * s.radius()) - vector3::dot(v, v) + (b * b);
 
 	if (det < 0.0 || b < s.radius())
 	{
@@ -228,14 +228,14 @@ inline bool Intersection::test_plane_3(const Plane& p1, const Plane& p2, const P
 	const Vector3& n2 = p2.n;
 	const Vector3& n3 = p3.n;
 
-	float den = -n1.cross(n2).dot(n3);
+	float den = -vector3::dot(vector3::cross(n1, n2), n3);
 
 	if (math::equals(den, (float)0.0))
 	{
 		return false;
 	}
 
-	Vector3 res = p1.d * n2.cross(n3) + p2.d * n3.cross(n1) + p3.d * n1.cross(n2);
+	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;
@@ -255,7 +255,7 @@ inline bool Intersection::test_static_sphere_plane(const Sphere& s, const Plane&
 //-----------------------------------------------------------------------------
 inline bool Intersection::test_static_sphere_sphere(const Sphere& a, const Sphere& b)
 {
-	float dist = (b.center() - a.center()).squared_length();
+	float dist = vector3::squared_length(b.center() - a.center());
 	return (dist < (b.radius() + a.radius()) * (b.radius() + a.radius()));
 }
 
@@ -269,7 +269,7 @@ inline bool Intersection::test_dynamic_sphere_plane(const Sphere& s, const Vecto
 	float t1;	// Time at which the sphere int32_tersects the plane remaining at the back side of the plane
 
 	float sphereToPlaneDistance = p.distance_to_point(sphereCenter);
-	float planeNormalDotVelocity = p.n.dot(d);
+	float planeNormalDotVelocity = vector3::dot(p.n, d);
 
 	if (planeNormalDotVelocity > 0.0)
 	{
@@ -336,9 +336,9 @@ inline bool Intersection::test_dynamic_sphere_triangle(const Sphere& s, const Ve
 	float x1, x2;
 
 	// v1
-	a = d.dot(d);
-	b = 2.0 * (d.dot(s.center() - tri.m_vertex[0]));
-	c = (tri.m_vertex[0] - s.center()).dot(tri.m_vertex[0] - s.center()) - (s.radius() * s.radius());
+	a = vector3::dot(d, d);
+	b = 2.0 * (vector3::dot(d, s.center() - tri.m_vertex[0]));
+	c = vector3::dot(tri.m_vertex[0] - s.center(), tri.m_vertex[0] - s.center()) - (s.radius() * s.radius());
 
 	if (math::solve_quadratic_equation(a, b, c, x1, x2))
 	{
@@ -348,8 +348,8 @@ inline bool Intersection::test_dynamic_sphere_triangle(const Sphere& s, const Ve
 	}
 
 	// v2
-	b = 2.0 * (d.dot(s.center() - tri.m_vertex[1]));
-	c = (tri.m_vertex[1] - s.center()).dot(tri.m_vertex[1] - s.center()) - (s.radius() * s.radius());
+	b = 2.0 * (vector3::dot(d, s.center() - tri.m_vertex[1]));
+	c = vector3::dot(tri.m_vertex[1] - s.center(), tri.m_vertex[1] - s.center()) - (s.radius() * s.radius());
 
 	if (math::solve_quadratic_equation(a, b, c, x1, x2))
 	{
@@ -359,8 +359,8 @@ inline bool Intersection::test_dynamic_sphere_triangle(const Sphere& s, const Ve
 	}
 
 	// v3
-	b = 2.0 * (d.dot(s.center() - tri.m_vertex[2]));
-	c = (tri.m_vertex[2] - s.center()).dot(tri.m_vertex[2] - s.center()) - (s.radius() * s.radius());
+	b = 2.0 * (vector3::dot(d, s.center() - tri.m_vertex[2]));
+	c = vector3::dot(tri.m_vertex[2] - s.center(), tri.m_vertex[2] - s.center()) - (s.radius() * s.radius());
 
 	if (math::solve_quadratic_equation(a, b, c, x1, x2))
 	{
@@ -377,20 +377,20 @@ inline bool Intersection::test_dynamic_sphere_triangle(const Sphere& s, const Ve
 	float edgeSquaredLength;
 	float velocitySquaredLength;
 
-	velocitySquaredLength = d.squared_length();
+	velocitySquaredLength = vector3::squared_length(d);
 
 	// e1
 	edge = tri.m_vertex[1] - tri.m_vertex[0];
 	centerToVertex = tri.m_vertex[0] - s.center();
-	edgeDotVelocity = edge.dot(d);
-	edgeDotCenterToVertex = edge.dot(centerToVertex);
-	edgeSquaredLength = edge.squared_length();
+	edgeDotVelocity = vector3::dot(edge, d);
+	edgeDotCenterToVertex = vector3::dot(edge, centerToVertex);
+	edgeSquaredLength = vector3::squared_length(edge);
 
 
 	a = edgeSquaredLength * -velocitySquaredLength + edgeDotVelocity * edgeDotVelocity;
-	b = edgeSquaredLength * (2.0 * d.dot(centerToVertex)) - (2.0 * edgeDotVelocity * edgeDotCenterToVertex);
+	b = edgeSquaredLength * (2.0 * vector3::dot(d, centerToVertex)) - (2.0 * edgeDotVelocity * edgeDotCenterToVertex);
 
-	c = edgeSquaredLength * ((s.radius() * s.radius()) - centerToVertex.squared_length()) + (edgeDotCenterToVertex * edgeDotCenterToVertex);
+	c = edgeSquaredLength * s.radius() * s.radius() - vector3::squared_length(centerToVertex) + (edgeDotCenterToVertex * edgeDotCenterToVertex);
 
 	if (math::solve_quadratic_equation(a, b, c, x1, x2))
 	{
@@ -407,15 +407,15 @@ inline bool Intersection::test_dynamic_sphere_triangle(const Sphere& s, const Ve
 	// e2
 	edge = tri.m_vertex[2] - tri.m_vertex[1];
 	centerToVertex = tri.m_vertex[1] - s.center();
-	edgeDotVelocity = edge.dot(d);
-	edgeDotCenterToVertex = edge.dot(centerToVertex);
-	edgeSquaredLength = edge.squared_length();
+	edgeDotVelocity = vector3::dot(edge, d);
+	edgeDotCenterToVertex = vector3::dot(edge, centerToVertex);
+	edgeSquaredLength = vector3::squared_length(edge);
 
 
 	a = edgeSquaredLength * -velocitySquaredLength + edgeDotVelocity * edgeDotVelocity;
-	b = edgeSquaredLength * (2.0 * d.dot(centerToVertex)) - (2.0 * edgeDotVelocity * edgeDotCenterToVertex);
+	b = edgeSquaredLength * 2.0 * vector3::dot(d, centerToVertex) - (2.0 * edgeDotVelocity * edgeDotCenterToVertex);
 
-	c = edgeSquaredLength * ((s.radius() * s.radius()) - centerToVertex.squared_length()) + (edgeDotCenterToVertex * edgeDotCenterToVertex);
+	c = edgeSquaredLength * ((s.radius() * s.radius()) - vector3::squared_length(centerToVertex)) + (edgeDotCenterToVertex * edgeDotCenterToVertex);
 
 	if (math::solve_quadratic_equation(a, b, c, x1, x2))
 	{
@@ -432,15 +432,15 @@ inline bool Intersection::test_dynamic_sphere_triangle(const Sphere& s, const Ve
 	// e3
 	edge = tri.m_vertex[0] - tri.m_vertex[2];
 	centerToVertex = tri.m_vertex[2] - s.center();
-	edgeDotVelocity = edge.dot(d);
-	edgeDotCenterToVertex = edge.dot(centerToVertex);
-	edgeSquaredLength = edge.squared_length();
+	edgeDotVelocity = vector3::dot(edge, d);
+	edgeDotCenterToVertex = vector3::dot(edge, centerToVertex);
+	edgeSquaredLength = vector3::squared_length(edge);
 
 
 	a = edgeSquaredLength * -velocitySquaredLength + edgeDotVelocity * edgeDotVelocity;
-	b = edgeSquaredLength * (2.0 * d.dot(centerToVertex)) - (2.0 * edgeDotVelocity * edgeDotCenterToVertex);
+	b = edgeSquaredLength * (2.0 * vector3::dot(d, centerToVertex)) - (2.0 * edgeDotVelocity * edgeDotCenterToVertex);
 
-	c = edgeSquaredLength * ((s.radius() * s.radius()) - centerToVertex.squared_length()) + (edgeDotCenterToVertex * edgeDotCenterToVertex);
+	c = edgeSquaredLength * ((s.radius() * s.radius()) - vector3::squared_length(centerToVertex)) + (edgeDotCenterToVertex * edgeDotCenterToVertex);
 
 	if (math::solve_quadratic_equation(a, b, c, x1, x2))
 	{
@@ -463,7 +463,7 @@ inline bool Intersection::test_dynamic_sphere_sphere(const Sphere& s1, const Vec
 	// s1 == static sphere
 	// s2 == moving sphere
 	Vector3 d = d2 - d1;
-	d.normalize();
+	vector3::normalize(d);
 
 	const Vector3& cs = s1.center();
 	const Vector3& cm = s2.center();
@@ -472,15 +472,15 @@ inline bool Intersection::test_dynamic_sphere_sphere(const Sphere& s1, const Vec
 	float r = s1.radius() + s2.radius();
 
 	// If ||e|| < r, int32_tersection occurs at t = 0
-	if (e.length() < r)
+	if (vector3::length(e) < r)
 	{
 		it = 0.0;
 		return true;
 	}
 
 	// it == Intersection Time
-	float ed = e.dot(d);
-	float squared = (ed * ed) + (r * r) - e.dot(e);
+	float ed = vector3::dot(e, d);
+	float squared = (ed * ed) + (r * r) - vector3::dot(e, e);
 
 	// If the value inside the square root is neg, then no int32_tersection
 	if (squared < 0.0)
@@ -489,7 +489,7 @@ inline bool Intersection::test_dynamic_sphere_sphere(const Sphere& s1, const Vec
 	}
 
 	float t = ed - math::sqrt(squared);
-	float l = (d2 - d1).length();
+	float l = vector3::length(d2 - d1);
 
 	// If t < 0 || t > l, then non int32_tersection in the considered period of time
 	if (t < 0.0 || t > l)

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

@@ -48,4 +48,23 @@ struct Vector2
 	float x, y;
 };
 
+struct Vector3
+{
+	Vector3();
+	Vector3(float val);
+	Vector3(float nx, float ny, float nz);
+	Vector3(const float v[3]);
+	Vector3(const Vector3& a);
+
+	float operator[](uint32_t i) const;
+	float& operator[](uint32_t i);
+
+	Vector3& operator+=(const Vector3& a);
+	Vector3& operator-=(const Vector3& a);
+	Vector3& operator*=(float k);
+	Vector3& operator/=(float k);
+
+	float x, y, z;
+};
+
 } // namespace crown

+ 15 - 11
engine/core/math/Matrix4x4.cpp

@@ -682,10 +682,10 @@ Matrix4x4 Matrix4x4::get_transposed() const
 void Matrix4x4::build_look_at_rh(const Vector3& pos, const Vector3& target, const Vector3& up)
 {
 	Vector3 zAxis =  pos - target;
-	zAxis.normalize();
+	vector3::normalize(zAxis);
 
-	Vector3 xAxis = up.cross(zAxis);
-	Vector3 yAxis = zAxis.cross(xAxis);
+	Vector3 xAxis = vector3::cross(up, zAxis);
+	Vector3 yAxis = vector3::cross(zAxis, xAxis);
 
 	m[0] = xAxis.x;
 	m[1] = yAxis.x;
@@ -699,9 +699,9 @@ void Matrix4x4::build_look_at_rh(const Vector3& pos, const Vector3& target, cons
 	m[9] = yAxis.z;
 	m[10] = zAxis.z;
 	m[11] = 0.0;
-	m[12] = -pos.dot(xAxis);
-	m[13] = -pos.dot(yAxis);
-	m[14] = -pos.dot(zAxis);
+	m[12] = -vector3::dot(pos, xAxis);
+	m[13] = -vector3::dot(pos, yAxis);
+	m[14] = -vector3::dot(pos, zAxis);
 	m[15] = 1.0;
 }
 
@@ -709,10 +709,12 @@ void Matrix4x4::build_look_at_rh(const Vector3& pos, const Vector3& target, cons
 void Matrix4x4::build_viewpoint_billboard(const Vector3& pos, const Vector3& target, const Vector3& up)
 {
 	Vector3 zAxis = target - pos;
-	zAxis.normalize();
+	vector3::normalize(zAxis);
 
-	Vector3 xAxis = up.cross(zAxis).normalize();
-	Vector3 yAxis = zAxis.cross(xAxis).normalize();
+	Vector3 xAxis = vector3::cross(up, zAxis);
+	Vector3 yAxis = vector3::cross(zAxis, xAxis);
+	vector3::normalize(xAxis);
+	vector3::normalize(yAxis);
 
 	m[0] = xAxis.x;
 	m[1] = xAxis.y;
@@ -737,8 +739,10 @@ void Matrix4x4::build_axis_billboard(const Vector3& pos, const Vector3& target,
 {
 	Vector3 zAxis = target - pos;
 
-	Vector3 xAxis = axis.cross(zAxis).normalize();
-	zAxis = axis.cross(xAxis).normalize();
+	Vector3 xAxis = vector3::cross(axis, zAxis);
+	zAxis = vector3::cross(axis, xAxis);
+	vector3::normalize(xAxis);
+	vector3::normalize(zAxis);
 	const Vector3& yAxis = axis;
 
 	m[0] = xAxis.x;

+ 7 - 7
engine/core/math/Plane.cpp

@@ -31,10 +31,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-const Plane Plane::ZERO = Plane(Vector3::ZERO, 0.0);
-const Plane	Plane::XAXIS = Plane(Vector3::XAXIS, 0.0);
-const Plane	Plane::YAXIS = Plane(Vector3::YAXIS, 0.0);
-const Plane	Plane::ZAXIS = Plane(Vector3::ZAXIS, 0.0);
+const Plane Plane::ZERO = Plane(vector3::ZERO, 0.0);
+const Plane	Plane::XAXIS = Plane(vector3::XAXIS, 0.0);
+const Plane	Plane::YAXIS = Plane(vector3::YAXIS, 0.0);
+const Plane	Plane::ZAXIS = Plane(vector3::ZAXIS, 0.0);
 
 //-----------------------------------------------------------------------------
 Plane::Plane()
@@ -54,7 +54,7 @@ Plane::Plane(const Vector3& normal, float dist) : n(normal), d(dist)
 //-----------------------------------------------------------------------------
 Plane& Plane::normalize()
 {
-	float len = n.length();
+	float len = vector3::length(n);
 
 	if (math::equals(len, (float)0.0))
 	{
@@ -72,13 +72,13 @@ Plane& Plane::normalize()
 //-----------------------------------------------------------------------------
 float Plane::distance_to_point(const Vector3& p) const
 {
-	return n.dot(p) + d;
+	return vector3::dot(n, p) + d;
 }
 
 //-----------------------------------------------------------------------------
 bool Plane::contains_point(const Vector3& p) const
 {
-	return math::equals(n.dot(p) + d, (float)0.0);
+	return math::equals(vector3::dot(n, p) + d, (float)0.0);
 }
 
 } // namespace crown

+ 4 - 4
engine/core/math/Quaternion.cpp

@@ -59,7 +59,7 @@ Quaternion::Quaternion(const Vector3& axis, float angle) :
 void Quaternion::negate()
 {
 	w = -w;
-	v.negate();
+	v = -v;
 }
 
 //-----------------------------------------------------------------------------
@@ -151,8 +151,8 @@ Quaternion Quaternion::operator*(const Quaternion& b) const
 {
 	Quaternion tmp;
 
-	tmp.w = w * b.w - v.dot(b.v);
-	tmp.v = w * b.v + b.w * v + b.v.cross(v);
+	tmp.w = w * b.w - vector3::dot(v, b.v);
+	tmp.v = w * b.v + b.w * v + vector3::cross(b.v, v);
 
 	return tmp;
 }
@@ -199,7 +199,7 @@ the vector dot product; the larger the absolute value of the Quaternion dot prod
 //-----------------------------------------------------------------------------
 float dot(const Quaternion& a, const Quaternion& b)
 {
-	return a.w * b.w + a.v.dot(b.v);
+	return a.w * b.w + vector3::dot(a.v, b.v);
 }
 
 // Spherical Linear interpolation

+ 10 - 8
engine/core/math/Triangle.h

@@ -89,7 +89,8 @@ inline Triangle::~Triangle()
 //-----------------------------------------------------------------------------
 inline float Triangle::area() const
 {
-	return ((m_vertex[1] - m_vertex[0]).cross(m_vertex[2] - m_vertex[0])).length() * (float)0.5;
+	Vector3 cr = vector3::cross(m_vertex[1] - m_vertex[0], m_vertex[2] - m_vertex[0]);
+	return vector3::length(cr * 0.5);
 }
 
 //-----------------------------------------------------------------------------
@@ -109,14 +110,14 @@ inline Vector3 Triangle::barycentric_coords(const Vector3& p) const
 	Vector3 d2 = p - m_vertex[1];
 	Vector3 d3 = p - m_vertex[2];
 
-	Vector3 n = e1.cross(e2) / e1.cross(e2).length();
+	Vector3 n = vector3::cross(e1, e2) / vector3::length(vector3::cross(e1, e2));
 
 	// Signed areas
-	float at = (float)(e1.cross(e2).dot(n) * 0.5);
+	float at = (float)(vector3::dot(vector3::cross(e1, e2), n) * 0.5);
 
-	float at1 = (float)(e1.cross(d3).dot(n) * 0.5);
-	float at2 = (float)(e2.cross(d1).dot(n) * 0.5);
-	float at3 = (float)(e3.cross(d2).dot(n) * 0.5);
+	float at1 = (float)(vector3::dot(vector3::cross(e1, d3), n) * 0.5);
+	float at2 = (float)(vector3::dot(vector3::cross(e2, d1), n) * 0.5);
+	float at3 = (float)(vector3::dot(vector3::cross(e3, d2), n) * 0.5);
 
 	float oneOverAt = (float)(1.0 / at);
 
@@ -142,8 +143,9 @@ inline Plane Triangle::to_plane() const
 	Vector3 e1 = m_vertex[2] - m_vertex[1];
 	Vector3 e2 = m_vertex[1] - m_vertex[0];
 
-	Vector3 n = e2.cross(e1).normalize();
-	float d = -n.dot(m_vertex[0]);
+	Vector3 e2xe1 = vector3::cross(e2, e1);
+	Vector3 n = vector3::normalize(e2xe1);
+	float d = -vector3::dot(n, m_vertex[0]);
 
 	return Plane(n, d);
 }

+ 0 - 39
engine/core/math/Vector3.cpp

@@ -1,39 +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.
-*/
-
-#include "Vector3.h"
-
-namespace crown
-{
-
-const Vector3 Vector3::ZERO	= Vector3(0.0, 0.0, 0.0);
-const Vector3 Vector3::ONE	= Vector3(1.0, 1.0, 1.0);
-const Vector3 Vector3::XAXIS	= Vector3(1.0, 0.0, 0.0);
-const Vector3 Vector3::YAXIS	= Vector3(0.0, 1.0, 0.0);
-const Vector3 Vector3::ZAXIS	= Vector3(0.0, 0.0, 1.0);
-
-} // namespace crown
-

+ 154 - 262
engine/core/math/Vector3.h

@@ -30,112 +30,196 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "MathUtils.h"
 #include "Vector2.h"
+#include "MathTypes.h"
 
 namespace crown
 {
 
-/// 3D column vector.
-struct Vector3
+/// Negates @a a and returns the result.
+Vector3 operator-(const Vector3& a);
+
+/// Adds the vector @a a to @a b and returns the result.
+Vector3 operator+(Vector3 a, const Vector3& b);
+
+/// Subtracts the vector @a b from @a a and returns the result.
+Vector3 operator-(Vector3 a, const Vector3& b);
+
+/// Multiplies the vector @a a by the scalar @a k and returns the result.
+Vector3 operator*(Vector3 a, float k);
+
+/// @copydoc operator*(Vector3, float)
+Vector3 operator*(float k, Vector3 a);
+
+/// Divides the vector @a a by the scalar @a k and returns the result.
+Vector3 operator/(Vector3 a, float k);
+
+/// Returns true whether the vectors @a a and @a b are equal.
+bool operator==(const Vector3& a, const Vector3& b);
+
+namespace vector3
 {
-public:
+	const Vector3 ZERO = Vector3(0, 0, 0);
+	const Vector3 XAXIS = Vector3(1, 0, 0);
+	const Vector3 YAXIS = Vector3(0, 1, 0);
+	const Vector3 ZAXIS = Vector3(0, 0, 1);
 
-	float				x, y, z;
+	/// Returns the dot product between the vectors @a a and @a b.
+	float dot(const Vector3& a, const Vector3& b);
 
-	/// Does nothing for efficiency.
-						Vector3();	
+	/// Returns the cross product between the vectors @a a and @a b.
+	Vector3 cross(const Vector3& a, const Vector3& b);
 
-	/// Initializes all the components to val								
-						Vector3(float val);	
+	/// Returns the lenght of @a a.
+	float length(const Vector3& a);
 
-	/// Constructs from three components						
-						Vector3(float nx, float ny, float nz);
-						
-	/// Constructs from array		
-						Vector3(const float v[3]);					
-						Vector3(const Vector3& a);	
+	/// Returns the squared length of @a a.
+	float squared_length(const Vector3& a);
 
-	/// Random access by index
-	float				operator[](uint32_t i) const;
+	/// Sets the lenght of @a a to @a len.
+	void set_length(Vector3& a, float len);
 
-	/// Random access by index			
-	float&				operator[](uint32_t i);					
+	/// Normalizes @a a and returns the result.
+	Vector3 normalize(Vector3& a);
 
-	Vector3				operator+(const Vector3& a) const;			
-	Vector3&			operator+=(const Vector3& a);				
-	Vector3 			operator-(const Vector3& a) const;			
-	Vector3&			operator-=(const Vector3& a);				
-	Vector3				operator*(float k) const;				
-	Vector3&			operator*=(float k);						
-	Vector3				operator/(float k) const;				
-	Vector3&			operator/=(float k);
+	/// Returns the distance between the points @a a and @a b.
+	float distance(const Vector3& a, const Vector3& b);
 
-	/// Dot product						
-	float				dot(const Vector3& a) const;
+	/// Returns the angle between the vectors @a a and @a b.
+	float angle(const Vector3& a, const Vector3& b);
 
-	/// Cross product				
-	Vector3				cross(const Vector3& a) const;				
+	/// Returns the pointer to the data of @a a.
+	float* to_float_ptr(Vector3& a);
 
-	/// For simmetry
-	friend Vector3		operator*(float k, const Vector3& a);		
+	/// @copydoc to_float_ptr(Vector3&)
+	const float* to_float_ptr(const Vector3& a);
 
-	bool				operator==(const Vector3& other) const;	
-	bool				operator!=(const Vector3& other) const;
+	/// Returns the Vector2 portion of @a a. (i.e. truncates z)
+	Vector2 to_vector2(const Vector3& a);
+} // namespace vector3
 
-	/// Returns whether all the components of this vector are smaller than all of the "other" vector	
-	bool				operator<(const Vector3& other) const;
+inline Vector3 operator-(const Vector3& a)
+{
+	return Vector3(-a.x, -a.y, -a.z);
+}
 
-	/// Returns whether all the components of this vector are greater than all of the "other" vector		
-	bool				operator>(const Vector3& other) const;		
+inline Vector3 operator+(Vector3 a, const Vector3& b)
+{
+	a += b;
+	return a;
+}
 
-	/// Returns the vector's length
-	float				length() const;	
+inline Vector3 operator-(Vector3 a, const Vector3& b)
+{
+	a -= b;
+	return a;
+}
 
-	/// Returns the vector's squared length						
-	float				squared_length() const;
+inline Vector3 operator*(Vector3 a, float k)
+{
+	a *= k;
+	return a;
+}
 
-	/// Sets the vector's length					
-	void				set_length(float len);
+inline Vector3 operator*(float k, Vector3 a)
+{
+	a *= k;
+	return a;
+}
 
-	/// Normalizes the vector					
-	Vector3&			normalize();
+inline Vector3 operator/(Vector3 a, float k)
+{
+	a /= k;
+	return a;
+}
 
-	/// Returns the normalized vector							
-	Vector3				get_normalized() const;		
+inline bool operator==(const Vector3& a, const Vector3& b)
+{
+	return math::equals(a.x, b.x) && math::equals(a.y, b.y) && math::equals(a.z, b.z);
+}
 
-	/// Negates the vector (i.e. builds the inverse)			
-	Vector3&			negate();
+namespace vector3
+{
+	//-----------------------------------------------------------------------------
+	inline float dot(const Vector3& a, const Vector3& b)
+	{
+		return a.x * b.x + a.y * b.y + a.z * b.z;
+	}
 
-	/// Negates the vector (i.e. builds the inverse)								
-	Vector3				operator-() const;						
+	//-----------------------------------------------------------------------------
+	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 distance
-	float				get_distance_to(const Vector3& a) const;	
+	//-----------------------------------------------------------------------------
+	inline float length(const Vector3& a)
+	{
+		return math::sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
+	}
 
-	/// Returns the angle in radians
-	float				get_angle_between(const Vector3& a) const;	
+	//-----------------------------------------------------------------------------
+	inline float squared_length(const Vector3& a)
+	{
+		return a.x * a.x + a.y * a.y + a.z * a.z;
+	}
 
-	/// Sets all components to zero
-	void				zero();									
+	//-----------------------------------------------------------------------------
+	inline void set_length(Vector3& a, float len)
+	{
+		normalize(a);
 
-	/// Returns the pointer to the vector's data
-	float*				to_float_ptr();	
+		a.x *= len;
+		a.y *= len;
+		a.z *= len;
+	}
 
-	/// Returns the pointer to the vector's data						
-	const float*		to_float_ptr() const;
+	//-----------------------------------------------------------------------------
+	inline Vector3 normalize(Vector3& a)
+	{
+		float inv_len = 1.0 / length(a);
 
-	/// Returns a Vector2 with only x and y coordinates					
-	Vector2				to_vec2() const;						
+		a.x *= inv_len;
+		a.y *= inv_len;
+		a.z *= inv_len;
 
-	static const Vector3	ZERO;
-	static const Vector3	ONE;
-	static const Vector3	XAXIS;
-	static const Vector3	YAXIS;
-	static const Vector3	ZAXIS;
-};
+		return a;
+	}
+
+	//-----------------------------------------------------------------------------
+	inline float distance(const Vector3& a, const Vector3& b)
+	{
+		return length(b - a);
+	}
+
+	//-----------------------------------------------------------------------------
+	inline float angle(const Vector3& a, const Vector3& b)
+	{
+		return math::acos(dot(a, b) / (length(a) * length(b)));
+	}
+
+	//-----------------------------------------------------------------------------
+	inline float* to_float_ptr(Vector3& a)
+	{
+		return &a.x;
+	}
+
+	//-----------------------------------------------------------------------------
+	inline const float* to_float_ptr(const Vector3& a)
+	{
+		return &a.x;
+	}
+
+	//-----------------------------------------------------------------------------
+	inline Vector2 to_vector2(const Vector3& a)
+	{
+		return Vector2(a.x, a.y);
+	}
+} // namespace vector3
 
 //-----------------------------------------------------------------------------
 inline Vector3::Vector3()
 {
+	// Do not initialize
 }
 
 //-----------------------------------------------------------------------------
@@ -174,12 +258,6 @@ inline float& Vector3::operator[](uint32_t i)
 	return (&x)[i];
 }
 
-//-----------------------------------------------------------------------------
-inline Vector3 Vector3::operator+(const Vector3& a) const
-{
-	return Vector3(x + a.x, y + a.y, z + a.z);
-}
-
 //-----------------------------------------------------------------------------
 inline Vector3& Vector3::operator+=(const Vector3& a)
 {
@@ -190,12 +268,6 @@ inline Vector3& Vector3::operator+=(const Vector3& a)
 	return *this;
 }
 
-//-----------------------------------------------------------------------------
-inline Vector3 Vector3::operator-(const Vector3& a) const
-{
-	return Vector3(x - a.x, y - a.y, z - a.z);
-}
-
 //-----------------------------------------------------------------------------
 inline Vector3& Vector3::operator-=(const Vector3& a)
 {
@@ -206,12 +278,6 @@ inline Vector3& Vector3::operator-=(const Vector3& a)
 	return *this;
 }
 
-//-----------------------------------------------------------------------------
-inline Vector3 Vector3::operator*(float k) const
-{
-	return Vector3(x * k, y * k, z * k);
-}
-
 //-----------------------------------------------------------------------------
 inline Vector3& Vector3::operator*=(float k)
 {
@@ -222,16 +288,6 @@ inline Vector3& Vector3::operator*=(float k)
 	return *this;
 }
 
-//-----------------------------------------------------------------------------
-inline Vector3 Vector3::operator/(float k) const
-{
-	CE_ASSERT(k != (float)0.0, "Division by zero");
-
-	float inv = (float)(1.0 / k);
-
-	return Vector3(x * inv, y * inv, z * inv);
-}
-
 //-----------------------------------------------------------------------------
 inline Vector3& Vector3::operator/=(float k)
 {
@@ -246,168 +302,4 @@ inline Vector3& Vector3::operator/=(float k)
 	return *this;
 }
 
-//-----------------------------------------------------------------------------
-inline float Vector3::dot(const Vector3& a) const
-{
-	return x * a.x + y * a.y + z * a.z;
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3 Vector3::cross(const Vector3& a) const
-{
-	return Vector3(y * a.z - z * a.y, z * a.x - x * a.z, x * a.y - y * a.x);
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3 operator*(float k, const Vector3& a)
-{
-	return a * k;
-}
-
-//-----------------------------------------------------------------------------
-inline bool Vector3::operator==(const Vector3& other) const
-{
-	return math::equals(x, other.x) && math::equals(y, other.y) && math::equals(z, other.z);
-}
-
-//-----------------------------------------------------------------------------
-inline bool Vector3::operator!=(const Vector3& other) const
-{
-	return !math::equals(x, other.x) || !math::equals(y, other.y) || !math::equals(z, other.z);
-}
-
-//-----------------------------------------------------------------------------
-inline bool Vector3::operator<(const Vector3& other) const
-{
-	return ((x < other.x) && (y < other.y) && (z < other.z));
-}
-
-//-----------------------------------------------------------------------------
-inline bool Vector3::operator>(const Vector3& other) const
-{
-	return ((x > other.x) && (y > other.y) && (z > other.z));
-}
-
-//-----------------------------------------------------------------------------
-inline float Vector3::length() const
-{
-	return math::sqrt(x * x + y * y + z * z);
-}
-
-//-----------------------------------------------------------------------------
-inline float Vector3::squared_length() const
-{
-	return x * x + y * y + z * z;
-}
-
-//-----------------------------------------------------------------------------
-inline void Vector3::set_length(float len)
-{
-	normalize();
-
-	x *= len;
-	y *= len;
-	z *= len;
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3& Vector3::normalize()
-{
-	float len = length();
-
-	if (math::equals(len, (float)0.0))
-	{
-		return *this;
-	}
-
-	len = (float)(1.0 / len); 
-
-	x *= len;
-	y *= len;
-	z *= len;
-
-	return *this;
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3 Vector3::get_normalized() const
-{
-	Vector3 tmp(x, y, z);
-
-	return tmp.normalize();
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3& Vector3::negate()
-{
-	x = -x;
-	y = -y;
-	z = -z;
-
-	return *this;
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3 Vector3::operator-() const
-{
-	return Vector3(-x, -y, -z);
-}
-
-//-----------------------------------------------------------------------------
-inline float Vector3::get_distance_to(const Vector3& a) const
-{
-	return (*this - a).length();
-}
-
-//-----------------------------------------------------------------------------
-inline float Vector3::get_angle_between(const Vector3& a) const
-{
-	return math::acos(this->dot(a) / (this->length() * a.length()));
-}
-
-//-----------------------------------------------------------------------------
-inline void Vector3::zero()
-{
-	x = 0.0;
-	y = 0.0;
-	z = 0.0;
-}
-
-//-----------------------------------------------------------------------------
-inline float* Vector3::to_float_ptr()
-{
-	return &x;
-}
-
-//-----------------------------------------------------------------------------
-inline const float* Vector3::to_float_ptr() const
-{
-	return &x;
-}
-
-//-----------------------------------------------------------------------------
-inline Vector2 Vector3::to_vec2() const
-{
-	return Vector2(x, y);
-}
-
-//-----------------------------------------------------------------------------
-/// Returns the parallel portion of "v" projected onto "n"
-inline Vector3 get_projected_parallel(const Vector3& v, const Vector3& n)
-{
-	float n_len_q;
-	n_len_q = n.length();
-	n_len_q = n_len_q * n_len_q;
-
-	return n * (v.dot(n) / n_len_q);
-}
-
-//-----------------------------------------------------------------------------
-/// Returns the perpendicular portion of "v" projected onto "n"
-inline Vector3 get_projected_perpendicular(const Vector3& v, const Vector3& n)
-{
-	return v - get_projected_parallel(v, n);
-}
-
 } // namespace crown
-

+ 2 - 2
engine/lua/LuaSystem.cpp

@@ -52,7 +52,7 @@ extern int vector3_multiply(lua_State* L);
 extern int vector3_divide(lua_State* L);
 extern int vector3_negate(lua_State* L);
 extern int vector2_new(lua_State* L);
-extern int vector3(lua_State* L);
+extern int vector3_new(lua_State* L);
 extern int matrix4x4(lua_State* L);
 extern int quaternion(lua_State* L);
 
@@ -67,7 +67,7 @@ static int crown_lua_vector2_call(lua_State* L)
 static int crown_lua_vector3_call(lua_State* L)
 {
 	lua_remove(L, 1);
-	return vector3(L);
+	return vector3_new(L);
 }
 
 //-----------------------------------------------------------------------------

+ 17 - 58
engine/lua/LuaVector3.cpp

@@ -32,7 +32,7 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-CE_EXPORT int vector3(lua_State* L)
+CE_EXPORT int vector3_new(lua_State* L)
 {
 	LuaStack stack(L);
 
@@ -188,7 +188,7 @@ CE_EXPORT int vector3_dot(lua_State* L)
 	Vector3& a = stack.get_vector3(1);
 	Vector3& b = stack.get_vector3(2);
 
-	stack.push_float(a.dot(b));
+	stack.push_float(vector3::dot(a, b));
 
 	return 1;
 }
@@ -201,7 +201,7 @@ CE_EXPORT int vector3_cross(lua_State* L)
 	Vector3& a = stack.get_vector3(1);
 	Vector3& b = stack.get_vector3(2);
 
-	stack.push_vector3(a.cross(b));
+	stack.push_vector3(vector3::cross(a, b));
 
 	return 1;
 }
@@ -219,32 +219,6 @@ CE_EXPORT int vector3_equal(lua_State* L)
 	return 1;
 }
 
-//-----------------------------------------------------------------------------
-CE_EXPORT int vector3_lower(lua_State* L)
-{
-	LuaStack stack(L);
-
-	Vector3& a = stack.get_vector3(1);
-	Vector3& b = stack.get_vector3(2);
-
-	stack.push_bool(a < b);
-
-	return 1;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int vector3_greater(lua_State* L)
-{
-	LuaStack stack(L);
-
-	Vector3& a = stack.get_vector3(1);
-	Vector3& b = stack.get_vector3(2);
-
-	stack.push_bool(a > b);
-
-	return 1;
-}
-
 //-----------------------------------------------------------------------------
 CE_EXPORT int vector3_length(lua_State* L)
 {
@@ -252,7 +226,7 @@ CE_EXPORT int vector3_length(lua_State* L)
 
 	Vector3& a = stack.get_vector3(1);
 
-	stack.push_float(a.length());
+	stack.push_float(vector3::length(a));
 
 	return 1;
 }
@@ -264,7 +238,7 @@ CE_EXPORT int vector3_squared_length(lua_State* L)
 
 	Vector3& a = stack.get_vector3(1);
 
-	stack.push_float(a.squared_length());
+	stack.push_float(vector3::squared_length(a));
 
 	return 1;
 }
@@ -277,7 +251,7 @@ CE_EXPORT int vector3_set_length(lua_State* L)
 	Vector3& a = stack.get_vector3(1);
 	float len = stack.get_float(2);
 
-	a.set_length(len);
+	vector3::set_length(a, len);
 
 	return 0;
 }
@@ -288,10 +262,10 @@ CE_EXPORT int vector3_normalize(lua_State* L)
 	LuaStack stack(L);
 
 	Vector3& a = stack.get_vector3(1);
+	
+	stack.push_vector3(vector3::normalize(a));
 
-	a.normalize();
-
-	return 0;
+	return 1;
 }
 
 //-----------------------------------------------------------------------------
@@ -301,53 +275,41 @@ CE_EXPORT int vector3_negate(lua_State* L)
 
 	Vector3& a = stack.get_vector3(1);
 
-	stack.push_vector3(a.negate());
+	stack.push_vector3(-a);
 
 	return 1;
 }
 
 //-----------------------------------------------------------------------------
-CE_EXPORT int vector3_get_distance_to(lua_State* L)
+CE_EXPORT int vector3_distance(lua_State* L)
 {
 	LuaStack stack(L);
 
 	Vector3& a = stack.get_vector3(1);
 	Vector3& b = stack.get_vector3(2);
 
-	stack.push_float(a.get_distance_to(b));
+	stack.push_float(vector3::distance(a, b));
 
 	return 1;
 }
 
 //-----------------------------------------------------------------------------
-CE_EXPORT int vector3_get_angle_between(lua_State* L)
+CE_EXPORT int vector3_angle(lua_State* L)
 {
 	LuaStack stack(L);
 
 	Vector3& a = stack.get_vector3(1);
 	Vector3& b = stack.get_vector3(2);
 
-	stack.push_float(a.get_angle_between(b));
+	stack.push_float(vector3::angle(a, b));
 
 	return 1;
 }
 
-//-----------------------------------------------------------------------------
-CE_EXPORT int vector3_zero(lua_State* L)
-{
-	LuaStack stack(L);
-
-	Vector3& a = stack.get_vector3(1);
-
-	a.zero();
-
-	return 0;
-}	
-
 //-----------------------------------------------------------------------------
 void load_vector3(LuaEnvironment& env)
 {
-	env.load_module_function("Vector3", "new", 				vector3);
+	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);
@@ -362,16 +324,13 @@ void load_vector3(LuaEnvironment& env)
 	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", "lower", 			vector3_lower);
-	env.load_module_function("Vector3", "greater", 			vector3_greater);
 	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", "negate", 			vector3_negate);
-	env.load_module_function("Vector3", "get_distance_to", 	vector3_get_distance_to);
-	env.load_module_function("Vector3", "get_angle_between",vector3_get_angle_between);
-	env.load_module_function("Vector3", "zero", 			vector3_zero);	
+	env.load_module_function("Vector3", "distance", 		vector3_distance);
+	env.load_module_function("Vector3", "angle",			vector3_angle);
 }
 
 } // namespace crown

+ 2 - 2
engine/lua/LuaWorld.cpp

@@ -41,7 +41,7 @@ CE_EXPORT int world_spawn_unit(lua_State* L)
 	World* world = stack.get_world(1);
 	const char* name = stack.get_string(2);
 
-	const Vector3& pos = stack.num_args() > 2 ? stack.get_vector3(3) : Vector3::ZERO;
+	const Vector3& pos = stack.num_args() > 2 ? stack.get_vector3(3) : vector3::ZERO;
 	const Quaternion& rot = stack.num_args() > 3 ? stack.get_quaternion(4) : Quaternion::IDENTITY;
 
 	UnitId unit = world->spawn_unit(name, pos, rot);
@@ -83,7 +83,7 @@ CE_EXPORT int world_play_sound(lua_State* L)
 
 	const bool loop = stack.num_args() > 2 ? stack.get_bool(3) : false;
 	const float volume = stack.num_args() > 3 ? stack.get_float(4) : 1.0f;
-	const Vector3& pos = stack.num_args() > 4 ? stack.get_vector3(5) : Vector3::ZERO;
+	const Vector3& pos = stack.num_args() > 4 ? stack.get_vector3(5) : vector3::ZERO;
 	const float range = stack.num_args() > 5 ? stack.get_float(6) : 1000.0f;
 
 	SoundInstanceId id = world->play_sound(name, loop, volume, pos, range);

+ 1 - 1
engine/physics/PhysicsWorld.cpp

@@ -262,7 +262,7 @@ PhysicsWorld::~PhysicsWorld()
 ActorId	PhysicsWorld::create_actor(const PhysicsResource* res, const uint32_t index, SceneGraph& sg, int32_t node, Unit* unit)
 {
 	PhysicsConfigResource* config = (PhysicsConfigResource*) device()->resource_manager()->lookup("physics_config", "global");
-	Actor* actor = CE_NEW(m_actors_pool, Actor)(res, config, index, physics_system::s_physics, physics_system::s_cooking, m_scene, sg, node, unit, Vector3::ZERO, Quaternion::IDENTITY);
+	Actor* actor = CE_NEW(m_actors_pool, Actor)(res, config, index, physics_system::s_physics, physics_system::s_cooking, m_scene, sg, node, unit, vector3::ZERO, Quaternion::IDENTITY);
 	return m_actors.create(actor);
 }
 

+ 2 - 2
engine/world/World.h

@@ -62,7 +62,7 @@ public:
 	WorldId								id() const;
 	void								set_id(WorldId id);
 
-	UnitId								spawn_unit(const char* name, const Vector3& pos = Vector3::ZERO, const Quaternion& rot = Quaternion::IDENTITY);
+	UnitId								spawn_unit(const char* name, const Vector3& pos = vector3::ZERO, const Quaternion& rot = Quaternion::IDENTITY);
 	UnitId								spawn_unit(const char* name, UnitResource* ur, const Vector3& pos, const Quaternion& rot);
 	void								destroy_unit(UnitId id);
 	void								reload_units(UnitResource* old_ur, UnitResource* new_ur);
@@ -81,7 +81,7 @@ public:
 	CameraId							create_camera(SceneGraph& sg, int32_t node);
 	void								destroy_camera(CameraId id);
 
-	SoundInstanceId						play_sound(const char* name, bool loop = false, float volume = 1.0f, const Vector3& pos = Vector3::ZERO, float range = 50.0f);
+	SoundInstanceId						play_sound(const char* name, bool loop = false, float volume = 1.0f, const Vector3& pos = vector3::ZERO, float range = 50.0f);
 	void								stop_sound(SoundInstanceId sound);
 	void								link_sound(SoundInstanceId sound, Unit* unit, int32_t node);
 	void								set_listener_pose(const Matrix4x4& pose);