Просмотр исходного кода

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

Daniele Bartolini 10 лет назад
Родитель
Сommit
08cb35a48d

+ 26 - 1
README.md

@@ -98,7 +98,7 @@ A number of tools can be found at https://github.com/taylor001/crown-tools
 Contact
 -------
 
-[@aa_dani_bart](https://twitter.com/aa_dani_bart)
+Daniele Bartolini ([@aa_dani_bart](https://twitter.com/aa_dani_bart))
 
 Contributors
 ------------
@@ -108,3 +108,28 @@ In alphabetical order.
 Michele Rossi ([@mikymod](https://github.com/mikymod))  
 Simone Boscaratto ([@Xed89](https://github.com/Xed89))
 
+License
+-------
+
+	Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
+
+	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.

+ 1 - 1
docs/Doxyfile.doxygen

@@ -763,7 +763,7 @@ WARN_LOGFILE           =
 # spaces.
 # Note: If this tag is empty the current directory is searched.
 
-INPUT                  = engine
+INPUT                  = src
 
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

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

@@ -5,12 +5,10 @@
 
 #pragma once
 
-#include "error.h"
 #include "math_types.h"
+#include "vector3.h"
 #include "matrix4x4.h"
 #include "sphere.h"
-#include "types.h"
-#include "vector3.h"
 
 namespace crown
 {

+ 78 - 92
src/core/math/color4.h

@@ -9,30 +9,95 @@
 
 namespace crown
 {
+/// @addtogroup Math
+/// @{
 
 /// Holds RGBA color as four floats.
-///
-/// @ingroup Math
 typedef Vector4 Color4;
 
-/// Functions to mamipulate Color4
-///
-/// @ingroup Math
-Color4 from_rgb(int r, int g, int b);
-Color4 from_rgba(int r, int g, int b, int a);
-Color4 from_rgba(uint32_t rgba);
+inline Color4 color4(float r, float g, float b, float a)
+{
+	Color4 c;
+	c.x = r;
+	c.y = g;
+	c.z = b;
+	c.w = a;
+	return c;
+}
+
+inline Color4 from_rgb(int r, int g, int b)
+{
+	Color4 c;
+	c.x = 1.0f/255.0f * r;
+	c.y = 1.0f/255.0f * g;
+	c.z = 1.0f/255.0f * b;
+	c.w = 1.0f;
+	return c;
+}
+
+inline Color4 from_rgba(int r, int g, int b, int a)
+{
+	Color4 c;
+	c.x = 1.0f/255.0f * r;
+	c.y = 1.0f/255.0f * g;
+	c.z = 1.0f/255.0f * b;
+	c.w = 1.0f/255.0f * a;
+	return c;
+}
+
+inline Color4 from_rgba(uint32_t rgba)
+{
+	Color4 c;
+	c.x = 1.0f/255.0f * ((rgba & 0xff000000) >> 24);
+	c.y = 1.0f/255.0f * ((rgba & 0x00ff0000) >> 16);
+	c.z = 1.0f/255.0f * ((rgba & 0x0000ff00) >> 8);
+	c.w = 1.0f/255.0f * ((rgba & 0x000000ff) >> 0);
+	return c;
+}
 
 /// Returns the color as a packed 32-bit integer. (RGBA order, alpha assumed = 255)
-uint32_t to_rgb(const Color4& c);
+inline uint32_t to_rgb(const Color4& c)
+{
+	uint32_t rgba;
+	rgba =	(uint32_t)(255.0f * c.x) << 24;
+	rgba |= (uint32_t)(255.0f * c.y) << 16;
+	rgba |= (uint32_t)(255.0f * c.z) << 8;
+	rgba |= 255;
+	return rgba;
+}
 
 /// Returns the color as a packed 32-bit integer. (ABGR order, alpha assumed = 255)
-uint32_t to_bgr(const Color4& c);
+inline uint32_t to_bgr(const Color4& c)
+{
+	uint32_t abgr;
+	abgr =	255 << 24;
+	abgr |= (uint32_t)(255.0f * c.z) << 16;
+	abgr |= (uint32_t)(255.0f * c.y) << 8;
+	abgr |= (uint32_t)(255.0f * c.x);
+	return abgr;
+}
 
 /// Returns the color as a packed 32-bit integer. (RGBA order)
-uint32_t to_rgba(const Color4& c);
+inline uint32_t to_rgba(const Color4& c)
+{
+	uint32_t rgba;
+	rgba =	(uint32_t)(255.0f * c.x) << 24;
+	rgba |= (uint32_t)(255.0f * c.y) << 16;
+	rgba |= (uint32_t)(255.0f * c.z) << 8;
+	rgba |= (uint32_t)(255.0f * c.w);
+	return rgba;
+}
 
 /// Returns the color as a packed 32-bit integer. (ABGR order)
-uint32_t to_abgr(const Color4& c);
+inline uint32_t to_abgr(const Color4& c)
+{
+	uint32_t abgr;
+	abgr =	(uint32_t)(255.0f * c.w) << 24;
+	abgr |= (uint32_t)(255.0f * c.z) << 16;
+	abgr |= (uint32_t)(255.0f * c.y) << 8;
+	abgr |= (uint32_t)(255.0f * c.x);
+	return abgr;
+}
 
 // SVG 1.0 color names
 const Color4 COLOR4_ALICEBLUE            = from_rgba(0xf0f8ffff);
@@ -183,84 +248,5 @@ const Color4 COLOR4_WHITESMOKE           = from_rgba(0xf5f5f5ff);
 const Color4 COLOR4_YELLOW               = from_rgba(0xffff00ff);
 const Color4 COLOR4_YELLOWGREEN          = from_rgba(0x9acd32ff);
 
-inline Color4 color4(float r, float g, float b, float a)
-{
-	Color4 c;
-	c.x = r;
-	c.y = g;
-	c.z = b;
-	c.w = a;
-	return c;
-}
-
-inline Color4 from_rgb(int r, int g, int b)
-{
-	Color4 c;
-	c.x = 1.0f/255.0f * r;
-	c.y = 1.0f/255.0f * g;
-	c.z = 1.0f/255.0f * b;
-	c.w = 1.0f;
-	return c;
-}
-
-inline Color4 from_rgba(int r, int g, int b, int a)
-{
-	Color4 c;
-	c.x = 1.0f/255.0f * r;
-	c.y = 1.0f/255.0f * g;
-	c.z = 1.0f/255.0f * b;
-	c.w = 1.0f/255.0f * a;
-	return c;
-}
-
-inline Color4 from_rgba(uint32_t rgba)
-{
-	Color4 c;
-	c.x = 1.0f/255.0f * ((rgba & 0xff000000) >> 24);
-	c.y = 1.0f/255.0f * ((rgba & 0x00ff0000) >> 16);
-	c.z = 1.0f/255.0f * ((rgba & 0x0000ff00) >> 8);
-	c.w = 1.0f/255.0f * ((rgba & 0x000000ff) >> 0);
-	return c;
-}
-
-inline uint32_t to_rgb(const Color4& c)
-{
-	uint32_t rgba;
-	rgba =	(uint32_t)(255.0f * c.x) << 24;
-	rgba |= (uint32_t)(255.0f * c.y) << 16;
-	rgba |= (uint32_t)(255.0f * c.z) << 8;
-	rgba |= 255;
-	return rgba;
-}
-
-inline uint32_t to_bgr(const Color4& c)
-{
-	uint32_t abgr;
-	abgr =	255 << 24;
-	abgr |= (uint32_t)(255.0f * c.z) << 16;
-	abgr |= (uint32_t)(255.0f * c.y) << 8;
-	abgr |= (uint32_t)(255.0f * c.x);
-	return abgr;
-}
-
-inline uint32_t to_rgba(const Color4& c)
-{
-	uint32_t rgba;
-	rgba =	(uint32_t)(255.0f * c.x) << 24;
-	rgba |= (uint32_t)(255.0f * c.y) << 16;
-	rgba |= (uint32_t)(255.0f * c.z) << 8;
-	rgba |= (uint32_t)(255.0f * c.w);
-	return rgba;
-}
-
-inline uint32_t to_abgr(const Color4& c)
-{
-	uint32_t abgr;
-	abgr =	(uint32_t)(255.0f * c.w) << 24;
-	abgr |= (uint32_t)(255.0f * c.z) << 16;
-	abgr |= (uint32_t)(255.0f * c.y) << 8;
-	abgr |= (uint32_t)(255.0f * c.x);
-	return abgr;
-}
-
+/// @}
 } // namespace crown

+ 0 - 1
src/core/math/frustum.h

@@ -5,7 +5,6 @@
 
 #pragma once
 
-#include "types.h"
 #include "math_types.h"
 #include "vector3.h"
 #include "plane.h"

+ 0 - 1
src/core/math/intersection.h

@@ -6,7 +6,6 @@
 #pragma once
 
 #include "math_types.h"
-#include "sphere.h"
 
 namespace crown
 {

+ 4 - 0
src/core/math/math_utils.h

@@ -12,6 +12,8 @@
 namespace crown
 {
 
+/// @addtogroup Math
+/// @{
 const float PI = 3.1415926535897932f;
 const float TWO_PI = PI * 2.0f;
 const float HALF_PI = PI * 0.5f;
@@ -203,4 +205,6 @@ inline T catmull_rom(const T& p0, const T& p1, const T& p2, const T& p3, float t
 	return tmp * 0.5;
 }
 
+/// @}
+
 } // namespace crown

+ 37 - 18
src/core/math/matrix3x3.h

@@ -7,16 +7,14 @@
 
 #include "math_types.h"
 #include "vector3.h"
-#include "error.h"
 #include "quaternion.h"
 
 namespace crown
 {
+/// @addtogroup Math
+/// @{
 
-/// Functions to manipulate Matrix3x3
-///
-/// @ingroup Math
-const Matrix3x3 IDENTITY = { {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0} };
+const Matrix3x3 MATRIX3X3_IDENTITY = { {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f} };
 
 inline Matrix3x3 matrix3x3(const Vector3& x, const Vector3& y, const Vector3& z)
 {
@@ -30,9 +28,17 @@ inline Matrix3x3 matrix3x3(const Vector3& x, const Vector3& y, const Vector3& z)
 inline Matrix3x3 matrix3x3(const Quaternion& r)
 {
 	Matrix3x3 m;
-	m.x = vector3(1.0f - 2.0f * r.y * r.y - 2.0f * r.z * r.z, 2.0f * r.x * r.y + 2.0f * r.w * r.z, 2.0f * r.x * r.z - 2.0f * r.w * r.y);
-	m.y = vector3(2.0f * r.x * r.y - 2.0f * r.w * r.z, 1.0f - 2.0f * r.x * r.x - 2.0f * r.z * r.z, 2.0f * r.y * r.z + 2.0f * r.w * r.x);
-	m.z = vector3(2.0f * r.x * r.z + 2.0f * r.w * r.y, 2.0f * r.y * r.z - 2.0f * r.w * r.x, 1.0f - 2.0f * r.x * r.x - 2.0f * r.y * r.y);
+	m.x.x = 1.0f - 2.0f * r.y * r.y - 2.0f * r.z * r.z;
+	m.x.y = 2.0f * r.x * r.y + 2.0f * r.w * r.z;
+	m.x.z = 2.0f * r.x * r.z - 2.0f * r.w * r.y;
+
+	m.y.x = 2.0f * r.x * r.y - 2.0f * r.w * r.z;
+	m.y.y = 1.0f - 2.0f * r.x * r.x - 2.0f * r.z * r.z;
+	m.y.z = 2.0f * r.y * r.z + 2.0f * r.w * r.x;
+
+	m.z.x = 2.0f * r.x * r.z + 2.0f * r.w * r.y;
+	m.z.y = 2.0f * r.y * r.z - 2.0f * r.w * r.x;
+	m.z.z = 1.0f - 2.0f * r.x * r.x - 2.0f * r.y * r.y;
 	return m;
 }
 
@@ -109,7 +115,7 @@ inline Matrix3x3 operator*(Matrix3x3 a, float k)
 	return a;
 }
 
-/// @copydoc operator*(Matrix3x3, float)
+/// Multiplies the matrix @a a by the scalar @a k and returns the result.
 inline Matrix3x3 operator*(float k, Matrix3x3 a)
 {
 	a *= k;
@@ -126,11 +132,11 @@ inline Matrix3x3 operator/(Matrix3x3 a, float k)
 /// Multiplies the matrix @a a by the vector @a v and returns the result.
 inline Vector3 operator*(const Vector3& v, const Matrix3x3& a)
 {
-	return vector3(
-		v.x*a.x.x + v.y*a.y.x + v.z*a.z.x,
-		v.x*a.x.y + v.y*a.y.y + v.z*a.z.y,
-		v.x*a.x.z + v.y*a.y.z + v.z*a.z.z
-	);
+	Vector3 res;
+	res.x = v.x*a.x.x + v.y*a.y.x + v.z*a.z.x;
+	res.y = v.x*a.x.y + v.y*a.y.y + v.z*a.z.y;
+	res.z = v.x*a.x.z + v.y*a.y.z + v.z*a.z.z;
+	return res;
 }
 
 /// Multiplies the matrix @a a by @a b and returns the result. (i.e. transforms first by @a a then by @a b)
@@ -216,9 +222,17 @@ inline Matrix3x3 get_inverted(Matrix3x3 m)
 /// Sets the matrix @a m to identity.
 inline void set_identity(Matrix3x3& m)
 {
-	m.x = vector3(1, 0, 0);
-	m.y = vector3(0, 1, 0);
-	m.z = vector3(0, 0, 1);
+	m.x.x = 1.0f;
+	m.x.y = 0.0f;
+	m.x.z = 0.0f;
+
+	m.y.x = 0.0f;
+	m.y.y = 1.0f;
+	m.y.z = 0.0f;
+
+	m.z.x = 0.0f;
+	m.z.y = 0.0f;
+	m.z.z = 1.0f;
 }
 
 /// Returns the rotation portion of the matrix @a m as a Quaternion.
@@ -304,7 +318,11 @@ inline Vector3 scale(const Matrix3x3& m)
 	const float sx = length(m.x);
 	const float sy = length(m.y);
 	const float sz = length(m.z);
-	return vector3(sx, sy, sz);
+	Vector3 res;
+	res.x = sx;
+	res.y = sy;
+	res.z = sz;
+	return res;
 }
 
 /// Sets the scale of the matrix @a m.
@@ -327,4 +345,5 @@ inline const float* to_float_ptr(const Matrix3x3& m)
 	return &m.x.x;
 }
 
+/// @}
 } // namespace crown

+ 127 - 57
src/core/math/matrix4x4.h

@@ -6,18 +6,16 @@
 #pragma once
 
 #include "math_types.h"
-#include "matrix3x3.h"
-#include "quaternion.h"
 #include "vector4.h"
-#include "types.h"
+#include "quaternion.h"
+#include "matrix3x3.h"
 
 namespace crown
 {
+/// @addtogroup Math
+/// @{
 
-/// Functions to manipulate Matrix4x4.
-///
-/// @ingroup Math
-const Matrix4x4 MATRIX4X4_IDENTITY = { {1.0, 0.0, 0.0, 0.0 }, {0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0 } };
+const Matrix4x4 MATRIX4X4_IDENTITY = { {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 1.0f} };
 
 inline Matrix4x4 matrix4x4(float r1c1, float r2c1, float r3c1, float r4c1,
 	float r1c2, float r2c2, float r3c2, float r4c2,
@@ -75,30 +73,75 @@ inline Matrix4x4 matrix4x4(const float a[16])
 inline Matrix4x4 matrix4x4(const Vector3& x, const Vector3& y, const Vector3& z, const Vector3& t)
 {
 	Matrix4x4 m;
-	m.x = vector4(x, 0.0f);
-	m.y = vector4(y, 0.0f);
-	m.z = vector4(z, 0.0f);
-	m.t = vector4(t, 1.0f);
+	m.x.x = x.x;
+	m.x.y = x.y;
+	m.x.z = x.z;
+	m.x.w = 0.0f;
+
+	m.y.x = y.x;
+	m.y.y = y.y;
+	m.y.z = y.z;
+	m.y.w = 0.0f;
+
+	m.z.x = z.x;
+	m.z.y = z.y;
+	m.z.z = z.z;
+	m.z.w = 0.0f;
+
+	m.t.x = t.x;
+	m.t.y = t.y;
+	m.t.z = t.z;
+	m.t.w = 1.0f;
 	return m;
 }
 
 inline Matrix4x4 matrix4x4(const Quaternion& r, const Vector3& p)
 {
 	Matrix4x4 m;
-	m.x = vector4(1.0f - 2.0f * r.y * r.y - 2.0f * r.z * r.z, 2.0f * r.x * r.y + 2.0f * r.w * r.z, 2.0f * r.x * r.z - 2.0f * r.w * r.y, 0);
-	m.y = vector4(2.0f * r.x * r.y - 2.0f * r.w * r.z, 1.0f - 2.0f * r.x * r.x - 2.0f * r.z * r.z, 2.0f * r.y * r.z + 2.0f * r.w * r.x, 0);
-	m.z = vector4(2.0f * r.x * r.z + 2.0f * r.w * r.y, 2.0f * r.y * r.z - 2.0f * r.w * r.x, 1.0f - 2.0f * r.x * r.x - 2.0f * r.y * r.y, 0);
-	m.t = vector4(p, 1.0f);
+	m.x.x = 1.0f - 2.0f * r.y * r.y - 2.0f * r.z * r.z;
+	m.x.y = 2.0f * r.x * r.y + 2.0f * r.w * r.z;
+	m.x.z = 2.0f * r.x * r.z - 2.0f * r.w * r.y;
+	m.x.w = 0.0f;
+
+	m.y.x = 2.0f * r.x * r.y - 2.0f * r.w * r.z;
+	m.y.y = 1.0f - 2.0f * r.x * r.x - 2.0f * r.z * r.z;
+	m.y.z = 2.0f * r.y * r.z + 2.0f * r.w * r.x;
+	m.y.w = 0.0f;
+
+	m.z.x = 2.0f * r.x * r.z + 2.0f * r.w * r.y;
+	m.z.y = 2.0f * r.y * r.z - 2.0f * r.w * r.x;
+	m.z.z = 1.0f - 2.0f * r.x * r.x - 2.0f * r.y * r.y;
+	m.z.w = 0.0f;
+
+	m.t.x = p.x;
+	m.t.y = p.y;
+	m.t.z = p.z;
+	m.t.w = 1.0f;
 	return m;
 }
 
 inline Matrix4x4 matrix4x4(const Matrix3x3& rot)
 {
 	Matrix4x4 m;
-	m.x = vector4(rot.x, 0.0f);
-	m.y = vector4(rot.y, 0.0f);
-	m.z = vector4(rot.z, 0.0f);
-	m.t = vector4(0.0f, 0.0f, 0.0f, 1.0f);
+	m.x.x = rot.x.x;
+	m.x.y = rot.x.y;
+	m.x.z = rot.x.z;
+	m.x.w = 0.0f;
+
+	m.y.x = rot.y.x;
+	m.y.y = rot.y.y;
+	m.y.z = rot.y.z;
+	m.y.w = 0.0f;
+
+	m.z.x = rot.z.x;
+	m.z.y = rot.z.y;
+	m.z.z = rot.z.z;
+	m.z.w = 0.0f;
+
+	m.t.x = 0.0f;
+	m.t.y = 0.0f;
+	m.t.z = 0.0f;
+	m.t.w = 1.0f;
 	return m;
 }
 
@@ -188,7 +231,7 @@ inline Matrix4x4 operator*(Matrix4x4 a, float k)
 	return a;
 }
 
-/// @copydoc operator*(Matrix4x4, float)
+/// Multiplies the matrix @a a by the scalar @a k and returns the result.
 inline Matrix4x4 operator*(float k, Matrix4x4 a)
 {
 	a *= k;
@@ -205,22 +248,22 @@ inline Matrix4x4 operator/(Matrix4x4 a, float k)
 /// Multiplies the matrix @a a by the vector @a v and returns the result.
 inline Vector3 operator*(const Vector3& v, const Matrix4x4& a)
 {
-	return vector3(
-		v.x*a.x.x + v.y*a.y.x + v.z*a.z.x + a.t.x,
-		v.x*a.x.y + v.y*a.y.y + v.z*a.z.y + a.t.y,
-		v.x*a.x.z + v.y*a.y.z + v.z*a.z.z + a.t.z
-	);
+	Vector3 res;
+	res.x = v.x*a.x.x + v.y*a.y.x + v.z*a.z.x + a.t.x;
+	res.y = v.x*a.x.y + v.y*a.y.y + v.z*a.z.y + a.t.y;
+	res.z = v.x*a.x.z + v.y*a.y.z + v.z*a.z.z + a.t.z;
+	return res;
 }
 
 /// Multiplies the matrix @a by the vector @a v and returns the result.
 inline Vector4 operator*(const Vector4& v, const Matrix4x4& a)
 {
-	return vector4(
-		v.x*a.x.x + v.y*a.y.x + v.z*a.z.x + v.w*a.t.x,
-		v.x*a.x.y + v.y*a.y.y + v.z*a.z.y + v.w*a.t.y,
-		v.x*a.x.z + v.y*a.y.z + v.z*a.z.z + v.w*a.t.z,
-		v.x*a.x.w + v.y*a.y.w + v.z*a.z.w + v.w*a.t.w
-	);
+	Vector4 res;
+	res.x = v.x*a.x.x + v.y*a.y.x + v.z*a.z.x + v.w*a.t.x;
+	res.y = v.x*a.x.y + v.y*a.y.y + v.z*a.z.y + v.w*a.t.y;
+	res.z = v.x*a.x.z + v.y*a.y.z + v.z*a.z.z + v.w*a.t.z;
+	res.w = v.x*a.x.w + v.y*a.y.w + v.z*a.z.w + v.w*a.t.w;
+	return res;
 }
 
 /// Multiplies the matrix @a a by @a b and returns the result. (i.e. transforms first by @a a then by @a b)
@@ -325,30 +368,30 @@ inline Matrix4x4 get_transposed(Matrix4x4 m)
 /// Sets the matrix @a m to look.
 inline void set_look(Matrix4x4& m, const Vector3& pos, const Vector3& target, const Vector3& up)
 {
-	Vector3 zAxis = pos - target;
-	normalize(zAxis);
-	const Vector3 xAxis = cross(up, zAxis);
-	const Vector3 yAxis = cross(zAxis, xAxis);
+	Vector3 zaxis = pos - target;
+	normalize(zaxis);
+	const Vector3 xaxis = cross(up, zaxis);
+	const Vector3 yaxis = cross(zaxis, xaxis);
 
-	m.x.x= xAxis.x;
-	m.x.y= yAxis.x;
-	m.x.z= zAxis.x;
-	m.x.w= 0;
+	m.x.x = xaxis.x;
+	m.x.y = yaxis.x;
+	m.x.z = zaxis.x;
+	m.x.w = 0.0f;
 
-	m.y.x= xAxis.y;
-	m.y.y= yAxis.y;
-	m.y.z= zAxis.y;
-	m.y.w= 0;
+	m.y.x = xaxis.y;
+	m.y.y = yaxis.y;
+	m.y.z = zaxis.y;
+	m.y.w = 0.0f;
 
-	m.z.x= xAxis.z;
-	m.z.y= yAxis.z;
-	m.z.z= zAxis.z;
-	m.z.w= 0;
+	m.z.x = xaxis.z;
+	m.z.y = yaxis.z;
+	m.z.z = zaxis.z;
+	m.z.w = 0.0f;
 
-	m.t.x= -dot(pos, xAxis);
-	m.t.y= -dot(pos, yAxis);
-	m.t.z= -dot(pos, zAxis);
-	m.t.w= 1;
+	m.t.x = -dot(pos, xaxis);
+	m.t.y = -dot(pos, yaxis);
+	m.t.z = -dot(pos, zaxis);
+	m.t.w = 1.0f;
 }
 
 /// Returns the determinant of the matrix @a m.
@@ -441,10 +484,25 @@ inline Matrix4x4 get_inverted(Matrix4x4 m)
 /// Sets the matrix @a m to identity.
 inline void set_identity(Matrix4x4& m)
 {
-	m.x = vector4(1, 0, 0, 0);
-	m.y = vector4(0, 1, 0, 0);
-	m.z = vector4(0, 0, 1, 0);
-	m.t = vector4(0, 0, 0, 1);
+	m.x.x = 1.0f;
+	m.x.y = 0.0f;
+	m.x.z = 0.0f;
+	m.x.w = 0.0f;
+
+	m.y.x = 0.0f;
+	m.y.y = 1.0f;
+	m.y.z = 0.0f;
+	m.y.w = 0.0f;
+
+	m.z.x = 0.0f;
+	m.z.y = 0.0f;
+	m.z.z = 1.0f;
+	m.z.w = 0.0f;
+
+	m.t.x = 0.0f;
+	m.t.y = 0.0f;
+	m.t.z = 0.0f;
+	m.t.w = 1.0f;
 }
 
 /// Returns the x asis of the matrix @a m.
@@ -503,11 +561,22 @@ inline void set_translation(Matrix4x4& m, const Vector3& trans)
 	m.t.z = trans.z;
 }
 
-
 /// Returns the rotation portion of the matrix @a m as a Matrix3x3.
 inline Matrix3x3 to_matrix3x3(const Matrix4x4& m)
 {
-	return matrix3x3(x(m), y(m), z(m));
+	Matrix3x3 res;
+	res.x.x = m.x.x;
+	res.x.y = m.x.y;
+	res.x.z = m.x.z;
+
+	res.y.x = m.y.x;
+	res.y.y = m.y.y;
+	res.y.z = m.y.z;
+
+	res.z.x = m.z.x;
+	res.z.y = m.z.y;
+	res.z.z = m.z.z;
+	return res;
 }
 
 /// Returns the rotation portion of the matrix @a m as a Quaternion.
@@ -565,4 +634,5 @@ inline const float* to_float_ptr(const Matrix4x4& m)
 	return to_float_ptr(m.x);
 }
 
+/// @}
 } // namespace crown

+ 5 - 10
src/core/math/plane.h

@@ -11,6 +11,11 @@
 namespace crown
 {
 
+const Plane PLANE_ZERO  = { VECTOR3_ZERO, 0.0f };
+const Plane PLANE_XAXIS = { VECTOR3_XAXIS, 0.0f };
+const Plane PLANE_YAXIS = { VECTOR3_YAXIS, 0.0f };
+const Plane PLANE_ZAXIS = { VECTOR3_ZAXIS, 0.0f };
+
 /// Functions to manipulate Plane.
 ///
 /// @ingroup Math
@@ -26,16 +31,6 @@ namespace plane
 
 namespace plane
 {
-	// const Plane ZERO = Plane(vector3::ZERO, 0.0f);
-	// const Plane XAXIS = Plane(vector3::XAXIS, 0.0f);
-	// const Plane YAXIS = Plane(vector3::YAXIS, 0.0f);
-	// const Plane ZAXIS = Plane(vector3::ZAXIS, 0.0f);
-
-	const Plane ZERO  = { VECTOR3_ZERO, 0.0f };
-	const Plane XAXIS = { VECTOR3_XAXIS, 0.0f };
-	const Plane YAXIS = { VECTOR3_YAXIS, 0.0f };
-	const Plane ZAXIS = { VECTOR3_ZAXIS, 0.0f };
-
 	inline Plane& normalize(Plane& p)
 	{
 		const float len = length(p.n);

+ 25 - 10
src/core/math/quaternion.h

@@ -11,11 +11,10 @@
 
 namespace crown
 {
+/// @addtogroup Math
+/// @{
 
-/// Functions to manipulate Quaternion.
-///
-/// @ingroup Math
-const Quaternion QUATERNION_IDENTITY = { 0.0, 0.0, 0.0, 1.0 };
+const Quaternion QUATERNION_IDENTITY = { 0.0f, 0.0f, 0.0f, 1.0f };
 
 inline Quaternion quaternion(float x, float y, float z, float w)
 {
@@ -53,7 +52,12 @@ inline Quaternion& operator*=(Quaternion& a, const Quaternion& b)
 /// Negates the quaternion @a q and returns the result.
 inline Quaternion operator-(const Quaternion& q)
 {
-	return quaternion(-q.x, -q.y, -q.z, -q.w);
+	Quaternion res;
+	res.x = -q.x;
+	res.y = -q.y;
+	res.z = -q.z;
+	res.w = -q.w;
+	return res;
 }
 
 /// Multiplies the quaternions @a a and @a b. (i.e. rotates first by @a a then by @a b).
@@ -64,9 +68,14 @@ inline Quaternion operator*(Quaternion a, const Quaternion& b)
 }
 
 /// Multiplies the quaternion @a a by the scalar @a k.
-inline Quaternion operator*(const Quaternion& a, float k)
+inline Quaternion operator*(const Quaternion& q, float k)
 {
-	return quaternion(a.x * k, a.y * k, a.z * k, a.w * k);
+	Quaternion res;
+	res.x = q.x * k;
+	res.y = q.y * k;
+	res.z = q.z * k;
+	res.w = q.w * k;
+	return res;
 }
 
 /// Returns the dot product between quaternions @a a and @a b.
@@ -95,7 +104,12 @@ inline Quaternion& normalize(Quaternion& q)
 /// Returns the conjugate of quaternion @a q.
 inline Quaternion conjugate(const Quaternion& q)
 {
-	return quaternion(-q.x, -q.y, -q.z, q.w);
+	Quaternion res;
+	res.x = -q.x;
+	res.y = -q.y;
+	res.z = -q.z;
+	res.w = q.w;
+	return res;
 }
 
 /// Returns the inverse of quaternion @a q.
@@ -109,11 +123,11 @@ inline Quaternion power(const Quaternion& q, float exp)
 {
 	if (abs(q.w) < 0.9999)
 	{
-		Quaternion tmp;
 		float alpha = acos(q.w); // alpha = theta/2
 		float new_alpha = alpha * exp;
-		tmp.w = cos(new_alpha);
 		float mult = sin(new_alpha) / sin(alpha);
+		Quaternion tmp;
+		tmp.w = cos(new_alpha);
 		tmp.x = q.x * mult;
 		tmp.y = q.y * mult;
 		tmp.z = q.z * mult;
@@ -123,4 +137,5 @@ inline Quaternion power(const Quaternion& q, float exp)
 	return q;
 }
 
+// @}
 } // namespace crown

+ 1 - 2
src/core/math/sphere.h

@@ -5,9 +5,8 @@
 
 #pragma once
 
-#include "types.h"
-#include "math_utils.h"
 #include "math_types.h"
+#include "math_utils.h"
 #include "vector3.h"
 
 namespace crown

+ 12 - 11
src/core/math/vector2.h

@@ -5,17 +5,15 @@
 
 #pragma once
 
-#include "error.h"
-#include "types.h"
-#include "math_utils.h"
 #include "math_types.h"
+#include "math_utils.h"
+#include "error.h"
 
 namespace crown
 {
+/// @addtogroup Math
+/// @{
 
-/// Functions to manipulate Vector2.
-///
-/// @ingroup Math
 const Vector2 VECTOR2_ZERO = { 0.0f, 0.0f };
 
 inline Vector2 vector2(float x, float y)
@@ -49,7 +47,7 @@ inline Vector2& operator*=(Vector2& a, float k)
 
 inline Vector2& operator/=(Vector2& a, float k)
 {
-	CE_ASSERT(k != (float)0.0, "Division by zero");
+	CE_ASSERT(k != 0.0f, "Division by zero");
 	float inv = 1.0f / k;
 	a.x *= inv;
 	a.y *= inv;
@@ -59,7 +57,10 @@ inline Vector2& operator/=(Vector2& a, float k)
 /// Negates @a a and returns the result.
 inline Vector2 operator-(const Vector2& a)
 {
-	return vector2(-a.x, -a.y);
+	Vector2 res;
+	res.x = -a.x;
+	res.y = -a.y;
+	return res;
 }
 
 /// Adds the vector @a a to @a b and returns the result.
@@ -83,7 +84,7 @@ inline Vector2 operator*(Vector2 a, float k)
 	return a;
 }
 
-/// @copydoc operator*(Vector2, float)
+/// Multiplies the vector @a a by the scalar @a k and returns the result.
 inline Vector2 operator*(float k, Vector2 a)
 {
 	a *= k;
@@ -134,7 +135,6 @@ inline Vector2 normalize(Vector2& a)
 inline void set_length(Vector2& a, float len)
 {
 	normalize(a);
-
 	a.x *= len;
 	a.y *= len;
 }
@@ -157,10 +157,11 @@ inline float* to_float_ptr(Vector2& a)
 	return &a.x;
 }
 
-/// @copydoc to_float_ptr(Vector2&)
+/// Returns the pointer to the data of @a a.
 inline const float* to_float_ptr(const Vector2& a)
 {
 	return &a.x;
 }
 
+/// @}
 } // namespace crown

+ 24 - 24
src/core/math/vector3.h

@@ -5,31 +5,26 @@
 
 #pragma once
 
-#include "error.h"
-#include "types.h"
+#include "math_types.h"
 #include "math_utils.h"
 #include "vector2.h"
-#include "math_types.h"
+#include "error.h"
 
 namespace crown
 {
+/// @addtogroup Math
+/// @{
 
-/// Functions to manipulate Vector3.
-///
-/// @ingroup Math
-const Vector3 VECTOR3_ZERO     = { 0, 0, 0 };
-const Vector3 VECTOR3_XAXIS    = { 1, 0, 0 };
-const Vector3 VECTOR3_YAXIS    = { 0, 1, 0 };
-const Vector3 VECTOR3_ZAXIS    = { 0, 0, 1 };
-const Vector3 VECTOR3_FORWARD  = { 0, 0, 1 };
-const Vector3 VECTOR3_BACKWARD = { 0, 0, -1 };
-const Vector3 VECTOR3_LEFT     = { -1, 0, 0 };
-const Vector3 VECTOR3_RIGHT    = { 1, 0, 0 };
-const Vector3 VECTOR3_UP       = { 0, 1, 0 };
-const Vector3 VECTOR3_DOWN     = { 0, -1, 0 };
-
-/// Returns the Vector2 portion of @a a. (i.e. truncates z)
-Vector2 to_vector2(const Vector3& a);
+const Vector3 VECTOR3_ZERO     = { 0.0f, 0.0f, 0.0f };
+const Vector3 VECTOR3_XAXIS    = { 1.0f, 0.0f, 0.0f };
+const Vector3 VECTOR3_YAXIS    = { 0.0f, 1.0f, 0.0f };
+const Vector3 VECTOR3_ZAXIS    = { 0.0f, 0.0f, 1.0f };
+const Vector3 VECTOR3_FORWARD  = { 0.0f, 0.0f, 1.0f };
+const Vector3 VECTOR3_BACKWARD = { 0.0f, 0.0f, -1.0f };
+const Vector3 VECTOR3_LEFT     = { -1.0f, 0.0f, 0.0f };
+const Vector3 VECTOR3_RIGHT    = { 1.0f, 0.0f, 0.0f };
+const Vector3 VECTOR3_UP       = { 0.0f, 1.0f, 0.0f };
+const Vector3 VECTOR3_DOWN     = { 0.0f, -1.0f, 0.0f };
 
 inline Vector3 vector3(float x, float y, float z)
 {
@@ -66,7 +61,7 @@ inline Vector3& operator*=(Vector3& a, float k)
 
 inline Vector3& operator/=(Vector3& a, float k)
 {
-	CE_ASSERT(k != (float)0.0, "Division by zero");
+	CE_ASSERT(k != 0.0f, "Division by zero");
 	float inv = 1.0f / k;
 	a.x *= inv;
 	a.y *= inv;
@@ -77,7 +72,11 @@ inline Vector3& operator/=(Vector3& a, float k)
 /// Negates @a a and returns the result.
 inline Vector3 operator-(const Vector3& a)
 {
-	return vector3(-a.x, -a.y, -a.z);
+	Vector3 res;
+	res.x = -a.x;
+	res.y = -a.y;
+	res.z = -a.z;
+	return res;
 }
 
 /// Adds the vector @a a to @a b and returns the result.
@@ -101,7 +100,7 @@ inline Vector3 operator*(Vector3 a, float k)
 	return a;
 }
 
-/// @copydoc operator*(Vector3, float)
+/// Multiplies the vector @a a by the scalar @a k and returns the result.
 inline Vector3 operator*(float k, Vector3 a)
 {
 	a *= k;
@@ -159,7 +158,6 @@ inline Vector3 normalize(Vector3& a)
 inline void set_length(Vector3& a, float len)
 {
 	normalize(a);
-
 	a.x *= len;
 	a.y *= len;
 	a.z *= len;
@@ -183,15 +181,17 @@ inline float* to_float_ptr(Vector3& a)
 	return &a.x;
 }
 
-/// @copydoc to_float_ptr(Vector3&)
+/// Returns the pointer to the data of @a a.
 inline const float* to_float_ptr(const Vector3& a)
 {
 	return &a.x;
 }
 
+/// Returns the Vector2 portion of @a a. (i.e. truncates z)
 inline Vector2 to_vector2(const Vector3& a)
 {
 	return vector2(a.x, a.y);
 }
 
+/// @}
 } // namespace crown

+ 19 - 15
src/core/math/vector4.h

@@ -5,22 +5,21 @@
 
 #pragma once
 
-#include "error.h"
-#include "types.h"
+#include "math_types.h"
 #include "math_utils.h"
 #include "vector3.h"
+#include "error.h"
 
 namespace crown
 {
+/// @addtogroup Math
+/// @{
 
-/// Functions to manipulate Vector4.
-///
-/// @ingroup Math
-const Vector4 VECTOR4_ZERO  = { 0, 0, 0, 0 };
-const Vector4 VECTOR4_XAXIS = { 1, 0, 0, 0 };
-const Vector4 VECTOR4_YAXIS = { 0, 1, 0, 0 };
-const Vector4 VECTOR4_ZAXIS = { 0, 0, 1, 0 };
-const Vector4 VECTOR4_WAXIS = { 0, 0, 0, 1 };
+const Vector4 VECTOR4_ZERO  = { 0.0f, 0.0f, 0.0f, 0.0f };
+const Vector4 VECTOR4_XAXIS = { 1.0f, 0.0f, 0.0f, 0.0f };
+const Vector4 VECTOR4_YAXIS = { 0.0f, 1.0f, 0.0f, 0.0f };
+const Vector4 VECTOR4_ZAXIS = { 0.0f, 0.0f, 1.0f, 0.0f };
+const Vector4 VECTOR4_WAXIS = { 0.0f, 0.0f, 0.0f, 1.0f };
 
 /// Returns the Vector3 portion of @a a. (i.e. truncates w)
 Vector3 to_vector3(const Vector4& a);
@@ -74,7 +73,7 @@ inline Vector4& operator*=(Vector4& a, float k)
 
 inline Vector4& operator/=(Vector4& a, float k)
 {
-	CE_ASSERT(k != (float)0.0, "Division by zero");
+	CE_ASSERT(k != 0.0f, "Division by zero");
 	float inv = 1.0f / k;
 	a.x *= inv;
 	a.y *= inv;
@@ -86,7 +85,12 @@ inline Vector4& operator/=(Vector4& a, float k)
 /// Negates @a a and returns the result.
 inline Vector4 operator-(const Vector4& a)
 {
-	return vector4(-a.x, -a.y, -a.z, -a.w);
+	Vector4 res;
+	res.x = -a.x;
+	res.y = -a.y;
+	res.z = -a.z;
+	res.w = -a.w;
+	return res;
 }
 
 /// Adds the vector @a a to @a b and returns the result.
@@ -110,7 +114,7 @@ inline Vector4 operator*(Vector4 a, float k)
 	return a;
 }
 
-/// @copydoc operator*(Vector4, float)
+/// Multiplies the vector @a a by the scalar @a k and returns the result.
 inline Vector4 operator*(float k, Vector4 a)
 {
 	a *= k;
@@ -163,7 +167,6 @@ inline Vector4 normalize(Vector4& a)
 inline void set_length(Vector4& a, float len)
 {
 	normalize(a);
-
 	a.x *= len;
 	a.y *= len;
 	a.z *= len;
@@ -188,7 +191,7 @@ inline float* to_float_ptr(Vector4& a)
 	return &a.x;
 }
 
-/// @copydoc to_float_ptr(Vector4&)
+/// Returns the pointer to the data of @a a.
 inline const float* to_float_ptr(const Vector4& a)
 {
 	return &a.x;
@@ -199,4 +202,5 @@ inline Vector3 to_vector3(const Vector4& a)
 	return vector3(a.x, a.y, a.z);
 }
 
+/// @}
 } // namespace crown