ソースを参照

Make math types POD

Daniele Bartolini 10 年 前
コミット
a59c221bdf

+ 6 - 6
src/audio/sound_world_al.cpp

@@ -169,12 +169,12 @@ struct SoundInstance
 	{
 		ALfloat pos[3];
 		AL_CHECK(alGetSourcefv(_source, AL_POSITION, pos));
-		return Vector3(pos[0], pos[1], pos[2]);
+		return vector3(pos[0], pos[1], pos[2]);
 	}
 
 	void set_position(const Vector3& pos)
 	{
-		AL_CHECK(alSourcefv(_source, AL_POSITION, vector3::to_float_ptr(pos)));
+		AL_CHECK(alSourcefv(_source, AL_POSITION, to_float_ptr(pos)));
 	}
 
 	void set_range(float range)
@@ -206,7 +206,7 @@ public:
 
 	ALSoundWorld()
 	{
-		set_listener_pose(matrix4x4::IDENTITY);
+		set_listener_pose(MATRIX4X4_IDENTITY);
 	}
 
 	virtual ~ALSoundWorld()
@@ -296,9 +296,9 @@ public:
 
 	virtual void set_listener_pose(const Matrix4x4& pose)
 	{
-		const Vector3 pos = matrix4x4::translation(pose);
-		const Vector3 up = matrix4x4::y(pose);
-		const Vector3 at = matrix4x4::z(pose);
+		const Vector3 pos = translation(pose);
+		const Vector3 up = y(pose);
+		const Vector3 at = z(pose);
 
 		AL_CHECK(alListener3f(AL_POSITION, pos.x, pos.y, pos.z));
 		//AL_CHECK(alListener3f(AL_VELOCITY, vel.x, vel.y, vel.z));

+ 14 - 14
src/core/json/json_parser.cpp

@@ -143,8 +143,8 @@ Vector2 JSONElement::to_vector2(const Vector2& def) const
 	Array<const char*> array(alloc);
 	njson::parse_array(_at, array);
 
-	return Vector2(njson::parse_float(array[0]),
-					njson::parse_float(array[1]));
+	return vector2(njson::parse_float(array[0]),
+		njson::parse_float(array[1]));
 }
 
 Vector3 JSONElement::to_vector3(const Vector3& def) const
@@ -156,9 +156,9 @@ Vector3 JSONElement::to_vector3(const Vector3& def) const
 	Array<const char*> array(alloc);
 	njson::parse_array(_at, array);
 
-	return Vector3(njson::parse_float(array[0]),
-					njson::parse_float(array[1]),
-					njson::parse_float(array[2]));
+	return vector3(njson::parse_float(array[0]),
+		njson::parse_float(array[1]),
+		njson::parse_float(array[2]));
 }
 
 Vector4 JSONElement::to_vector4(const Vector4& def) const
@@ -170,10 +170,10 @@ Vector4 JSONElement::to_vector4(const Vector4& def) const
 	Array<const char*> array(alloc);
 	njson::parse_array(_at, array);
 
-	return Vector4(njson::parse_float(array[0]),
-					njson::parse_float(array[1]),
-					njson::parse_float(array[2]),
-					njson::parse_float(array[3]));
+	return vector4(njson::parse_float(array[0]),
+		njson::parse_float(array[1]),
+		njson::parse_float(array[2]),
+		njson::parse_float(array[3]));
 }
 
 Quaternion JSONElement::to_quaternion(const Quaternion& def) const
@@ -185,10 +185,10 @@ Quaternion JSONElement::to_quaternion(const Quaternion& def) const
 	Array<const char*> array(alloc);
 	njson::parse_array(_at, array);
 
-	return Quaternion(njson::parse_float(array[0]),
-					njson::parse_float(array[1]),
-					njson::parse_float(array[2]),
-					njson::parse_float(array[3]));
+	return quaternion(njson::parse_float(array[0]),
+		njson::parse_float(array[1]),
+		njson::parse_float(array[2]),
+		njson::parse_float(array[3]));
 }
 
 Matrix4x4 JSONElement::to_matrix4x4(const Matrix4x4& def) const
@@ -200,7 +200,7 @@ Matrix4x4 JSONElement::to_matrix4x4(const Matrix4x4& def) const
 	Array<float> array(alloc);
 	to_array(array);
 
-	return Matrix4x4(array::begin(array));
+	return matrix4x4(array::begin(array));
 }
 
 StringId32 JSONElement::to_string_id(const StringId32 def) const

+ 5 - 5
src/core/json/json_parser.h

@@ -101,23 +101,23 @@ public:
 
 	/// Returns the Vector2 value of the element.
 	/// @note Vector2 = [x, y]
-	Vector2 to_vector2(const Vector2& def = Vector2(0, 0)) const;
+	Vector2 to_vector2(const Vector2& def = vector2(0, 0)) const;
 
 	/// Returns the Vector3 value of the element.
 	/// @note Vector3 = [x, y, z]
-	Vector3 to_vector3(const Vector3& def = Vector3(0, 0, 0)) const;
+	Vector3 to_vector3(const Vector3& def = vector3(0, 0, 0)) const;
 
 	/// Returns the Vector4 value of the element.
 	/// @note Vector4 = [x, y, z, w]
-	Vector4 to_vector4(const Vector4& def = Vector4(0, 0, 0, 0)) const;
+	Vector4 to_vector4(const Vector4& def = vector4(0, 0, 0, 0)) const;
 
 	/// Returns the Quaternion value of the element.
 	/// @note Quaternion = [x, y, z, w]
-	Quaternion to_quaternion(const Quaternion& def = quaternion::IDENTITY) const;
+	Quaternion to_quaternion(const Quaternion& def = QUATERNION_IDENTITY) const;
 
 	/// Returns the Matrix4x4 value of the element.
 	/// @note Matrix4x4 = [x, x, x, x, y, y, y, y, z, z, z, z, t, t, t, t]
-	Matrix4x4 to_matrix4x4(const Matrix4x4& def = matrix4x4::IDENTITY) const;
+	Matrix4x4 to_matrix4x4(const Matrix4x4& def = MATRIX4X4_IDENTITY) const;
 
 	/// Returns the string id value hashed to murmur32() of the element.
 	StringId32 to_string_id(const StringId32 def = StringId32(uint32_t(0))) const;

+ 16 - 23
src/core/math/aabb.h

@@ -57,8 +57,8 @@ namespace aabb
 {
 	inline void reset(AABB& b)
 	{
-		b.min = vector3::ZERO;
-		b.max = vector3::ZERO;
+		b.min = VECTOR3_ZERO;
+		b.max = VECTOR3_ZERO;
 	}
 
 	inline Vector3 center(const AABB& b)
@@ -68,7 +68,7 @@ namespace aabb
 
 	inline float radius(const AABB& b)
 	{
-		return vector3::length(b.max - (b.min + b.max) * 0.5f);
+		return length(b.max - (b.min + b.max) * 0.5f);
 	}
 	inline float volume(const AABB& b)
 	{
@@ -120,15 +120,15 @@ namespace aabb
 	{
 		switch (index)
 		{
-			case 0: return Vector3(b.min.x, b.min.y, b.min.z);
-			case 1: return Vector3(b.max.x, b.min.y, b.min.z);
-			case 2: return Vector3(b.max.x, b.min.y, b.max.z);
-			case 3: return Vector3(b.min.x, b.min.y, b.max.z);
-			case 4: return Vector3(b.min.x, b.max.y, b.min.z);
-			case 5: return Vector3(b.max.x, b.max.y, b.min.z);
-			case 6: return Vector3(b.max.x, b.max.y, b.max.z);
-			case 7: return Vector3(b.min.x, b.max.y, b.max.z);
-			default: CE_FATAL("Bad index"); return Vector3(0.0f, 0.0f, 0.0f);
+			case 0: return vector3(b.min.x, b.min.y, b.min.z);
+			case 1: return vector3(b.max.x, b.min.y, b.min.z);
+			case 2: return vector3(b.max.x, b.min.y, b.max.z);
+			case 3: return vector3(b.min.x, b.min.y, b.max.z);
+			case 4: return vector3(b.min.x, b.max.y, b.min.z);
+			case 5: return vector3(b.max.x, b.max.y, b.min.z);
+			case 6: return vector3(b.max.x, b.max.y, b.max.z);
+			case 7: return vector3(b.min.x, b.max.y, b.max.z);
+			default: CE_FATAL("Bad index"); return vector3(0.0f, 0.0f, 0.0f);
 		}
 	}
 
@@ -198,18 +198,11 @@ namespace aabb
 
 	inline Sphere to_sphere(const AABB& b)
 	{
-		return Sphere(center(b), radius(b));
+		Sphere s;
+		s.c = center(b);
+		s.r = radius(b);
+		return s;
 	}
 } // namespace aabb
 
-inline AABB::AABB()
-{
-	// Do not initialize
-}
-
-inline AABB::AABB(const Vector3& min, const Vector3& max)
-	: min(min), max(max)
-{
-}
-
 } // namespace crown

+ 230 - 234
src/core/math/color4.h

@@ -18,253 +18,249 @@ typedef Vector4 Color4;
 /// Functions to mamipulate Color4
 ///
 /// @ingroup Math
-namespace color4
-{
-	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);
+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);
 
-	/// Returns the color as a packed 32-bit integer. (RGBA order, alpha assumed = 255)
-	uint32_t to_rgb(const Color4& c);
+/// Returns the color as a packed 32-bit integer. (RGBA order, alpha assumed = 255)
+uint32_t to_rgb(const Color4& c);
 
-	/// Returns the color as a packed 32-bit integer. (ABGR order, alpha assumed = 255)
-	uint32_t to_bgr(const Color4& c);
+/// Returns the color as a packed 32-bit integer. (ABGR order, alpha assumed = 255)
+uint32_t to_bgr(const Color4& c);
 
-	/// Returns the color as a packed 32-bit integer. (RGBA order)
-	uint32_t to_rgba(const Color4& c);
+/// Returns the color as a packed 32-bit integer. (RGBA order)
+uint32_t to_rgba(const Color4& c);
 
-	/// Returns the color as a packed 32-bit integer. (ABGR order)
-	uint32_t to_abgr(const Color4& c);
-} // namespace color4
+/// Returns the color as a packed 32-bit integer. (ABGR order)
+uint32_t to_abgr(const Color4& c);
 
-namespace color4
-{
-	// SVG 1.0 color names
-	const Color4 ALICEBLUE            = from_rgba(0xf0f8ffff);
-	const Color4 ANTIQUEWHITE         = from_rgba(0xfaebd7ff);
-	const Color4 AQUA                 = from_rgba(0x00ffffff);
-	const Color4 AQUAMARINE           = from_rgba(0x7fffd4ff);
-	const Color4 AZURE                = from_rgba(0xf0ffffff);
-	const Color4 BEIGE                = from_rgba(0xf5f5dcff);
-	const Color4 BISQUE               = from_rgba(0xffe4c4ff);
-	const Color4 BLACK                = from_rgba(0x000000ff);
-	const Color4 BLANCHEDALMOND       = from_rgba(0xffebcdff);
-	const Color4 BLUE                 = from_rgba(0x0000ffff);
-	const Color4 BLUEVIOLET           = from_rgba(0x8a2be2ff);
-	const Color4 BROWN                = from_rgba(0xa52a2aff);
-	const Color4 BURLYWOOD            = from_rgba(0xdeb887ff);
-	const Color4 CADETBLUE            = from_rgba(0x5f9ea0ff);
-	const Color4 CHARTREUSE           = from_rgba(0x7fff00ff);
-	const Color4 CHOCOLATE            = from_rgba(0xd2691eff);
-	const Color4 CORAL                = from_rgba(0xff7f50ff);
-	const Color4 CORNFLOWERBLUE       = from_rgba(0x6495edff);
-	const Color4 CORNSILK             = from_rgba(0xfff8dcff);
-	const Color4 CRIMSON              = from_rgba(0xdc143cff);
-	const Color4 CYAN                 = from_rgba(0x00ffffff);
-	const Color4 DARKBLUE             = from_rgba(0x00008bff);
-	const Color4 DARKCYAN             = from_rgba(0x008b8bff);
-	const Color4 DARKGOLDENROD        = from_rgba(0xb8860bff);
-	const Color4 DARKGRAY             = from_rgba(0xa9a9a9ff);
-	const Color4 DARKGREEN            = from_rgba(0x006400ff);
-	const Color4 DARKGREY             = from_rgba(0xa9a9a9ff);
-	const Color4 DARKKHAKI            = from_rgba(0xbdb76bff);
-	const Color4 DARKMAGENTA          = from_rgba(0x8b008bff);
-	const Color4 DARKOLIVEGREEN       = from_rgba(0x556b2fff);
-	const Color4 DARKORANGE           = from_rgba(0xff8c00ff);
-	const Color4 DARKORCHID           = from_rgba(0x9932ccff);
-	const Color4 DARKRED              = from_rgba(0x8b0000ff);
-	const Color4 DARKSALMON           = from_rgba(0xe9967aff);
-	const Color4 DARKSEAGREEN         = from_rgba(0x8fbc8fff);
-	const Color4 DARKSLATEBLUE        = from_rgba(0x483d8bff);
-	const Color4 DARKSLATEGRAY        = from_rgba(0x2f4f4fff);
-	const Color4 DARKSLATEGREY        = from_rgba(0x2f4f4fff);
-	const Color4 DARKTURQUOISE        = from_rgba(0x00ced1ff);
-	const Color4 DARKVIOLET           = from_rgba(0x9400d3ff);
-	const Color4 DEEPPINK             = from_rgba(0xff1493ff);
-	const Color4 DEEPSKYBLUE          = from_rgba(0x00bfffff);
-	const Color4 DIMGRAY              = from_rgba(0x696969ff);
-	const Color4 DIMGREY              = from_rgba(0x696969ff);
-	const Color4 DODGERBLUE           = from_rgba(0x1e90ffff);
-	const Color4 FIREBRICK            = from_rgba(0xb22222ff);
-	const Color4 FLORALWHITE          = from_rgba(0xfffaf0ff);
-	const Color4 FORESTGREEN          = from_rgba(0x228b22ff);
-	const Color4 FUCHSIA              = from_rgba(0xff00ffff);
-	const Color4 GAINSBORO            = from_rgba(0xdcdcdcff);
-	const Color4 GHOSTWHITE           = from_rgba(0xf8f8ffff);
-	const Color4 GOLD                 = from_rgba(0xffd700ff);
-	const Color4 GOLDENROD            = from_rgba(0xdaa520ff);
-	const Color4 GRAY                 = from_rgba(0x808080ff);
-	const Color4 GREEN                = from_rgba(0x008000ff);
-	const Color4 GREENYELLOW          = from_rgba(0xadff2fff);
-	const Color4 GREY                 = from_rgba(0x808080ff);
-	const Color4 HONEYDEW             = from_rgba(0xf0fff0ff);
-	const Color4 HOTPINK              = from_rgba(0xff69b4ff);
-	const Color4 INDIANRED            = from_rgba(0xcd5c5cff);
-	const Color4 INDIGO               = from_rgba(0x4b0082ff);
-	const Color4 IVORY                = from_rgba(0xfffff0ff);
-	const Color4 KHAKI                = from_rgba(0xf0e68cff);
-	const Color4 LAVENDER             = from_rgba(0xe6e6faff);
-	const Color4 LAVENDERBLUSH        = from_rgba(0xfff0f5ff);
-	const Color4 LAWNGREEN            = from_rgba(0x7cfc00ff);
-	const Color4 LEMONCHIFFON         = from_rgba(0xfffacdff);
-	const Color4 LIGHTBLUE            = from_rgba(0xadd8e6ff);
-	const Color4 LIGHTCORAL           = from_rgba(0xf08080ff);
-	const Color4 LIGHTCYAN            = from_rgba(0xe0ffffff);
-	const Color4 LIGHTGOLDENRODYELLOW = from_rgba(0xfafad2ff);
-	const Color4 LIGHTGRAY            = from_rgba(0xd3d3d3ff);
-	const Color4 LIGHTGREEN           = from_rgba(0x90ee90ff);
-	const Color4 LIGHTGREY            = from_rgba(0xd3d3d3ff);
-	const Color4 LIGHTPINK            = from_rgba(0xffb6c1ff);
-	const Color4 LIGHTSALMON          = from_rgba(0xffa07aff);
-	const Color4 LIGHTSEAGREEN        = from_rgba(0x20b2aaff);
-	const Color4 LIGHTSKYBLUE         = from_rgba(0x87cefaff);
-	const Color4 LIGHTSLATEGRAY       = from_rgba(0x778899ff);
-	const Color4 LIGHTSLATEGREY       = from_rgba(0x778899ff);
-	const Color4 LIGHTSTEELBLUE       = from_rgba(0xb0c4deff);
-	const Color4 LIGHTYELLOW          = from_rgba(0xffffe0ff);
-	const Color4 LIME                 = from_rgba(0x00ff00ff);
-	const Color4 LIMEGREEN            = from_rgba(0x32cd32ff);
-	const Color4 LINEN                = from_rgba(0xfaf0e6ff);
-	const Color4 MAGENTA              = from_rgba(0xff00ffff);
-	const Color4 MAROON               = from_rgba(0x800000ff);
-	const Color4 MEDIUMAQUAMARINE     = from_rgba(0x66cdaaff);
-	const Color4 MEDIUMBLUE           = from_rgba(0x0000cdff);
-	const Color4 MEDIUMORCHID         = from_rgba(0xba55d3ff);
-	const Color4 MEDIUMPURPLE         = from_rgba(0x9370dbff);
-	const Color4 MEDIUMSEAGREEN       = from_rgba(0x3cb371ff);
-	const Color4 MEDIUMSLATEBLUE      = from_rgba(0x7b68eeff);
-	const Color4 MEDIUMSPRINGGREEN    = from_rgba(0x00fa9aff);
-	const Color4 MEDIUMTURQUOISE      = from_rgba(0x48d1ccff);
-	const Color4 MEDIUMVIOLETRED      = from_rgba(0xc71585ff);
-	const Color4 MIDNIGHTBLUE         = from_rgba(0x191970ff);
-	const Color4 MINTCREAM            = from_rgba(0xf5fffaff);
-	const Color4 MISTYROSE            = from_rgba(0xffe4e1ff);
-	const Color4 MOCCASIN             = from_rgba(0xffe4b5ff);
-	const Color4 NAVAJOWHITE          = from_rgba(0xffdeadff);
-	const Color4 NAVY                 = from_rgba(0x000080ff);
-	const Color4 OLDLACE              = from_rgba(0xfdf5e6ff);
-	const Color4 OLIVE                = from_rgba(0x808000ff);
-	const Color4 OLIVEDRAB            = from_rgba(0x6b8e23ff);
-	const Color4 ORANGE               = from_rgba(0xffa500ff);
-	const Color4 ORANGERED            = from_rgba(0xff4500ff);
-	const Color4 ORCHID               = from_rgba(0xda70d6ff);
-	const Color4 PALEGOLDENROD        = from_rgba(0xeee8aaff);
-	const Color4 PALEGREEN            = from_rgba(0x98fb98ff);
-	const Color4 PALETURQUOISE        = from_rgba(0xafeeeeff);
-	const Color4 PALEVIOLETRED        = from_rgba(0xdb7093ff);
-	const Color4 PAPAYAWHIP           = from_rgba(0xffefd5ff);
-	const Color4 PEACHPUFF            = from_rgba(0xffdab9ff);
-	const Color4 PERU                 = from_rgba(0xcd853fff);
-	const Color4 PINK                 = from_rgba(0xffc0cbff);
-	const Color4 PLUM                 = from_rgba(0xdda0ddff);
-	const Color4 POWDERBLUE           = from_rgba(0xb0e0e6ff);
-	const Color4 PURPLE               = from_rgba(0x800080ff);
-	const Color4 RED                  = from_rgba(0xff0000ff);
-	const Color4 ROSYBROWN            = from_rgba(0xbc8f8fff);
-	const Color4 ROYALBLUE            = from_rgba(0x4169e1ff);
-	const Color4 SADDLEBROWN          = from_rgba(0x8b4513ff);
-	const Color4 SALMON               = from_rgba(0xfa8072ff);
-	const Color4 SANDYBROWN           = from_rgba(0xf4a460ff);
-	const Color4 SEAGREEN             = from_rgba(0x2e8b57ff);
-	const Color4 SEASHELL             = from_rgba(0xfff5eeff);
-	const Color4 SIENNA               = from_rgba(0xa0522dff);
-	const Color4 SILVER               = from_rgba(0xc0c0c0ff);
-	const Color4 SKYBLUE              = from_rgba(0x87ceebff);
-	const Color4 SLATEBLUE            = from_rgba(0x6a5acdff);
-	const Color4 SLATEGRAY            = from_rgba(0x708090ff);
-	const Color4 SLATEGREY            = from_rgba(0x708090ff);
-	const Color4 SNOW                 = from_rgba(0xfffafaff);
-	const Color4 SPRINGGREEN          = from_rgba(0x00ff7fff);
-	const Color4 STEELBLUE            = from_rgba(0x4682b4ff);
-	const Color4 TAN                  = from_rgba(0xd2b48cff);
-	const Color4 TEAL                 = from_rgba(0x008080ff);
-	const Color4 THISTLE              = from_rgba(0xd8bfd8ff);
-	const Color4 TOMATO               = from_rgba(0xff6347ff);
-	const Color4 TURQUOISE            = from_rgba(0x40e0d0ff);
-	const Color4 VIOLET               = from_rgba(0xee82eeff);
-	const Color4 WHEAT                = from_rgba(0xf5deb3ff);
-	const Color4 WHITE                = from_rgba(0xffffffff);
-	const Color4 WHITESMOKE           = from_rgba(0xf5f5f5ff);
-	const Color4 YELLOW               = from_rgba(0xffff00ff);
-	const Color4 YELLOWGREEN          = from_rgba(0x9acd32ff);
-} // namespace color4
+// SVG 1.0 color names
+const Color4 COLOR4_ALICEBLUE            = from_rgba(0xf0f8ffff);
+const Color4 COLOR4_ANTIQUEWHITE         = from_rgba(0xfaebd7ff);
+const Color4 COLOR4_AQUA                 = from_rgba(0x00ffffff);
+const Color4 COLOR4_AQUAMARINE           = from_rgba(0x7fffd4ff);
+const Color4 COLOR4_AZURE                = from_rgba(0xf0ffffff);
+const Color4 COLOR4_BEIGE                = from_rgba(0xf5f5dcff);
+const Color4 COLOR4_BISQUE               = from_rgba(0xffe4c4ff);
+const Color4 COLOR4_BLACK                = from_rgba(0x000000ff);
+const Color4 COLOR4_BLANCHEDALMOND       = from_rgba(0xffebcdff);
+const Color4 COLOR4_BLUE                 = from_rgba(0x0000ffff);
+const Color4 COLOR4_BLUEVIOLET           = from_rgba(0x8a2be2ff);
+const Color4 COLOR4_BROWN                = from_rgba(0xa52a2aff);
+const Color4 COLOR4_BURLYWOOD            = from_rgba(0xdeb887ff);
+const Color4 COLOR4_CADETBLUE            = from_rgba(0x5f9ea0ff);
+const Color4 COLOR4_CHARTREUSE           = from_rgba(0x7fff00ff);
+const Color4 COLOR4_CHOCOLATE            = from_rgba(0xd2691eff);
+const Color4 COLOR4_CORAL                = from_rgba(0xff7f50ff);
+const Color4 COLOR4_CORNFLOWERBLUE       = from_rgba(0x6495edff);
+const Color4 COLOR4_CORNSILK             = from_rgba(0xfff8dcff);
+const Color4 COLOR4_CRIMSON              = from_rgba(0xdc143cff);
+const Color4 COLOR4_CYAN                 = from_rgba(0x00ffffff);
+const Color4 COLOR4_DARKBLUE             = from_rgba(0x00008bff);
+const Color4 COLOR4_DARKCYAN             = from_rgba(0x008b8bff);
+const Color4 COLOR4_DARKGOLDENROD        = from_rgba(0xb8860bff);
+const Color4 COLOR4_DARKGRAY             = from_rgba(0xa9a9a9ff);
+const Color4 COLOR4_DARKGREEN            = from_rgba(0x006400ff);
+const Color4 COLOR4_DARKGREY             = from_rgba(0xa9a9a9ff);
+const Color4 COLOR4_DARKKHAKI            = from_rgba(0xbdb76bff);
+const Color4 COLOR4_DARKMAGENTA          = from_rgba(0x8b008bff);
+const Color4 COLOR4_DARKOLIVEGREEN       = from_rgba(0x556b2fff);
+const Color4 COLOR4_DARKORANGE           = from_rgba(0xff8c00ff);
+const Color4 COLOR4_DARKORCHID           = from_rgba(0x9932ccff);
+const Color4 COLOR4_DARKRED              = from_rgba(0x8b0000ff);
+const Color4 COLOR4_DARKSALMON           = from_rgba(0xe9967aff);
+const Color4 COLOR4_DARKSEAGREEN         = from_rgba(0x8fbc8fff);
+const Color4 COLOR4_DARKSLATEBLUE        = from_rgba(0x483d8bff);
+const Color4 COLOR4_DARKSLATEGRAY        = from_rgba(0x2f4f4fff);
+const Color4 COLOR4_DARKSLATEGREY        = from_rgba(0x2f4f4fff);
+const Color4 COLOR4_DARKTURQUOISE        = from_rgba(0x00ced1ff);
+const Color4 COLOR4_DARKVIOLET           = from_rgba(0x9400d3ff);
+const Color4 COLOR4_DEEPPINK             = from_rgba(0xff1493ff);
+const Color4 COLOR4_DEEPSKYBLUE          = from_rgba(0x00bfffff);
+const Color4 COLOR4_DIMGRAY              = from_rgba(0x696969ff);
+const Color4 COLOR4_DIMGREY              = from_rgba(0x696969ff);
+const Color4 COLOR4_DODGERBLUE           = from_rgba(0x1e90ffff);
+const Color4 COLOR4_FIREBRICK            = from_rgba(0xb22222ff);
+const Color4 COLOR4_FLORALWHITE          = from_rgba(0xfffaf0ff);
+const Color4 COLOR4_FORESTGREEN          = from_rgba(0x228b22ff);
+const Color4 COLOR4_FUCHSIA              = from_rgba(0xff00ffff);
+const Color4 COLOR4_GAINSBORO            = from_rgba(0xdcdcdcff);
+const Color4 COLOR4_GHOSTWHITE           = from_rgba(0xf8f8ffff);
+const Color4 COLOR4_GOLD                 = from_rgba(0xffd700ff);
+const Color4 COLOR4_GOLDENROD            = from_rgba(0xdaa520ff);
+const Color4 COLOR4_GRAY                 = from_rgba(0x808080ff);
+const Color4 COLOR4_GREEN                = from_rgba(0x008000ff);
+const Color4 COLOR4_GREENYELLOW          = from_rgba(0xadff2fff);
+const Color4 COLOR4_GREY                 = from_rgba(0x808080ff);
+const Color4 COLOR4_HONEYDEW             = from_rgba(0xf0fff0ff);
+const Color4 COLOR4_HOTPINK              = from_rgba(0xff69b4ff);
+const Color4 COLOR4_INDIANRED            = from_rgba(0xcd5c5cff);
+const Color4 COLOR4_INDIGO               = from_rgba(0x4b0082ff);
+const Color4 COLOR4_IVORY                = from_rgba(0xfffff0ff);
+const Color4 COLOR4_KHAKI                = from_rgba(0xf0e68cff);
+const Color4 COLOR4_LAVENDER             = from_rgba(0xe6e6faff);
+const Color4 COLOR4_LAVENDERBLUSH        = from_rgba(0xfff0f5ff);
+const Color4 COLOR4_LAWNGREEN            = from_rgba(0x7cfc00ff);
+const Color4 COLOR4_LEMONCHIFFON         = from_rgba(0xfffacdff);
+const Color4 COLOR4_LIGHTBLUE            = from_rgba(0xadd8e6ff);
+const Color4 COLOR4_LIGHTCORAL           = from_rgba(0xf08080ff);
+const Color4 COLOR4_LIGHTCYAN            = from_rgba(0xe0ffffff);
+const Color4 COLOR4_LIGHTGOLDENRODYELLOW = from_rgba(0xfafad2ff);
+const Color4 COLOR4_LIGHTGRAY            = from_rgba(0xd3d3d3ff);
+const Color4 COLOR4_LIGHTGREEN           = from_rgba(0x90ee90ff);
+const Color4 COLOR4_LIGHTGREY            = from_rgba(0xd3d3d3ff);
+const Color4 COLOR4_LIGHTPINK            = from_rgba(0xffb6c1ff);
+const Color4 COLOR4_LIGHTSALMON          = from_rgba(0xffa07aff);
+const Color4 COLOR4_LIGHTSEAGREEN        = from_rgba(0x20b2aaff);
+const Color4 COLOR4_LIGHTSKYBLUE         = from_rgba(0x87cefaff);
+const Color4 COLOR4_LIGHTSLATEGRAY       = from_rgba(0x778899ff);
+const Color4 COLOR4_LIGHTSLATEGREY       = from_rgba(0x778899ff);
+const Color4 COLOR4_LIGHTSTEELBLUE       = from_rgba(0xb0c4deff);
+const Color4 COLOR4_LIGHTYELLOW          = from_rgba(0xffffe0ff);
+const Color4 COLOR4_LIME                 = from_rgba(0x00ff00ff);
+const Color4 COLOR4_LIMEGREEN            = from_rgba(0x32cd32ff);
+const Color4 COLOR4_LINEN                = from_rgba(0xfaf0e6ff);
+const Color4 COLOR4_MAGENTA              = from_rgba(0xff00ffff);
+const Color4 COLOR4_MAROON               = from_rgba(0x800000ff);
+const Color4 COLOR4_MEDIUMAQUAMARINE     = from_rgba(0x66cdaaff);
+const Color4 COLOR4_MEDIUMBLUE           = from_rgba(0x0000cdff);
+const Color4 COLOR4_MEDIUMORCHID         = from_rgba(0xba55d3ff);
+const Color4 COLOR4_MEDIUMPURPLE         = from_rgba(0x9370dbff);
+const Color4 COLOR4_MEDIUMSEAGREEN       = from_rgba(0x3cb371ff);
+const Color4 COLOR4_MEDIUMSLATEBLUE      = from_rgba(0x7b68eeff);
+const Color4 COLOR4_MEDIUMSPRINGGREEN    = from_rgba(0x00fa9aff);
+const Color4 COLOR4_MEDIUMTURQUOISE      = from_rgba(0x48d1ccff);
+const Color4 COLOR4_MEDIUMVIOLETRED      = from_rgba(0xc71585ff);
+const Color4 COLOR4_MIDNIGHTBLUE         = from_rgba(0x191970ff);
+const Color4 COLOR4_MINTCREAM            = from_rgba(0xf5fffaff);
+const Color4 COLOR4_MISTYROSE            = from_rgba(0xffe4e1ff);
+const Color4 COLOR4_MOCCASIN             = from_rgba(0xffe4b5ff);
+const Color4 COLOR4_NAVAJOWHITE          = from_rgba(0xffdeadff);
+const Color4 COLOR4_NAVY                 = from_rgba(0x000080ff);
+const Color4 COLOR4_OLDLACE              = from_rgba(0xfdf5e6ff);
+const Color4 COLOR4_OLIVE                = from_rgba(0x808000ff);
+const Color4 COLOR4_OLIVEDRAB            = from_rgba(0x6b8e23ff);
+const Color4 COLOR4_ORANGE               = from_rgba(0xffa500ff);
+const Color4 COLOR4_ORANGERED            = from_rgba(0xff4500ff);
+const Color4 COLOR4_ORCHID               = from_rgba(0xda70d6ff);
+const Color4 COLOR4_PALEGOLDENROD        = from_rgba(0xeee8aaff);
+const Color4 COLOR4_PALEGREEN            = from_rgba(0x98fb98ff);
+const Color4 COLOR4_PALETURQUOISE        = from_rgba(0xafeeeeff);
+const Color4 COLOR4_PALEVIOLETRED        = from_rgba(0xdb7093ff);
+const Color4 COLOR4_PAPAYAWHIP           = from_rgba(0xffefd5ff);
+const Color4 COLOR4_PEACHPUFF            = from_rgba(0xffdab9ff);
+const Color4 COLOR4_PERU                 = from_rgba(0xcd853fff);
+const Color4 COLOR4_PINK                 = from_rgba(0xffc0cbff);
+const Color4 COLOR4_PLUM                 = from_rgba(0xdda0ddff);
+const Color4 COLOR4_POWDERBLUE           = from_rgba(0xb0e0e6ff);
+const Color4 COLOR4_PURPLE               = from_rgba(0x800080ff);
+const Color4 COLOR4_RED                  = from_rgba(0xff0000ff);
+const Color4 COLOR4_ROSYBROWN            = from_rgba(0xbc8f8fff);
+const Color4 COLOR4_ROYALBLUE            = from_rgba(0x4169e1ff);
+const Color4 COLOR4_SADDLEBROWN          = from_rgba(0x8b4513ff);
+const Color4 COLOR4_SALMON               = from_rgba(0xfa8072ff);
+const Color4 COLOR4_SANDYBROWN           = from_rgba(0xf4a460ff);
+const Color4 COLOR4_SEAGREEN             = from_rgba(0x2e8b57ff);
+const Color4 COLOR4_SEASHELL             = from_rgba(0xfff5eeff);
+const Color4 COLOR4_SIENNA               = from_rgba(0xa0522dff);
+const Color4 COLOR4_SILVER               = from_rgba(0xc0c0c0ff);
+const Color4 COLOR4_SKYBLUE              = from_rgba(0x87ceebff);
+const Color4 COLOR4_SLATEBLUE            = from_rgba(0x6a5acdff);
+const Color4 COLOR4_SLATEGRAY            = from_rgba(0x708090ff);
+const Color4 COLOR4_SLATEGREY            = from_rgba(0x708090ff);
+const Color4 COLOR4_SNOW                 = from_rgba(0xfffafaff);
+const Color4 COLOR4_SPRINGGREEN          = from_rgba(0x00ff7fff);
+const Color4 COLOR4_STEELBLUE            = from_rgba(0x4682b4ff);
+const Color4 COLOR4_TAN                  = from_rgba(0xd2b48cff);
+const Color4 COLOR4_TEAL                 = from_rgba(0x008080ff);
+const Color4 COLOR4_THISTLE              = from_rgba(0xd8bfd8ff);
+const Color4 COLOR4_TOMATO               = from_rgba(0xff6347ff);
+const Color4 COLOR4_TURQUOISE            = from_rgba(0x40e0d0ff);
+const Color4 COLOR4_VIOLET               = from_rgba(0xee82eeff);
+const Color4 COLOR4_WHEAT                = from_rgba(0xf5deb3ff);
+const Color4 COLOR4_WHITE                = from_rgba(0xffffffff);
+const Color4 COLOR4_WHITESMOKE           = from_rgba(0xf5f5f5ff);
+const Color4 COLOR4_YELLOW               = from_rgba(0xffff00ff);
+const Color4 COLOR4_YELLOWGREEN          = from_rgba(0x9acd32ff);
 
-namespace color4
+inline Color4 color4(float r, float g, float b, float a)
 {
-	inline Color4 from_rgb(int r, int g, int b)
-	{
-		return Color4(r * 1.0f/255.0f
-			, g * 1.0f/255.0f
-			, b * 1.0f/255.0f
-			, 1.0f
-		);
-	}
-
-	inline Color4 from_rgba(int r, int g, int b, int a)
-	{
-		return Color4(r * 1.0f/255.0f
-			, g * 1.0f/255.0f
-			, b * 1.0f/255.0f
-			, a * 1.0f/255.0f
-		);
-	}
-
-	inline Color4 from_rgba(uint32_t rgba)
-	{
-		return Color4(1.0f/255.0f * ((rgba & 0xff000000) >> 24)
-			, 1.0f/255.0f * ((rgba & 0x00ff0000) >> 16)
-			, 1.0f/255.0f * ((rgba & 0x0000ff00) >> 8)
-			, 1.0f/255.0f * ((rgba & 0x000000ff) >> 0)
-		);
-	}
-
-	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;
+	Color4 c;
+	c.x = r;
+	c.y = g;
+	c.z = b;
+	c.w = a;
+	return c;
+}
 
-		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 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 uint32_t to_rgba(const Color4& c)
-	{
-		uint32_t rgba;
+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;
+}
 
-		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);
+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;
+}
 
-		return rgba;
-	}
+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_abgr(const Color4& c)
-	{
-		uint32_t abgr;
+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;
+}
 
-		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);
+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;
+}
 
-		return abgr;
-	}
-} // namespace color4
+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

+ 37 - 42
src/core/math/frustum.h

@@ -75,14 +75,14 @@ namespace frustum
 
 		switch (index)
 		{
-			case 0: return plane_3_intersection(side[4], side[0], side[2], ip);
-			case 1: return plane_3_intersection(side[4], side[1], side[2], ip);
-			case 2: return plane_3_intersection(side[4], side[1], side[3], ip);
-			case 3: return plane_3_intersection(side[4], side[0], side[3], ip);
-			case 4: return plane_3_intersection(side[5], side[0], side[2], ip);
-			case 5: return plane_3_intersection(side[5], side[1], side[2], ip);
-			case 6: return plane_3_intersection(side[5], side[1], side[3], ip);
-			case 7: return plane_3_intersection(side[5], side[0], side[3], ip);
+			case 0: 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;
 		}
 
@@ -91,35 +91,35 @@ namespace frustum
 
 	inline void from_matrix(Frustum& f, const Matrix4x4& m)
 	{
-		f.left.n.x		= m[3] + m[0];
-		f.left.n.y		= m[7] + m[4];
-		f.left.n.z		= m[11] + m[8];
-		f.left.d		= m[15] + m[12];
-
-		f.right.n.x		= m[3] - m[0];
-		f.right.n.y		= m[7] - m[4];
-		f.right.n.z		= m[11] - m[8];
-		f.right.d		= m[15] - m[12];
-
-		f.bottom.n.x	= m[3] + m[1];
-		f.bottom.n.y	= m[7] + m[5];
-		f.bottom.n.z	= m[11] + m[9];
-		f.bottom.d		= m[15] + m[13];
-
-		f.top.n.x		= m[3] - m[1];
-		f.top.n.y		= m[7] - m[5];
-		f.top.n.z		= m[11] - m[9];
-		f.top.d			= m[15] - m[13];
-
-		f.near.n.x		= m[3] + m[2];
-		f.near.n.y		= m[7] + m[6];
-		f.near.n.z		= m[11] + m[10];
-		f.near.d		= m[15] + m[14];
-
-		f.far.n.x		= m[3] - m[2];
-		f.far.n.y		= m[7] - m[6];
-		f.far.n.z		= m[11] - m[10];
-		f.far.d			= m[15] - m[14];
+		f.left.n.x   = m.x.w + m.x.x;
+		f.left.n.y   = m.y.w + m.y.x;
+		f.left.n.z   = m.z.w + m.z.x;
+		f.left.d     = m.t.w + m.t.x;
+
+		f.right.n.x  = m.x.w - m.x.x;
+		f.right.n.y  = m.y.w - m.y.x;
+		f.right.n.z  = m.z.w - m.z.x;
+		f.right.d    = m.t.w - m.t.x;
+
+		f.bottom.n.x = m.x.w + m.x.y;
+		f.bottom.n.y = m.y.w + m.y.y;
+		f.bottom.n.z = m.z.w + m.z.y;
+		f.bottom.d   = m.t.w + m.t.y;
+
+		f.top.n.x    = m.x.w - m.x.y;
+		f.top.n.y    = m.y.w - m.y.y;
+		f.top.n.z    = m.z.w - m.z.y;
+		f.top.d      = m.t.w - m.t.y;
+
+		f.near.n.x   = m.x.w + m.x.z;
+		f.near.n.y   = m.y.w + m.y.z;
+		f.near.n.z   = m.z.w + m.z.z;
+		f.near.d     = m.t.w + m.t.z;
+
+		f.far.n.x    = m.x.w - m.x.z;
+		f.far.n.y    = m.y.w - m.y.z;
+		f.far.n.z    = m.z.w - m.z.z;
+		f.far.d      = m.t.w - m.t.z;
 
 		plane::normalize(f.left);
 		plane::normalize(f.right);
@@ -150,9 +150,4 @@ namespace frustum
 	}
 } // namespace frustum
 
-inline Frustum::Frustum()
-{
-	// Do not initialize
-}
-
 } // namespace crown

+ 10 - 12
src/core/math/intersection.cpp

@@ -16,8 +16,8 @@ namespace crown
 /// -1.0f if no collision.
 float ray_plane_intersection(const Vector3& from, const Vector3& dir, const Plane& p)
 {
-	float nd = vector3::dot(dir, p.n);
-	float orpn = vector3::dot(from, p.n);
+	float nd = dot(dir, p.n);
+	float orpn = dot(from, p.n);
 	float dist = -1.0f;
 
 	if (nd < 0.0f)
@@ -31,8 +31,8 @@ float ray_plane_intersection(const Vector3& from, const Vector3& dir, const Plan
 float ray_sphere_intersection(const Vector3& from, const Vector3& dir, const Sphere& s)
 {
 	Vector3 v = s.c - from;
-	float b = vector3::dot(v, dir);
-	float det = (s.r * s.r) - vector3::dot(v, v) + (b * b);
+	float b = dot(v, dir);
+	float det = (s.r * s.r) - dot(v, v) + (b * b);
 
 	if (det < 0.0 || b < s.r)
 	{
@@ -45,16 +45,14 @@ float ray_sphere_intersection(const Vector3& from, const Vector3& dir, const Sph
 // http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/picking-with-custom-ray-obb-function/
 float ray_oobb_intersection(const Vector3& from, const Vector3& dir, const OBB& obb)
 {
-	using namespace vector3;
-
 	float tmin = 0.0f;
 	float tmax = 100000.0f;
 
-	Vector3 obb_pos(obb.tm.t.x, obb.tm.t.y, obb.tm.t.z);
+	Vector3 obb_pos = vector3(obb.tm.t.x, obb.tm.t.y, obb.tm.t.z);
 	Vector3 delta = obb_pos - from;
 
 	{
-		const Vector3 xaxis(obb.tm.x.x, obb.tm.x.y, obb.tm.x.z);
+		const Vector3 xaxis = vector3(obb.tm.x.x, obb.tm.x.y, obb.tm.x.z);
 		float e = dot(xaxis, delta);
 		float f = dot(dir, xaxis);
 
@@ -84,7 +82,7 @@ float ray_oobb_intersection(const Vector3& from, const Vector3& dir, const OBB&
 	}
 
 	{
-		const Vector3 yaxis(obb.tm.y.x, obb.tm.y.y, obb.tm.y.z);
+		const Vector3 yaxis = vector3(obb.tm.y.x, obb.tm.y.y, obb.tm.y.z);
 		float e = dot(yaxis, delta);
 		float f = dot(dir, yaxis);
 
@@ -111,7 +109,7 @@ float ray_oobb_intersection(const Vector3& from, const Vector3& dir, const OBB&
 	}
 
 	{
-		const Vector3 zaxis(obb.tm.z.x, obb.tm.z.y, obb.tm.z.z);
+		const Vector3 zaxis = vector3(obb.tm.z.x, obb.tm.z.y, obb.tm.z.z);
 		float e = dot(zaxis, delta);
 		float f = dot(dir, zaxis);
 
@@ -147,14 +145,14 @@ bool plane_3_intersection(const Plane& p1, const Plane& p2, const Plane& p3, Vec
 	const Vector3& n2 = p2.n;
 	const Vector3& n3 = p3.n;
 
-	float den = -vector3::dot(vector3::cross(n1, n2), n3);
+	float den = -dot(cross(n1, n2), n3);
 
 	if (equals(den, (float)0.0))
 	{
 		return false;
 	}
 
-	Vector3 res = p1.d * vector3::cross(n2, n3) + p2.d * vector3::cross(n3, n1) + p3.d * vector3::cross(n1, n2);
+	Vector3 res = p1.d * cross(n2, n3) + p2.d * cross(n3, n1) + p3.d * cross(n1, n2);
 	ip = res / den;
 
 	return true;

+ 0 - 103
src/core/math/math_types.h

@@ -15,136 +15,42 @@ namespace crown
 /// @ingroup Math
 struct Vector2
 {
-	Vector2();
-	Vector2(float val);
-	Vector2(float nx, float ny);
-	Vector2(const float v[2]);
-
-	float& operator[](uint32_t i);
-	const float& operator[](uint32_t i) const;
-
-	Vector2& operator+=(const Vector2& a);
-	Vector2& operator-=(const Vector2& a);
-	Vector2& operator*=(float k);
-	Vector2& operator/=(float k);
-
 	float x, y;
 };
 
 /// @ingroup Math
 struct Vector3
 {
-	Vector3();
-	Vector3(float val);
-	Vector3(float nx, float ny, float nz);
-	Vector3(const float v[3]);
-
-	float& operator[](uint32_t i);
-	const float& operator[](uint32_t i) const;
-
-	Vector3& operator+=(const Vector3& a);
-	Vector3& operator-=(const Vector3& a);
-	Vector3& operator*=(float k);
-	Vector3& operator/=(float k);
-
 	float x, y, z;
 };
 
 /// @ingroup Math
 struct Vector4
 {
-	Vector4();
-	Vector4(const Vector3& a, float w);
-	Vector4(float val);
-	Vector4(float nx, float ny, float nz, float nw);
-	Vector4(const float v[4]);
-
-	float& operator[](uint32_t i);
-	const float& operator[](uint32_t i) const;
-
-	Vector4& operator+=(const Vector4& a);
-	Vector4& operator-=(const Vector4& a);
-	Vector4& operator*=(float k);
-	Vector4& operator/=(float k);
-
 	float x, y, z, w;
 };
 
 /// @ingroup Math
 struct Quaternion
 {
-	Quaternion();
-	Quaternion(float nx, float ny, float nz, float nw);
-	Quaternion(const Vector3& axis, float angle);
-
-	float& operator[](uint32_t i);
-	const float& operator[](uint32_t i) const;
-
-	Quaternion& operator*=(const Quaternion& a);
-
 	float x, y, z, w;
 };
 
 /// @ingroup Math
 struct Matrix3x3
 {
-	Matrix3x3();
-	Matrix3x3(const Vector3& x, const Vector3& y, const Vector3& z);
-	Matrix3x3(const Quaternion& r);
-
-	Matrix3x3(float r1c1, float r2c1, float r3c1,
-		float r1c2, float r2c2, float r3c2,
-		float r1c3, float r2c3, float r3c3);
-
-	Matrix3x3(const float v[9]);
-
-	float& operator[](uint32_t i);
-	const float& operator[](uint32_t i) const;
-
-	Matrix3x3& operator+=(const Matrix3x3& a);
-	Matrix3x3& operator-=(const Matrix3x3& a);
-	Matrix3x3& operator*=(const Matrix3x3& a);
-	Matrix3x3& operator*=(float k);
-	Matrix3x3& operator/=(float k);
-
 	Vector3 x, y, z;
 };
 
 /// @ingroup Math
 struct Matrix4x4
 {
-	Matrix4x4();
-	Matrix4x4(const Vector3& x, const Vector3& y, const Vector3& z, const Vector3& t);
-	Matrix4x4(const Quaternion& r, const Vector3& p);
-	Matrix4x4(const Matrix3x3& m);
-
-	Matrix4x4(float r1c1, float r2c1, float r3c1, float r4c1,
-		float r1c2, float r2c2, float r3c2, float r4c2,
-		float r1c3, float r2c3, float r3c3, float r4c3,
-		float r1c4, float r2c4, float r3c4, float r4c4);
-
-	Matrix4x4(const float v[16]);
-
-	float& operator[](uint32_t i);
-	const float& operator[](uint32_t i) const;
-
-	Matrix4x4& operator+=(const Matrix4x4& a);
-	Matrix4x4& operator-=(const Matrix4x4& a);
-	Matrix4x4& operator*=(const Matrix4x4& a);
-	Matrix4x4& operator*=(float k);
-	Matrix4x4& operator/=(float k);
-
 	Vector4 x, y, z, t;
 };
 
 /// @ingroup Math
 struct AABB
 {
-	AABB();
-
-	/// Constructs from @a min and @a max.
-	AABB(const Vector3& min, const Vector3& max);
-
 	Vector3 min;
 	Vector3 max;
 };
@@ -163,10 +69,6 @@ struct OBB
 /// @ingroup Math
 struct Plane
 {
-	/// Does nothing for efficiency.
-	Plane();
-	Plane(const Vector3& n, float d);
-
 	Vector3 n;
 	float d;
 };
@@ -174,8 +76,6 @@ struct Plane
 /// @ingroup Math
 struct Frustum
 {
-	Frustum();
-
 	Plane left;
 	Plane right;
 	Plane bottom;
@@ -187,9 +87,6 @@ struct Frustum
 /// @ingroup Math
 struct Sphere
 {
-	Sphere();
-	Sphere(const Vector3& nc, float nr);
-
 	Vector3 c;
 	float r;
 };

+ 213 - 291
src/core/math/matrix3x3.h

@@ -13,396 +13,318 @@
 namespace crown
 {
 
-/// Adds the matrix @a a to @a b and returns the result.
-Matrix3x3 operator+(Matrix3x3 a, const Matrix3x3& b);
-
-/// Subtracts the matrix @a b from @a a and returns the result.
-Matrix3x3 operator-(Matrix3x3 a, const Matrix3x3& b);
-
-/// Multiplies the matrix @a a by the scalar @a k and returns the result.
-Matrix3x3 operator*(Matrix3x3 a, float k);
-
-/// @copydoc operator*(Matrix3x3, float)
-Matrix3x3 operator*(float k, Matrix3x3 a);
-
-/// Divides the matrix @a a by the scalar @a k.
-Matrix3x3 operator/(Matrix3x3 a, float k);
-
-/// Multiplies the matrix @a a by the vector @a v and returns the result.
-Vector3 operator*(const Vector3& v, const Matrix3x3& a);
-
-/// Multiplies the matrix @a a by @a b and returns the result. (i.e. transforms first by @a a then by @a b)
-Matrix3x3 operator*(Matrix3x3 a, const Matrix3x3& b);
-
 /// Functions to manipulate Matrix3x3
 ///
 /// @ingroup Math
-namespace matrix3x3
-{
-	const Matrix3x3 IDENTITY = Matrix3x3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
-
-	/// Transposes the matrix @a m and returns the result.
-	Matrix3x3& transpose(Matrix3x3& m);
+const Matrix3x3 IDENTITY = { {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0} };
 
-	/// Returns the transposed of the matrix @a m.
-	Matrix3x3 get_transposed(Matrix3x3 m);
-
-	/// Returns the determinant of the matrix @a m.
-	float determinant(const Matrix3x3& m);
+inline Matrix3x3 matrix3x3(const Vector3& x, const Vector3& y, const Vector3& z)
+{
+	Matrix3x3 m;
+	m.x = x;
+	m.y = y;
+	m.z = z;
+	return m;
+}
 
-	/// Inverts the matrix @a m and returns the result.
-	Matrix3x3& invert(Matrix3x3& m);
+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);
+	return m;
+}
 
-	/// Returns the inverse of the matrix @a m.
-	Matrix3x3 get_inverted(Matrix3x3 m);
+inline Matrix3x3& operator+=(Matrix3x3& a, const Matrix3x3& b)
+{
+	a.x += b.x;
+	a.y += b.y;
+	a.z += b.z;
+	return a;
+}
 
-	/// Sets the matrix @a m to identity.
-	void set_identity(Matrix3x3& m);
+inline Matrix3x3& operator-=(Matrix3x3& a, const Matrix3x3& b)
+{
+	a.x -= b.x;
+	a.y -= b.y;
+	a.z -= b.z;
+	return a;
+}
 
-	/// Returns the rotation portion of the matrix @a m as a Quaternion.
-	Quaternion rotation(const Matrix3x3& m);
+inline Matrix3x3& operator*=(Matrix3x3& a, float k)
+{
+	a.x *= k;
+	a.y *= k;
+	a.z *= k;
+	return a;
+}
 
-	/// Returns the scale of the matrix @a m.
-	Vector3 scale(const Matrix3x3& m);
+inline Matrix3x3& operator/=(Matrix3x3& a, float k)
+{
+	const float inv_k = 1.0f / k;
+	a.x *= inv_k;
+	a.y *= inv_k;
+	a.z *= inv_k;
+	return a;
+}
 
-	/// Sets the scale of the matrix @a m.
-	void set_scale(Matrix3x3& m, const Vector3& s);
+inline Matrix3x3& operator*=(Matrix3x3& a, const Matrix3x3& b)
+{
+	Matrix3x3 tmp;
+	tmp.x.x = a.x.x*b.x.x + a.x.y*b.y.x + a.x.z*b.z.x;
+	tmp.x.y = a.x.x*b.x.y + a.x.y*b.y.y + a.x.z*b.z.y;
+	tmp.x.z = a.x.x*b.x.z + a.x.y*b.y.z + a.x.z*b.z.z;
 
-	/// Returns the pointer to the matrix's data
-	float* to_float_ptr(Matrix3x3& m);
+	tmp.y.x = a.y.x*b.x.x + a.y.y*b.y.x + a.y.z*b.z.x;
+	tmp.y.y = a.y.x*b.x.y + a.y.y*b.y.y + a.y.z*b.z.y;
+	tmp.y.z = a.y.x*b.x.z + a.y.y*b.y.z + a.y.z*b.z.z;
 
-	/// Returns the pointer to the matrix's data
-	const float* to_float_ptr(const Matrix3x3& m);
+	tmp.z.x = a.z.x*b.x.x + a.z.y*b.y.x + a.z.z*b.z.x;
+	tmp.z.y = a.z.x*b.x.y + a.z.y*b.y.y + a.z.z*b.z.y;
+	tmp.z.z = a.z.x*b.x.z + a.z.y*b.y.z + a.z.z*b.z.z;
 
-	/// Returns a 4x4 matrix according to the matrix's rotation portion
-	Matrix4x4 to_matrix4x4(const Matrix3x3& m);
-} // namespace matrix3x3
+	a = tmp;
+	return a;
+}
 
+/// Adds the matrix @a a to @a b and returns the result.
 inline Matrix3x3 operator+(Matrix3x3 a, const Matrix3x3& b)
 {
 	a += b;
 	return a;
 }
 
+/// Subtracts the matrix @a b from @a a and returns the result.
 inline Matrix3x3 operator-(Matrix3x3 a, const Matrix3x3& b)
 {
 	a -= b;
 	return a;
 }
 
+/// Multiplies the matrix @a a by the scalar @a k and returns the result.
 inline Matrix3x3 operator*(Matrix3x3 a, float k)
 {
 	a *= k;
 	return a;
 }
 
+/// @copydoc operator*(Matrix3x3, float)
 inline Matrix3x3 operator*(float k, Matrix3x3 a)
 {
 	a *= k;
 	return a;
 }
 
+/// Divides the matrix @a a by the scalar @a k.
 inline Matrix3x3 operator/(Matrix3x3 a, float k)
 {
 	a /= k;
 	return a;
 }
 
+/// 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(
+	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
 	);
 }
 
+/// Multiplies the matrix @a a by @a b and returns the result. (i.e. transforms first by @a a then by @a b)
 inline Matrix3x3 operator*(Matrix3x3 a, const Matrix3x3& b)
 {
 	a *= b;
 	return a;
 }
 
-namespace matrix3x3
+/// Transposes the matrix @a m and returns the result.
+inline Matrix3x3& transpose(Matrix3x3& m)
 {
-	inline Matrix3x3& transpose(Matrix3x3& m)
-	{
-		float tmp;
+	float tmp;
 
-		tmp = m.x.y;
-		m.x.y = m.y.x;
-		m.y.x = tmp;
+	tmp = m.x.y;
+	m.x.y = m.y.x;
+	m.y.x = tmp;
 
-		tmp = m.x.z;
-		m.x.z = m.z.x;
-		m.z.x = tmp;
+	tmp = m.x.z;
+	m.x.z = m.z.x;
+	m.z.x = tmp;
 
-		tmp = m.y.z;
-		m.y.z = m.z.y;
-		m.z.y = tmp;
+	tmp = m.y.z;
+	m.y.z = m.z.y;
+	m.z.y = tmp;
 
-		return m;
-	}
+	return m;
+}
 
-	inline Matrix3x3 get_transposed(Matrix3x3 m)
-	{
-		transpose(m);
-		return m;
-	}
+/// Returns the transposed of the matrix @a m.
+inline Matrix3x3 get_transposed(Matrix3x3 m)
+{
+	transpose(m);
+	return m;
+}
 
-	inline float determinant(const Matrix3x3& m)
-	{
-		return	m.x.x * (m.y.y * m.z.z - m.z.y * m.y.z) -
-				m.y.x * (m.x.y * m.z.z - m.z.y * m.x.z) +
-				m.z.x * (m.x.y * m.y.z - m.y.y * m.x.z);
-	}
+/// Returns the determinant of the matrix @a m.
+inline float determinant(const Matrix3x3& m)
+{
+	return	m.x.x * (m.y.y * m.z.z - m.z.y * m.y.z) -
+			m.y.x * (m.x.y * m.z.z - m.z.y * m.x.z) +
+			m.z.x * (m.x.y * m.y.z - m.y.y * m.x.z);
+}
 
-	inline Matrix3x3& invert(Matrix3x3& m)
-	{
-		Matrix3x3 mat;
-
-		mat.x.x = (m.y.y * m.z.z - m.z.y * m.y.z);
-		mat.x.y = (m.x.y * m.z.z - m.z.y * m.x.z);
-		mat.x.z = (m.x.y * m.y.z - m.y.y * m.x.z);
-
-		const float inv_det = 1.0f / (m.x.x * mat.x.x - m.y.x * mat.x.y + m.z.x * mat.x.z);
-
-		mat.y.x = (m.y.x * m.z.z - m.z.x * m.y.z);
-		mat.y.y = (m.x.x * m.z.z - m.z.x * m.x.z);
-		mat.y.z = (m.x.x * m.y.z - m.y.x * m.x.z);
-		mat.z.x = (m.y.x * m.z.y - m.z.x * m.y.y);
-		mat.z.y = (m.x.x * m.z.y - m.z.x * m.x.y);
-		mat.z.z = (m.x.x * m.y.y - m.y.x * m.x.y);
-
-		m.x.x = + mat.x.x * inv_det;
-		m.x.y = - mat.x.y * inv_det;
-		m.x.z = + mat.x.z * inv_det;
-		m.y.x = - mat.y.x * inv_det;
-		m.y.y = + mat.y.y * inv_det;
-		m.y.z = - mat.y.z * inv_det;
-		m.z.x = + mat.z.x * inv_det;
-		m.z.y = - mat.z.y * inv_det;
-		m.z.z = + mat.z.z * inv_det;
-
-		return m;
-	}
+/// Inverts the matrix @a m and returns the result.
+inline Matrix3x3& invert(Matrix3x3& m)
+{
+	Matrix3x3 mat;
+
+	mat.x.x = (m.y.y * m.z.z - m.z.y * m.y.z);
+	mat.x.y = (m.x.y * m.z.z - m.z.y * m.x.z);
+	mat.x.z = (m.x.y * m.y.z - m.y.y * m.x.z);
+
+	const float inv_det = 1.0f / (m.x.x * mat.x.x - m.y.x * mat.x.y + m.z.x * mat.x.z);
+
+	mat.y.x = (m.y.x * m.z.z - m.z.x * m.y.z);
+	mat.y.y = (m.x.x * m.z.z - m.z.x * m.x.z);
+	mat.y.z = (m.x.x * m.y.z - m.y.x * m.x.z);
+	mat.z.x = (m.y.x * m.z.y - m.z.x * m.y.y);
+	mat.z.y = (m.x.x * m.z.y - m.z.x * m.x.y);
+	mat.z.z = (m.x.x * m.y.y - m.y.x * m.x.y);
+
+	m.x.x = + mat.x.x * inv_det;
+	m.x.y = - mat.x.y * inv_det;
+	m.x.z = + mat.x.z * inv_det;
+	m.y.x = - mat.y.x * inv_det;
+	m.y.y = + mat.y.y * inv_det;
+	m.y.z = - mat.y.z * inv_det;
+	m.z.x = + mat.z.x * inv_det;
+	m.z.y = - mat.z.y * inv_det;
+	m.z.z = + mat.z.z * inv_det;
+
+	return m;
+}
+
+/// Returns the inverse of the matrix @a m.
+inline Matrix3x3 get_inverted(Matrix3x3 m)
+{
+	invert(m);
+	return 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);
+}
 
-	inline Matrix3x3 get_inverted(Matrix3x3 m)
+/// Returns the rotation portion of the matrix @a m as a Quaternion.
+inline Quaternion rotation(const Matrix3x3& m)
+{
+	const float ww = m.x.x + m.y.y + m.z.z;
+	const float xx = m.x.x - m.y.y - m.z.z;
+	const float yy = m.y.y - m.x.x - m.z.z;
+	const float zz = m.z.z - m.x.x - m.y.y;
+	float max = ww;
+	uint32_t index = 0;
+
+	if (xx > max)
 	{
-		invert(m);
-		return m;
+		max = xx;
+		index = 1;
 	}
 
-	inline void set_identity(Matrix3x3& m)
+	if (yy > max)
 	{
-		m.x = Vector3(1, 0, 0);
-		m.y = Vector3(0, 1, 0);
-		m.z = Vector3(0, 0, 1);
+		max = yy;
+		index = 2;
 	}
 
-	inline Matrix4x4 to_matrix4x4(const Matrix3x3& m)
+	if (zz > max)
 	{
-		return Matrix4x4(m);
+		max = zz;
+		index = 3;
 	}
 
-	inline Quaternion rotation(const Matrix3x3& m)
+	const float biggest = sqrt(max + 1.0f) * 0.5f;
+	const float mult = 0.25f / biggest;
+
+	Quaternion tmp;
+	switch (index)
 	{
-		const float ww = m.x.x + m.y.y + m.z.z;
-		const float xx = m.x.x - m.y.y - m.z.z;
-		const float yy = m.y.y - m.x.x - m.z.z;
-		const float zz = m.z.z - m.x.x - m.y.y;
-		float max = ww;
-		uint32_t index = 0;
-
-		if (xx > max)
+		case 0:
 		{
-			max = xx;
-			index = 1;
+			tmp.w = biggest;
+			tmp.x = (m.y.z - m.z.y) * mult;
+			tmp.y = (m.z.x - m.x.z) * mult;
+			tmp.z = (m.x.y - m.y.x) * mult;
+			break;
 		}
-
-		if (yy > max)
+		case 1:
 		{
-			max = yy;
-			index = 2;
+			tmp.x = biggest;
+			tmp.w = (m.y.z - m.z.y) * mult;
+			tmp.y = (m.x.y + m.y.x) * mult;
+			tmp.z = (m.z.x + m.x.z) * mult;
+			break;
 		}
-
-		if (zz > max)
+		case 2:
 		{
-			max = zz;
-			index = 3;
+			tmp.y = biggest;
+			tmp.w = (m.z.x - m.x.z) * mult;
+			tmp.x = (m.x.y + m.y.x) * mult;
+			tmp.z = (m.y.z + m.z.y) * mult;
+			break;
 		}
-
-		const float biggest = sqrt(max + 1.0f) * 0.5f;
-		const float mult = 0.25f / biggest;
-
-		Quaternion tmp;
-		switch (index)
+		case 3:
 		{
-			case 0:
-			{
-				tmp.w = biggest;
-				tmp.x = (m.y.z - m.z.y) * mult;
-				tmp.y = (m.z.x - m.x.z) * mult;
-				tmp.z = (m.x.y - m.y.x) * mult;
-				break;
-			}
-			case 1:
-			{
-				tmp.x = biggest;
-				tmp.w = (m.y.z - m.z.y) * mult;
-				tmp.y = (m.x.y + m.y.x) * mult;
-				tmp.z = (m.z.x + m.x.z) * mult;
-				break;
-			}
-			case 2:
-			{
-				tmp.y = biggest;
-				tmp.w = (m.z.x - m.x.z) * mult;
-				tmp.x = (m.x.y + m.y.x) * mult;
-				tmp.z = (m.y.z + m.z.y) * mult;
-				break;
-			}
-			case 3:
-			{
-				tmp.z = biggest;
-				tmp.w = (m.x.y - m.y.x) * mult;
-				tmp.x = (m.z.x + m.x.z) * mult;
-				tmp.y = (m.y.z + m.z.y) * mult;
-				break;
-			}
-			default:
-			{
-				CE_FATAL("You should not be here");
-				break;
-			}
+			tmp.z = biggest;
+			tmp.w = (m.x.y - m.y.x) * mult;
+			tmp.x = (m.z.x + m.x.z) * mult;
+			tmp.y = (m.y.z + m.z.y) * mult;
+			break;
+		}
+		default:
+		{
+			CE_FATAL("You should not be here");
+			break;
 		}
-
-		quaternion::normalize(tmp);
-		return tmp;
-	}
-
-	inline Vector3 scale(const Matrix3x3& m)
-	{
-		using namespace vector3;
-		const float sx = length(m.x);
-		const float sy = length(m.y);
-		const float sz = length(m.z);
-		return Vector3(sx, sy, sz);
-	}
-
-	inline void set_scale(Matrix3x3& m, const Vector3& s)
-	{
-		using namespace vector3;
-		set_length(m.x, s.x);
-		set_length(m.y, s.y);
-		set_length(m.z, s.z);
 	}
-} // namespace matrix3x3
-
-inline Matrix3x3::Matrix3x3()
-{
-	// Do not initialize
-}
-
-inline Matrix3x3::Matrix3x3(const Vector3& x, const Vector3& y, const Vector3& z)
-	: x(x)
-	, y(y)
-	, z(z)
-{
-}
-
-inline Matrix3x3::Matrix3x3(const Quaternion& r)
-	: x(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)
-	, y(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)
-	, z(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)
-{
-}
-
-inline Matrix3x3::Matrix3x3(float r1c1, float r2c1, float r3c1, float r1c2, float r2c2, float r3c2,
-						float r1c3, float r2c3, float r3c3)
-	: x(r1c1, r2c1, r3c1)
-	, y(r1c2, r2c2, r3c2)
-	, z(r1c3, r2c3, r3c3)
-{
-}
-
-inline Matrix3x3::Matrix3x3(const float v[9])
-	: x(v[0], v[1], v[2])
-	, y(v[3], v[4], v[5])
-	, z(v[6], v[7], v[8])
-{
-}
-
-inline float& Matrix3x3::operator[](uint32_t i)
-{
-	CE_ASSERT(i < 9, "Index out of bounds");
-
-	return vector3::to_float_ptr(x)[i];
-}
-
-inline const float& Matrix3x3::operator[](uint32_t i) const
-{
-	CE_ASSERT(i < 9, "Index out of bounds");
-
-	return vector3::to_float_ptr(x)[i];
-}
-
-inline Matrix3x3& Matrix3x3::operator+=(const Matrix3x3& a)
-{
-	x += a.x;
-	y += a.y;
-	z += a.z;
 
-	return *this;
+	normalize(tmp);
+	return tmp;
 }
 
-inline Matrix3x3& Matrix3x3::operator-=(const Matrix3x3& a)
+/// Returns the scale of the matrix @a m.
+inline Vector3 scale(const Matrix3x3& m)
 {
-	x -= a.x;
-	y -= a.y;
-	z -= a.z;
-
-	return *this;
+	const float sx = length(m.x);
+	const float sy = length(m.y);
+	const float sz = length(m.z);
+	return vector3(sx, sy, sz);
 }
 
-inline Matrix3x3& Matrix3x3::operator*=(float k)
+/// Sets the scale of the matrix @a m.
+inline void set_scale(Matrix3x3& m, const Vector3& s)
 {
-	x *= k;
-	y *= k;
-	z *= k;
-
-	return *this;
+	set_length(m.x, s.x);
+	set_length(m.y, s.y);
+	set_length(m.z, s.z);
 }
 
-inline Matrix3x3& Matrix3x3::operator/=(float k)
+/// Returns the pointer to the matrix's data
+inline float* to_float_ptr(Matrix3x3& m)
 {
-	const float inv_k = 1.0f / k;
-
-	x *= inv_k;
-	y *= inv_k;
-	z *= inv_k;
-
-	return *this;
+	return &m.x.x;
 }
 
-inline Matrix3x3& Matrix3x3::operator*=(const Matrix3x3& a)
+/// Returns the pointer to the matrix's data
+inline const float* to_float_ptr(const Matrix3x3& m)
 {
-	Matrix3x3 tmp(
-		x.x*a.x.x + x.y*a.y.x + x.z*a.z.x,
-		x.x*a.x.y + x.y*a.y.y + x.z*a.z.y,
-		x.x*a.x.z + x.y*a.y.z + x.z*a.z.z,
-
-		y.x*a.x.x + y.y*a.y.x + y.z*a.z.x,
-		y.x*a.x.y + y.y*a.y.y + y.z*a.z.y,
-		y.x*a.x.z + y.y*a.y.z + y.z*a.z.z,
-
-		z.x*a.x.x + z.y*a.y.x + z.z*a.z.x,
-		z.x*a.x.y + z.y*a.y.y + z.z*a.z.y,
-		z.x*a.x.z + z.y*a.y.z + z.z*a.z.z
-	);
-
-	*this = tmp;
-	return *this;
+	return &m.x.x;
 }
 
 } // namespace crown

+ 426 - 480
src/core/math/matrix4x4.h

@@ -14,155 +14,208 @@
 namespace crown
 {
 
-/// Adds the matrix @a a to @a b and returns the result.
-Matrix4x4 operator+(Matrix4x4 a, const Matrix4x4& b);
-
-/// Subtracts the matrix @a b from @a a and returns the result.
-Matrix4x4 operator-(Matrix4x4 a, const Matrix4x4& b);
-
-/// Multiplies the matrix @a a by the scalar @a k and returns the result.
-Matrix4x4 operator*(Matrix4x4 a, float k);
-
-/// @copydoc operator*(Matrix4x4, float)
-Matrix4x4 operator*(float k, Matrix4x4 a);
-
-/// Divides the matrix @a a by the scalar @a k and returns the result.
-Matrix4x4 operator/(Matrix4x4 a, float k);
-
-/// Multiplies the matrix @a a by the vector @a v and returns the result.
-Vector3 operator*(const Vector3& v, const Matrix4x4& a);
-
-/// Multiplies the matrix @a by the vector @a v and returns the result.
-Vector4 operator*(const Vector4& v, const Matrix4x4& a);
-
-/// Multiplies the matrix @a a by @a b and returns the result. (i.e. transforms first by @a a then by @a b)
-Matrix4x4 operator*(Matrix4x4 a, const Matrix4x4& b);
-
 /// Functions to manipulate Matrix4x4.
 ///
 /// @ingroup Math
-namespace matrix4x4
-{
-	const Matrix4x4 IDENTITY = Matrix4x4(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);
-
-	/// Sets the matrix @a m to perspective.
-	void set_perspective(Matrix4x4& m, float fovy, float aspect, float near, float far);
-
-	/// Sets the matrix @a m to orthographic.
-	void set_orthographic(Matrix4x4& m, float left, float right, float bottom, float top, float near, float far);
-
-	/// Sets the matrix @a m to look.
-	void set_look(Matrix4x4& m, const Vector3& pos, const Vector3& target, const Vector3& up);
-
-	/// Transposes the matrix @a m and returns the result.
-	Matrix4x4& transpose(Matrix4x4& m);
-
-	/// Returns the transposed of the matrix @a m.
-	Matrix4x4 get_transposed(Matrix4x4 m);
-
-	/// Returns the determinant of the matrix @a m.
-	float determinant(const Matrix4x4& m);
-
-	/// Inverts the matrix @a m and returns the result.
-	Matrix4x4& invert(Matrix4x4& m);
+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 } };
 
-	/// Returns the inverse of the matrix @a m.
-	Matrix4x4 get_inverted(Matrix4x4 m);
-
-	/// Sets the matrix @a m to identity.
-	void set_identity(Matrix4x4& m);
-
-	/// Returns the x asis of the matrix @a m.
-	Vector3 x(const Matrix4x4& m);
-
-	/// Returns the y axis of the matrix @a m.
-	Vector3 y(const Matrix4x4& m);
+inline Matrix4x4 matrix4x4(float r1c1, float r2c1, float r3c1, float r4c1,
+	float r1c2, float r2c2, float r3c2, float r4c2,
+	float r1c3, float r2c3, float r3c3, float r4c3,
+	float r1c4, float r2c4, float r3c4, float r4c4)
+{
+	Matrix4x4 m;
+	m.x.x = r1c1;
+	m.x.y = r1c2;
+	m.x.z = r1c3;
+	m.x.w = r1c4;
+
+	m.y.x = r2c1;
+	m.y.y = r2c2;
+	m.y.z = r2c3;
+	m.y.w = r2c4;
+
+	m.z.x = r3c1;
+	m.z.y = r3c2;
+	m.z.z = r3c3;
+	m.z.w = r3c4;
+
+	m.t.x = r4c1;
+	m.t.y = r4c2;
+	m.t.z = r4c3;
+	m.t.w = r4c4;
+	return m;
+}
 
-	/// Returns the z axis of the matrix @a m.
-	Vector3 z(const Matrix4x4& m);
+inline Matrix4x4 matrix4x4(const float a[16])
+{
+	Matrix4x4 m;
+	m.x.x = a[0];
+	m.x.y = a[1];
+	m.x.z = a[2];
+	m.x.w = a[3];
+
+	m.y.x = a[4];
+	m.y.y = a[5];
+	m.y.z = a[6];
+	m.y.w = a[7];
+
+	m.z.x = a[8];
+	m.z.y = a[9];
+	m.z.z = a[10];
+	m.z.w = a[11];
+
+	m.t.x = a[12];
+	m.t.y = a[13];
+	m.t.z = a[14];
+	m.t.w = a[15];
+	return m;
+}
 
-	/// Sets the x axis of the matrix @a m.
-	void set_x(Matrix4x4& m, const Vector3& x);
+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);
+	return m;
+}
 
-	/// Sets the y axis of the matrix @a m.
-	void set_y(Matrix4x4& m, const Vector3& y);
+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);
+	return m;
+}
 
-	/// Sets the z axis of the matrix @a m.
-	void set_z(Matrix4x4& m, const Vector3& z);
+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);
+	return m;
+}
 
-	/// Returns the translation portion of the matrix @a m.
-	Vector3 translation(const Matrix4x4& m);
+inline Matrix4x4& operator+=(Matrix4x4& a, const Matrix4x4& b)
+{
+	a.x += b.x;
+	a.y += b.y;
+	a.z += b.z;
+	a.t += b.t;
+	return a;
+}
 
-	/// Sets the translation portion of the matrix @a m.
-	void set_translation(Matrix4x4& m, const Vector3& trans);
+inline Matrix4x4& operator-=(Matrix4x4& a, const Matrix4x4& b)
+{
+	a.x -= b.x;
+	a.y -= b.y;
+	a.z -= b.z;
+	a.t -= b.t;
+	return a;
+}
 
-	/// Returns the rotation portion of the matrix @a m as a Quaternion.
-	Quaternion rotation(const Matrix4x4& m);
+inline Matrix4x4& operator*=(Matrix4x4& a, float k)
+{
+	a.x *= k;
+	a.y *= k;
+	a.z *= k;
+	a.t *= k;
+	return a;
+}
 
-	/// Sets the rotation portion of the matrix @a m.
-	void set_rotation(Matrix4x4& m, const Quaternion& rot);
+inline Matrix4x4& operator/=(Matrix4x4& a, float k)
+{
+	const float inv_k = 1.0f / k;
+	a.x *= inv_k;
+	a.y *= inv_k;
+	a.z *= inv_k;
+	a.t *= inv_k;
+	return a;
+}
 
-	/// Sets the rotation portion of the matrix @a m.
-	void set_rotation(Matrix4x4& m, const Matrix3x3& rot);
+inline Matrix4x4& operator*=(Matrix4x4& a, const Matrix4x4& b)
+{
+	Matrix4x4 tmp;
 
-	/// Returns the scale of the matrix @a m.
-	Vector3 scale(const Matrix4x4& m);
+	tmp.x.x = a.x.x*b.x.x + a.x.y*b.y.x + a.x.z*b.z.x + a.x.w*b.t.x;
+	tmp.x.y = a.x.x*b.x.y + a.x.y*b.y.y + a.x.z*b.z.y + a.x.w*b.t.y;
+	tmp.x.z = a.x.x*b.x.z + a.x.y*b.y.z + a.x.z*b.z.z + a.x.w*b.t.z;
+	tmp.x.w = a.x.x*b.x.w + a.x.y*b.y.w + a.x.z*b.z.w + a.x.w*b.t.w;
 
-	/// Sets the scale of the matrix @æ m.
-	void set_scale(Matrix4x4& m, const Vector3& s);
+	tmp.y.x = a.y.x*b.x.x + a.y.y*b.y.x + a.y.z*b.z.x + a.y.w*b.t.x;
+	tmp.y.y = a.y.x*b.x.y + a.y.y*b.y.y + a.y.z*b.z.y + a.y.w*b.t.y;
+	tmp.y.z = a.y.x*b.x.z + a.y.y*b.y.z + a.y.z*b.z.z + a.y.w*b.t.z;
+	tmp.y.w = a.y.x*b.x.w + a.y.y*b.y.w + a.y.z*b.z.w + a.y.w*b.t.w;
 
-	/// Returns the pointer to the matrix's data
-	float* to_float_ptr(Matrix4x4& m);
+	tmp.z.x = a.z.x*b.x.x + a.z.y*b.y.x + a.z.z*b.z.x + a.z.w*b.t.x;
+	tmp.z.y = a.z.x*b.x.y + a.z.y*b.y.y + a.z.z*b.z.y + a.z.w*b.t.y;
+	tmp.z.z = a.z.x*b.x.z + a.z.y*b.y.z + a.z.z*b.z.z + a.z.w*b.t.z;
+	tmp.z.w = a.z.x*b.x.w + a.z.y*b.y.w + a.z.z*b.z.w + a.z.w*b.t.w;
 
-	/// Returns the pointer to the first elemento of the matrix @a m.
-	const float* to_float_ptr(const Matrix4x4& m);
+	tmp.t.x = a.t.x*b.x.x + a.t.y*b.y.x + a.t.z*b.z.x + a.t.w*b.t.x;
+	tmp.t.y = a.t.x*b.x.y + a.t.y*b.y.y + a.t.z*b.z.y + a.t.w*b.t.y;
+	tmp.t.z = a.t.x*b.x.z + a.t.y*b.y.z + a.t.z*b.z.z + a.t.w*b.t.z;
+	tmp.t.w = a.t.x*b.x.w + a.t.y*b.y.w + a.t.z*b.z.w + a.t.w*b.t.w;
 
-	/// Returns the rotation portion of the matrix @a m as a Matrix3x3.
-	Matrix3x3 to_matrix3x3(const Matrix4x4& m);
-} // namespace matrix4x4
+	a = tmp;
+	return a;
+}
 
+/// Adds the matrix @a a to @a b and returns the result.
 inline Matrix4x4 operator+(Matrix4x4 a, const Matrix4x4& b)
 {
 	a += b;
 	return a;
 }
 
+/// Subtracts the matrix @a b from @a a and returns the result.
 inline Matrix4x4 operator-(Matrix4x4 a, const Matrix4x4& b)
 {
 	a -= b;
 	return a;
 }
 
+/// Multiplies the matrix @a a by the scalar @a k and returns the result.
 inline Matrix4x4 operator*(Matrix4x4 a, float k)
 {
 	a *= k;
 	return a;
 }
 
+/// @copydoc operator*(Matrix4x4, float)
 inline Matrix4x4 operator*(float k, Matrix4x4 a)
 {
 	a *= k;
 	return a;
 }
 
+/// Divides the matrix @a a by the scalar @a k and returns the result.
 inline Matrix4x4 operator/(Matrix4x4 a, float k)
 {
 	a /= k;
 	return a;
 }
 
+/// 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(
+	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
 	);
 }
 
+/// Multiplies the matrix @a by the vector @a v and returns the result.
 inline Vector4 operator*(const Vector4& v, const Matrix4x4& a)
 {
-	return Vector4(
+	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,
@@ -170,453 +223,346 @@ inline Vector4 operator*(const Vector4& v, const Matrix4x4& a)
 	);
 }
 
+/// Multiplies the matrix @a a by @a b and returns the result. (i.e. transforms first by @a a then by @a b)
 inline Matrix4x4 operator*(Matrix4x4 a, const Matrix4x4& b)
 {
 	a *= b;
 	return a;
 }
 
-namespace matrix4x4
-{
-	inline void set_perspective(Matrix4x4& m, float fovy, float aspect, float near, float far)
-	{
-		const float height = 1.0f / tan(fovy * ((float) PI / 180.0f) * 0.5f);
-		const float width = height * 1.0f / aspect;
-		const float aa = far / (far - near);
-		const float bb = -near * aa;
-
-		m.x.x = width;
-		m.x.y = 0.0f;
-		m.x.z = 0.0f;
-		m.x.w = 0.0f;
-
-		m.y.x = 0.0f;
-		m.y.y = height;
-		m.y.z = 0.0f;
-		m.y.w = 0.0f;
-
-		m.z.x = 0.0f;
-		m.z.y = 0.0f;
-		m.z.z = aa;
-		m.z.w = 1.0f;
-
-		m.t.x = 0.0f;
-		m.t.y = 0.0f;
-		m.t.z = bb;
-		m.t.w = 0.0f;
-	}
-
-	inline void set_orthographic(Matrix4x4& m, float left, float right, float bottom, float top, float near, float far)
-	{
-		m.x.x = 2.0f / (right - left);
-		m.x.y = 0.0f;
-		m.x.z = 0.0f;
-		m.x.w = 0.0f;
-
-		m.y.x = 0.0f;
-		m.y.y = 2.0f / (top - bottom);
-		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 / (far - near);
-		m.z.w = 0.0f;
-
-		m.t.x = (left + right) / (left - right);
-		m.t.y = (top + bottom) / (bottom - top);
-		m.t.z = near / (near - far);
-		m.t.w = 1.0f;
-	}
-
-	inline Matrix4x4& transpose(Matrix4x4& m)
-	{
-		float tmp;
-
-		tmp = m.x.y;
-		m.x.y = m.y.x;
-		m.y.x = tmp;
-
-		tmp = m.x.z;
-		m.x.z = m.z.x;
-		m.z.x = tmp;
-
-		tmp = m.x.w;
-		m.x.w = m.t.x;
-		m.t.x = tmp;
-
-		tmp = m.y.z;
-		m.y.z = m.z.y;
-		m.z.y = tmp;
-
-		tmp = m.y.w;
-		m.y.w = m.t.y;
-		m.t.y = tmp;
-
-		tmp = m.z.w;
-		m.z.w = m.t.z;
-		m.t.z = tmp;
-
-		return m;
-	}
-
-	inline Matrix4x4 get_transposed(Matrix4x4 m)
-	{
-		transpose(m);
-		return m;
-	}
-
-	inline void set_look(Matrix4x4& m, const Vector3& pos, const Vector3& target, const Vector3& up)
-	{
-		Vector3 zAxis = pos - target;
-		vector3::normalize(zAxis);
-		const Vector3 xAxis = vector3::cross(up, zAxis);
-		const Vector3 yAxis = vector3::cross(zAxis, xAxis);
-
-		m.x.x= xAxis.x;
-		m.x.y= yAxis.x;
-		m.x.z= zAxis.x;
-		m.x.w= 0;
-
-		m.y.x= xAxis.y;
-		m.y.y= yAxis.y;
-		m.y.z= zAxis.y;
-		m.y.w= 0;
-
-		m.z.x= xAxis.z;
-		m.z.y= yAxis.z;
-		m.z.z= zAxis.z;
-		m.z.w= 0;
-
-		m.t.x= -vector3::dot(pos, xAxis);
-		m.t.y= -vector3::dot(pos, yAxis);
-		m.t.z= -vector3::dot(pos, zAxis);
-		m.t.w= 1;
-	}
-
-	inline float determinant(const Matrix4x4& m)
-	{
-		const float m02m07_m06m03 = m.x.z * m.y.w - m.y.z * m.x.w;
-		const float m02m11_m10m03 = m.x.z * m.z.w - m.z.z * m.x.w;
-		const float m02m15_m14m03 = m.x.z * m.t.w - m.t.z * m.x.w;
-		const float m06m11_m10m07 = m.y.z * m.z.w - m.z.z * m.y.w;
-		const float m06m15_m14m07 = m.y.z * m.t.w - m.t.z * m.y.w;
-		const float m10m15_m14m11 = m.z.z * m.t.w - m.t.z * m.z.w;
-
-		return 	+ m.x.x * (m.y.y * m10m15_m14m11 - m.z.y * m06m15_m14m07 + m.t.y * m06m11_m10m07)
-				- m.y.x * (m.x.y * m10m15_m14m11 - m.z.y * m02m15_m14m03 + m.t.y * m02m11_m10m03)
-				+ m.z.x * (m.x.y * m06m15_m14m07 - m.y.y * m02m15_m14m03 + m.t.y * m02m07_m06m03)
-				- m.t.x * (m.x.y * m06m11_m10m07 - m.y.y * m02m11_m10m03 + m.z.y * m02m07_m06m03);
-	}
-
-	inline Matrix4x4& invert(Matrix4x4& m)
-	{
-		Matrix4x4 mat;
-
-		const float m01m06_m05m02 = m.x.y * m.y.z - m.y.y * m.x.z;
-		const float m01m07_m05m03 = m.x.y * m.y.w - m.y.y * m.x.w;
-		const float m01m10_m09m02 = m.x.y * m.z.z - m.z.y * m.x.z;
-		const float m01m11_m09m03 = m.x.y * m.z.w - m.z.y * m.x.w;
-		const float m01m14_m13m02 = m.x.y * m.t.z - m.t.y * m.x.z;
-		const float m01m15_m13m03 = m.x.y * m.t.w - m.t.y * m.x.w;
-		const float m02m07_m06m03 = m.x.z * m.y.w - m.y.z * m.x.w;
-		const float m02m11_m10m03 = m.x.z * m.z.w - m.z.z * m.x.w;
-		const float m02m15_m14m03 = m.x.z * m.t.w - m.t.z * m.x.w;
-		const float m05m10_m09m06 = m.y.y * m.z.z - m.z.y * m.y.z;
-		const float m05m11_m09m07 = m.y.y * m.z.w - m.z.y * m.y.w;
-		const float m05m14_m13m06 = m.y.y * m.t.z - m.t.y * m.y.z;
-		const float m05m15_m13m07 = m.y.y * m.t.w - m.t.y * m.y.w;
-		const float m06m11_m10m07 = m.y.z * m.z.w - m.z.z * m.y.w;
-		const float m06m15_m14m07 = m.y.z * m.t.w - m.t.z * m.y.w;
-		const float m09m14_m13m10 = m.z.y * m.t.z - m.t.y * m.z.z;
-		const float m09m15_m13m11 = m.z.y * m.t.w - m.t.y * m.z.w;
-		const float m10m15_m14m11 = m.z.z * m.t.w - m.t.z * m.z.w;
-
-		mat.x.x = (+ m.y.y * m10m15_m14m11 - m.z.y * m06m15_m14m07 + m.t.y * m06m11_m10m07);
-		mat.x.y = (+ m.x.y * m10m15_m14m11 - m.z.y * m02m15_m14m03 + m.t.y * m02m11_m10m03);
-		mat.x.z = (+ m.x.y * m06m15_m14m07 - m.y.y * m02m15_m14m03 + m.t.y * m02m07_m06m03);
-		mat.x.w = (+ m.x.y * m06m11_m10m07 - m.y.y * m02m11_m10m03 + m.z.y * m02m07_m06m03);
-
-		const float inv_det = 1.0f / (m.x.x * mat.x.x - m.y.x * mat.x.y + m.z.x * mat.x.z - m.t.x * mat.x.w);
-
-		mat.y.x = (+ m.y.x * m10m15_m14m11 - m.z.x * m06m15_m14m07 + m.t.x * m06m11_m10m07);
-		mat.y.y = (+ m.x.x * m10m15_m14m11 - m.z.x * m02m15_m14m03 + m.t.x * m02m11_m10m03);
-		mat.y.z = (+ m.x.x * m06m15_m14m07 - m.y.x * m02m15_m14m03 + m.t.x * m02m07_m06m03);
-		mat.y.w = (+ m.x.x * m06m11_m10m07 - m.y.x * m02m11_m10m03 + m.z.x * m02m07_m06m03);
-		mat.z.x = (+ m.y.x * m09m15_m13m11 - m.z.x * m05m15_m13m07 + m.t.x * m05m11_m09m07);
-		mat.z.y = (+ m.x.x * m09m15_m13m11 - m.z.x * m01m15_m13m03 + m.t.x * m01m11_m09m03);
-		mat.z.z = (+ m.x.x * m05m15_m13m07 - m.y.x * m01m15_m13m03 + m.t.x * m01m07_m05m03);
-		mat.z.w = (+ m.x.x * m05m11_m09m07 - m.y.x * m01m11_m09m03 + m.z.x * m01m07_m05m03);
-		mat.t.x = (+ m.y.x * m09m14_m13m10 - m.z.x * m05m14_m13m06 + m.t.x * m05m10_m09m06);
-		mat.t.y = (+ m.x.x * m09m14_m13m10 - m.z.x * m01m14_m13m02 + m.t.x * m01m10_m09m02);
-		mat.t.z = (+ m.x.x * m05m14_m13m06 - m.y.x * m01m14_m13m02 + m.t.x * m01m06_m05m02);
-		mat.t.w = (+ m.x.x * m05m10_m09m06 - m.y.x * m01m10_m09m02 + m.z.x * m01m06_m05m02);
-
-		m.x.x = + mat.x.x * inv_det;
-		m.x.y = - mat.x.y * inv_det;
-		m.x.z = + mat.x.z * inv_det;
-		m.x.w = - mat.x.w * inv_det;
-		m.y.x = - mat.y.x * inv_det;
-		m.y.y = + mat.y.y * inv_det;
-		m.y.z = - mat.y.z * inv_det;
-		m.y.w = + mat.y.w * inv_det;
-		m.z.x = + mat.z.x * inv_det;
-		m.z.y = - mat.z.y * inv_det;
-		m.z.z = + mat.z.z * inv_det;
-		m.z.w = - mat.z.w * inv_det;
-		m.t.x = - mat.t.x * inv_det;
-		m.t.y = + mat.t.y * inv_det;
-		m.t.z = - mat.t.z * inv_det;
-		m.t.w = + mat.t.w * inv_det;
-
-		return m;
-	}
-
-	inline Matrix4x4 get_inverted(Matrix4x4 m)
-	{
-		invert(m);
-		return m;
-	}
-
-	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);
-	}
-
-	inline Vector3 x(const Matrix4x4& m)
-	{
-		return Vector3(m.x.x, m.x.y, m.x.z);
-	}
-
-	inline Vector3 y(const Matrix4x4& m)
-	{
-		return Vector3(m.y.x, m.y.y, m.y.z);
-	}
-
-	inline Vector3 z(const Matrix4x4& m)
-	{
-		return Vector3(m.z.x, m.z.y, m.z.z);
-	}
-
-	inline void set_x(Matrix4x4& m, const Vector3& x)
-	{
-		m.x.x = x.x;
-		m.x.y = x.y;
-		m.x.z = x.z;
-	}
-
-	inline void set_y(Matrix4x4& m, const Vector3& y)
-	{
-		m.y.x = y.x;
-		m.y.y = y.y;
-		m.y.z = y.z;
-	}
-
-	inline void set_z(Matrix4x4& m, const Vector3& z)
-	{
-		m.z.x = z.x;
-		m.z.y = z.y;
-		m.z.z = z.z;
-	}
-
-	inline Vector3 translation(const Matrix4x4& m)
-	{
-		return Vector3(m.t.x, m.t.y, m.t.z);
-	}
-
-	inline void set_translation(Matrix4x4& m, const Vector3& trans)
-	{
-		m.t.x = trans.x;
-		m.t.y = trans.y;
-		m.t.z = trans.z;
-	}
-
-	inline Quaternion rotation(const Matrix4x4& m)
-	{
-		return matrix3x3::rotation(to_matrix3x3(m));
-	}
-
-	inline void set_rotation(Matrix4x4& m, const Quaternion& rot)
-	{
-		set_rotation(m, Matrix3x3(rot));
-	}
-
-	inline void set_rotation(Matrix4x4& m, const Matrix3x3& rot)
-	{
-		m.x.x = rot.x.x;
-		m.x.y = rot.x.y;
-		m.x.z = rot.x.z;
-		m.y.x = rot.y.x;
-		m.y.y = rot.y.y;
-		m.y.z = rot.y.z;
-		m.z.x = rot.z.x;
-		m.z.y = rot.z.y;
-		m.z.z = rot.z.z;
-	}
-
-	inline Vector3 scale(const Matrix4x4& m)
-	{
-		using namespace vector4;
-		using namespace vector3;
-		const float sx = length(to_vector3(m.x));
-		const float sy = length(to_vector3(m.y));
-		const float sz = length(to_vector3(m.z));
-		return Vector3(sx, sy, sz);
-	}
+/// 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 / tan(fovy * ((float) PI / 180.0f) * 0.5f);
+	const float width = height * 1.0f / aspect;
+	const float aa = far / (far - near);
+	const float bb = -near * aa;
+
+	m.x.x = width;
+	m.x.y = 0.0f;
+	m.x.z = 0.0f;
+	m.x.w = 0.0f;
+
+	m.y.x = 0.0f;
+	m.y.y = height;
+	m.y.z = 0.0f;
+	m.y.w = 0.0f;
+
+	m.z.x = 0.0f;
+	m.z.y = 0.0f;
+	m.z.z = aa;
+	m.z.w = 1.0f;
+
+	m.t.x = 0.0f;
+	m.t.y = 0.0f;
+	m.t.z = bb;
+	m.t.w = 0.0f;
+}
+
+/// Sets the matrix @a m to orthographic.
+inline void set_orthographic(Matrix4x4& m, float left, float right, float bottom, float top, float near, float far)
+{
+	m.x.x = 2.0f / (right - left);
+	m.x.y = 0.0f;
+	m.x.z = 0.0f;
+	m.x.w = 0.0f;
+
+	m.y.x = 0.0f;
+	m.y.y = 2.0f / (top - bottom);
+	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 / (far - near);
+	m.z.w = 0.0f;
+
+	m.t.x = (left + right) / (left - right);
+	m.t.y = (top + bottom) / (bottom - top);
+	m.t.z = near / (near - far);
+	m.t.w = 1.0f;
+}
+
+/// Transposes the matrix @a m and returns the result.
+inline Matrix4x4& transpose(Matrix4x4& m)
+{
+	float tmp;
 
-	inline void set_scale(Matrix4x4& m, const Vector3& s)
-	{
-		Matrix3x3 rot = to_matrix3x3(m);
-		matrix3x3::set_scale(rot, s);
-		set_rotation(m, rot);
-	}
+	tmp = m.x.y;
+	m.x.y = m.y.x;
+	m.y.x = tmp;
 
-	inline float* to_float_ptr(Matrix4x4& m)
-	{
-		return vector4::to_float_ptr(m.x);
-	}
+	tmp = m.x.z;
+	m.x.z = m.z.x;
+	m.z.x = tmp;
 
-	inline const float* to_float_ptr(const Matrix4x4& m)
-	{
-		return vector4::to_float_ptr(m.x);
-	}
+	tmp = m.x.w;
+	m.x.w = m.t.x;
+	m.t.x = tmp;
 
-	inline Matrix3x3 to_matrix3x3(const Matrix4x4& m)
-	{
-		return Matrix3x3(x(m), y(m), z(m));
-	}
-} // namespace matrix4x4
+	tmp = m.y.z;
+	m.y.z = m.z.y;
+	m.z.y = tmp;
 
-inline Matrix4x4::Matrix4x4()
-{
-	// Do not initialize
+	tmp = m.y.w;
+	m.y.w = m.t.y;
+	m.t.y = tmp;
+
+	tmp = m.z.w;
+	m.z.w = m.t.z;
+	m.t.z = tmp;
+
+	return m;
 }
 
-inline Matrix4x4::Matrix4x4(const Vector3& x, const Vector3& y, const Vector3& z, const Vector3& t)
-	: x(x, 0), y(y, 0), z(z, 0), t(t, 1)
+/// Returns the transposed of the matrix @a m.
+inline Matrix4x4 get_transposed(Matrix4x4 m)
 {
+	transpose(m);
+	return m;
 }
 
-inline Matrix4x4::Matrix4x4(float r1c1, float r2c1, float r3c1, float r4c1,
-							float r1c2, float r2c2, float r3c2, float r4c2,
-							float r1c3, float r2c3, float r3c3, float r4c3,
-							float r1c4, float r2c4, float r3c4, float r4c4)
-	: x(r1c1, r2c1, r3c1, r4c1)
-	, y(r1c2, r2c2, r3c2, r4c2)
-	, z(r1c3, r2c3, r3c3, r4c3)
-	, t(r1c4, r2c4, r3c4, r4c4)
+/// 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);
+
+	m.x.x= xAxis.x;
+	m.x.y= yAxis.x;
+	m.x.z= zAxis.x;
+	m.x.w= 0;
+
+	m.y.x= xAxis.y;
+	m.y.y= yAxis.y;
+	m.y.z= zAxis.y;
+	m.y.w= 0;
+
+	m.z.x= xAxis.z;
+	m.z.y= yAxis.z;
+	m.z.z= zAxis.z;
+	m.z.w= 0;
+
+	m.t.x= -dot(pos, xAxis);
+	m.t.y= -dot(pos, yAxis);
+	m.t.z= -dot(pos, zAxis);
+	m.t.w= 1;
 }
 
-inline Matrix4x4::Matrix4x4(const Quaternion& r, const Vector3& p)
-	: x(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)
-	, y(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)
-	, z(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)
-	, t(p, 1)
+/// Returns the determinant of the matrix @a m.
+inline float determinant(const Matrix4x4& m)
 {
+	const float m02m07_m06m03 = m.x.z * m.y.w - m.y.z * m.x.w;
+	const float m02m11_m10m03 = m.x.z * m.z.w - m.z.z * m.x.w;
+	const float m02m15_m14m03 = m.x.z * m.t.w - m.t.z * m.x.w;
+	const float m06m11_m10m07 = m.y.z * m.z.w - m.z.z * m.y.w;
+	const float m06m15_m14m07 = m.y.z * m.t.w - m.t.z * m.y.w;
+	const float m10m15_m14m11 = m.z.z * m.t.w - m.t.z * m.z.w;
+
+	return 	+ m.x.x * (m.y.y * m10m15_m14m11 - m.z.y * m06m15_m14m07 + m.t.y * m06m11_m10m07)
+			- m.y.x * (m.x.y * m10m15_m14m11 - m.z.y * m02m15_m14m03 + m.t.y * m02m11_m10m03)
+			+ m.z.x * (m.x.y * m06m15_m14m07 - m.y.y * m02m15_m14m03 + m.t.y * m02m07_m06m03)
+			- m.t.x * (m.x.y * m06m11_m10m07 - m.y.y * m02m11_m10m03 + m.z.y * m02m07_m06m03);
 }
 
-inline Matrix4x4::Matrix4x4(const Matrix3x3& m)
-	: x(m.x, 0)
-	, y(m.y, 0)
-	, z(m.z, 0)
-	, t(0, 0, 0, 1)
+/// Inverts the matrix @a m and returns the result.
+inline Matrix4x4& invert(Matrix4x4& m)
 {
+	Matrix4x4 mat;
+
+	const float m01m06_m05m02 = m.x.y * m.y.z - m.y.y * m.x.z;
+	const float m01m07_m05m03 = m.x.y * m.y.w - m.y.y * m.x.w;
+	const float m01m10_m09m02 = m.x.y * m.z.z - m.z.y * m.x.z;
+	const float m01m11_m09m03 = m.x.y * m.z.w - m.z.y * m.x.w;
+	const float m01m14_m13m02 = m.x.y * m.t.z - m.t.y * m.x.z;
+	const float m01m15_m13m03 = m.x.y * m.t.w - m.t.y * m.x.w;
+	const float m02m07_m06m03 = m.x.z * m.y.w - m.y.z * m.x.w;
+	const float m02m11_m10m03 = m.x.z * m.z.w - m.z.z * m.x.w;
+	const float m02m15_m14m03 = m.x.z * m.t.w - m.t.z * m.x.w;
+	const float m05m10_m09m06 = m.y.y * m.z.z - m.z.y * m.y.z;
+	const float m05m11_m09m07 = m.y.y * m.z.w - m.z.y * m.y.w;
+	const float m05m14_m13m06 = m.y.y * m.t.z - m.t.y * m.y.z;
+	const float m05m15_m13m07 = m.y.y * m.t.w - m.t.y * m.y.w;
+	const float m06m11_m10m07 = m.y.z * m.z.w - m.z.z * m.y.w;
+	const float m06m15_m14m07 = m.y.z * m.t.w - m.t.z * m.y.w;
+	const float m09m14_m13m10 = m.z.y * m.t.z - m.t.y * m.z.z;
+	const float m09m15_m13m11 = m.z.y * m.t.w - m.t.y * m.z.w;
+	const float m10m15_m14m11 = m.z.z * m.t.w - m.t.z * m.z.w;
+
+	mat.x.x = (+ m.y.y * m10m15_m14m11 - m.z.y * m06m15_m14m07 + m.t.y * m06m11_m10m07);
+	mat.x.y = (+ m.x.y * m10m15_m14m11 - m.z.y * m02m15_m14m03 + m.t.y * m02m11_m10m03);
+	mat.x.z = (+ m.x.y * m06m15_m14m07 - m.y.y * m02m15_m14m03 + m.t.y * m02m07_m06m03);
+	mat.x.w = (+ m.x.y * m06m11_m10m07 - m.y.y * m02m11_m10m03 + m.z.y * m02m07_m06m03);
+
+	const float inv_det = 1.0f / (m.x.x * mat.x.x - m.y.x * mat.x.y + m.z.x * mat.x.z - m.t.x * mat.x.w);
+
+	mat.y.x = (+ m.y.x * m10m15_m14m11 - m.z.x * m06m15_m14m07 + m.t.x * m06m11_m10m07);
+	mat.y.y = (+ m.x.x * m10m15_m14m11 - m.z.x * m02m15_m14m03 + m.t.x * m02m11_m10m03);
+	mat.y.z = (+ m.x.x * m06m15_m14m07 - m.y.x * m02m15_m14m03 + m.t.x * m02m07_m06m03);
+	mat.y.w = (+ m.x.x * m06m11_m10m07 - m.y.x * m02m11_m10m03 + m.z.x * m02m07_m06m03);
+	mat.z.x = (+ m.y.x * m09m15_m13m11 - m.z.x * m05m15_m13m07 + m.t.x * m05m11_m09m07);
+	mat.z.y = (+ m.x.x * m09m15_m13m11 - m.z.x * m01m15_m13m03 + m.t.x * m01m11_m09m03);
+	mat.z.z = (+ m.x.x * m05m15_m13m07 - m.y.x * m01m15_m13m03 + m.t.x * m01m07_m05m03);
+	mat.z.w = (+ m.x.x * m05m11_m09m07 - m.y.x * m01m11_m09m03 + m.z.x * m01m07_m05m03);
+	mat.t.x = (+ m.y.x * m09m14_m13m10 - m.z.x * m05m14_m13m06 + m.t.x * m05m10_m09m06);
+	mat.t.y = (+ m.x.x * m09m14_m13m10 - m.z.x * m01m14_m13m02 + m.t.x * m01m10_m09m02);
+	mat.t.z = (+ m.x.x * m05m14_m13m06 - m.y.x * m01m14_m13m02 + m.t.x * m01m06_m05m02);
+	mat.t.w = (+ m.x.x * m05m10_m09m06 - m.y.x * m01m10_m09m02 + m.z.x * m01m06_m05m02);
+
+	m.x.x = + mat.x.x * inv_det;
+	m.x.y = - mat.x.y * inv_det;
+	m.x.z = + mat.x.z * inv_det;
+	m.x.w = - mat.x.w * inv_det;
+	m.y.x = - mat.y.x * inv_det;
+	m.y.y = + mat.y.y * inv_det;
+	m.y.z = - mat.y.z * inv_det;
+	m.y.w = + mat.y.w * inv_det;
+	m.z.x = + mat.z.x * inv_det;
+	m.z.y = - mat.z.y * inv_det;
+	m.z.z = + mat.z.z * inv_det;
+	m.z.w = - mat.z.w * inv_det;
+	m.t.x = - mat.t.x * inv_det;
+	m.t.y = + mat.t.y * inv_det;
+	m.t.z = - mat.t.z * inv_det;
+	m.t.w = + mat.t.w * inv_det;
+
+	return m;
 }
 
-inline Matrix4x4::Matrix4x4(const float v[16])
-	: x(v[0], v[1], v[2], v[3])
-	, y(v[4], v[5], v[6], v[7])
-	, z(v[8], v[9], v[10], v[11])
-	, t(v[12], v[13], v[14], v[15])
+/// Returns the inverse of the matrix @a m.
+inline Matrix4x4 get_inverted(Matrix4x4 m)
 {
+	invert(m);
+	return m;
 }
 
-inline float& Matrix4x4::operator[](uint32_t i)
+/// Sets the matrix @a m to identity.
+inline void set_identity(Matrix4x4& m)
 {
-	CE_ASSERT(i < 16, "Index out of bounds");
-
-	return vector4::to_float_ptr(x)[i];
+	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);
 }
 
-inline const float& Matrix4x4::operator[](uint32_t i) const
+/// Returns the x asis of the matrix @a m.
+inline Vector3 x(const Matrix4x4& m)
 {
-	CE_ASSERT(i < 16, "Index out of bounds");
+	return vector3(m.x.x, m.x.y, m.x.z);
+}
 
-	return vector4::to_float_ptr(x)[i];
+/// Returns the y asis of the matrix @a m.
+inline Vector3 y(const Matrix4x4& m)
+{
+	return vector3(m.y.x, m.y.y, m.y.z);
 }
 
-inline Matrix4x4& Matrix4x4::operator+=(const Matrix4x4& a)
+/// Returns the z asis of the matrix @a m.
+inline Vector3 z(const Matrix4x4& m)
 {
-	x += a.x;
-	y += a.y;
-	z += a.z;
-	t += a.t;
+	return vector3(m.z.x, m.z.y, m.z.z);
+}
 
-	return *this;
+/// Sets the x axis of the matrix @a m.
+inline void set_x(Matrix4x4& m, const Vector3& x)
+{
+	m.x.x = x.x;
+	m.x.y = x.y;
+	m.x.z = x.z;
 }
 
-inline Matrix4x4& Matrix4x4::operator-=(const Matrix4x4& a)
+/// Sets the y axis of the matrix @a m.
+inline void set_y(Matrix4x4& m, const Vector3& y)
 {
-	x -= a.x;
-	y -= a.y;
-	z -= a.z;
-	t -= a.t;
+	m.y.x = y.x;
+	m.y.y = y.y;
+	m.y.z = y.z;
+}
 
-	return *this;
+/// Sets the z axis of the matrix @a m.
+inline void set_z(Matrix4x4& m, const Vector3& z)
+{
+	m.z.x = z.x;
+	m.z.y = z.y;
+	m.z.z = z.z;
 }
 
-inline Matrix4x4& Matrix4x4::operator*=(float k)
+/// Returns the translation portion of the matrix @a m.
+inline Vector3 translation(const Matrix4x4& m)
 {
-	x *= k;
-	y *= k;
-	z *= k;
-	t *= k;
+	return vector3(m.t.x, m.t.y, m.t.z);
+}
 
-	return *this;
+/// Sets the translation portion of the matrix @a m.
+inline void set_translation(Matrix4x4& m, const Vector3& trans)
+{
+	m.t.x = trans.x;
+	m.t.y = trans.y;
+	m.t.z = trans.z;
 }
 
-inline Matrix4x4& Matrix4x4::operator/=(float k)
+
+/// Returns the rotation portion of the matrix @a m as a Matrix3x3.
+inline Matrix3x3 to_matrix3x3(const Matrix4x4& m)
 {
-	const float inv_k = 1.0f / k;
+	return matrix3x3(x(m), y(m), z(m));
+}
 
-	x *= inv_k;
-	y *= inv_k;
-	z *= inv_k;
-	t *= inv_k;
+/// Returns the rotation portion of the matrix @a m as a Quaternion.
+inline Quaternion rotation(const Matrix4x4& m)
+{
+	return rotation(to_matrix3x3(m));
+}
 
-	return *this;
+/// Sets the rotation portion of the matrix @a m.
+inline void set_rotation(Matrix4x4& m, const Matrix3x3& rot)
+{
+	m.x.x = rot.x.x;
+	m.x.y = rot.x.y;
+	m.x.z = rot.x.z;
+	m.y.x = rot.y.x;
+	m.y.y = rot.y.y;
+	m.y.z = rot.y.z;
+	m.z.x = rot.z.x;
+	m.z.y = rot.z.y;
+	m.z.z = rot.z.z;
 }
 
-inline Matrix4x4& Matrix4x4::operator*=(const Matrix4x4& a)
+/// Sets the rotation portion of the matrix @a m.
+inline void set_rotation(Matrix4x4& m, const Quaternion& rot)
 {
-	Matrix4x4 tmp(
-		x.x*a.x.x + x.y*a.y.x + x.z*a.z.x + x.w*a.t.x,
-		x.x*a.x.y + x.y*a.y.y + x.z*a.z.y + x.w*a.t.y,
-		x.x*a.x.z + x.y*a.y.z + x.z*a.z.z + x.w*a.t.z,
-		x.x*a.x.w + x.y*a.y.w + x.z*a.z.w + x.w*a.t.w,
+	set_rotation(m, matrix3x3(rot));
+}
 
-		y.x*a.x.x + y.y*a.y.x + y.z*a.z.x + y.w*a.t.x,
-		y.x*a.x.y + y.y*a.y.y + y.z*a.z.y + y.w*a.t.y,
-		y.x*a.x.z + y.y*a.y.z + y.z*a.z.z + y.w*a.t.z,
-		y.x*a.x.w + y.y*a.y.w + y.z*a.z.w + y.w*a.t.w,
+/// Returns the scale of the matrix @a m.
+inline Vector3 scale(const Matrix4x4& m)
+{
+	const float sx = length(to_vector3(m.x));
+	const float sy = length(to_vector3(m.y));
+	const float sz = length(to_vector3(m.z));
+	return vector3(sx, sy, sz);
+}
 
-		z.x*a.x.x + z.y*a.y.x + z.z*a.z.x + z.w*a.t.x,
-		z.x*a.x.y + z.y*a.y.y + z.z*a.z.y + z.w*a.t.y,
-		z.x*a.x.z + z.y*a.y.z + z.z*a.z.z + z.w*a.t.z,
-		z.x*a.x.w + z.y*a.y.w + z.z*a.z.w + z.w*a.t.w,
+/// Sets the scale of the matrix @æ m.
+inline void set_scale(Matrix4x4& m, const Vector3& s)
+{
+	Matrix3x3 rot = to_matrix3x3(m);
+	set_scale(rot, s);
+	set_rotation(m, rot);
+}
 
-		t.x*a.x.x + t.y*a.y.x + t.z*a.z.x + t.w*a.t.x,
-		t.x*a.x.y + t.y*a.y.y + t.z*a.z.y + t.w*a.t.y,
-		t.x*a.x.z + t.y*a.y.z + t.z*a.z.z + t.w*a.t.z,
-		t.x*a.x.w + t.y*a.y.w + t.z*a.z.w + t.w*a.t.w
-	);
+/// Returns the pointer to the matrix's data
+inline float* to_float_ptr(Matrix4x4& m)
+{
+	return to_float_ptr(m.x);
+}
 
-	*this = tmp;
-	return *this;
+/// Returns the pointer to the matrix's data
+inline const float* to_float_ptr(const Matrix4x4& m)
+{
+	return to_float_ptr(m.x);
 }
 
 } // namespace crown

+ 11 - 16
src/core/math/plane.h

@@ -26,14 +26,19 @@ 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 = 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 = vector3::length(p.n);
+		const float len = length(p.n);
 
 		if (equals(len, 0.0f))
 			return p;
@@ -48,18 +53,8 @@ namespace plane
 
 	inline float distance_to_point(const Plane& p, const Vector3& point)
 	{
-		return vector3::dot(p.n, point) + p.d;
+		return dot(p.n, point) + p.d;
 	}
 } // namespace plane
 
-inline Plane::Plane()
-{
-	// Do not initialize
-}
-
-inline Plane::Plane(const Vector3& normal, float dist)
-	: n(normal), d(dist)
-{
-}
-
 } // namespace crown

+ 71 - 110
src/core/math/quaternion.h

@@ -12,154 +12,115 @@
 namespace crown
 {
 
-/// Negates the quaternion @a q and returns the result.
-Quaternion operator-(const Quaternion& q);
-
-/// Multiplies the quaternions @a a and @a b. (i.e. rotates first by @a a then by @a b).
-Quaternion operator*(Quaternion a, const Quaternion& b);
-
-/// Multiplies the quaternion @a a by the scalar @a k.
-Quaternion operator*(const Quaternion& a, float k);
-
 /// Functions to manipulate Quaternion.
 ///
 /// @ingroup Math
-namespace quaternion
-{
-	const Quaternion IDENTITY = Quaternion(0.0, 0.0, 0.0, 1.0);
-
-	/// Returns the dot product between quaternions @a a and @a b.
-	float dot(const Quaternion& a, const Quaternion& b);
-
-	/// Returns the length of @a q.
-	float length(const Quaternion& q);
+const Quaternion QUATERNION_IDENTITY = { 0.0, 0.0, 0.0, 1.0 };
 
-	/// Normalizes the quaternion @a q and returns the result.
-	Quaternion& normalize(Quaternion& q);
-
-	/// Returns the conjugate of quaternion @a q.
-	Quaternion conjugate(const Quaternion& q);
+inline Quaternion quaternion(float x, float y, float z, float w)
+{
+	Quaternion q;
+	q.x = x;
+	q.y = y;
+	q.z = z;
+	q.w = w;
+	return q;
+}
 
-	/// Returns the inverse of quaternion @a q.
-	Quaternion inverse(const Quaternion& q);
+inline Quaternion quaternion(const Vector3& axis, float angle)
+{
+	Quaternion q;
+	q.x = axis.x * sin(angle * 0.5f);
+	q.y = axis.y * sin(angle * 0.5f);
+	q.z = axis.z * sin(angle * 0.5f);
+	q.w = cos(angle * 0.5f);
+	return q;
+}
 
-	/// Returns the quaternion @a q raised to the power of @a exp.
-	Quaternion power(const Quaternion& q, float exp);
-} // namespace quaternion
+inline Quaternion& operator*=(Quaternion& a, const Quaternion& b)
+{
+	const float t_w = a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z;
+	const float t_x = a.w*b.x + a.x*b.w + a.y*b.z - a.z*b.y;
+	const float t_y = a.w*b.y + a.y*b.w + a.z*b.x - a.x*b.z;
+	const float t_z = a.w*b.z + a.z*b.w + a.x*b.y - a.y*b.x;
+	a.x = t_x;
+	a.y = t_y;
+	a.z = t_z;
+	a.w = t_w;
+	return a;
+}
 
+/// 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);
+	return quaternion(-q.x, -q.y, -q.z, -q.w);
 }
 
+/// Multiplies the quaternions @a a and @a b. (i.e. rotates first by @a a then by @a b).
 inline Quaternion operator*(Quaternion a, const Quaternion& b)
 {
 	a *= b;
 	return a;
 }
 
+/// Multiplies the quaternion @a a by the scalar @a k.
 inline Quaternion operator*(const Quaternion& a, float k)
 {
-	return Quaternion(a.x * k, a.y * k, a.z * k, a.w * k);
+	return quaternion(a.x * k, a.y * k, a.z * k, a.w * k);
 }
 
-namespace quaternion
-{
-	inline float dot(const Quaternion& a, const Quaternion& b)
-	{
-		return a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z;
-	}
-
-	inline float length(const Quaternion& q)
-	{
-		return sqrt(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z);
-	}
-
-	inline Quaternion& normalize(Quaternion& q)
-	{
-		const float inv_len = 1.0f / length(q);
-		q.x *= inv_len;
-		q.y *= inv_len;
-		q.z *= inv_len;
-		q.w *= inv_len;
-		return q;
-	}
-
-	inline Quaternion conjugate(const Quaternion& q)
-	{
-		return Quaternion(-q.x, -q.y, -q.z, q.w);
-	}
-
-	inline Quaternion inverse(const Quaternion& q)
-	{
-		return conjugate(q) * (1.0f / length(q));
-	}
-
-	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);
-			tmp.x = q.x * mult;
-			tmp.y = q.y * mult;
-			tmp.z = q.z * mult;
-			return tmp;
-		}
-
-		return q;
-	}
-} // namespace quaternion
-
-inline Quaternion::Quaternion()
+/// Returns the dot product between quaternions @a a and @a b.
+inline float dot(const Quaternion& a, const Quaternion& b)
 {
-	// Do not initialize
+	return a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z;
 }
 
-inline Quaternion::Quaternion(float nx, float ny, float nz, float nw)
-	: x(nx)
-	, y(ny)
-	, z(nz)
-	, w(nw)
+/// Returns the length of @a q.
+inline float length(const Quaternion& q)
 {
+	return sqrt(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z);
 }
 
-inline Quaternion::Quaternion(const Vector3& axis, float angle)
-	: x(axis.x * sin(angle * 0.5f))
-	, y(axis.y * sin(angle * 0.5f))
-	, z(axis.z * sin(angle * 0.5f))
-	, w(cos(angle * 0.5f))
+/// Normalizes the quaternion @a q and returns the result.
+inline Quaternion& normalize(Quaternion& q)
 {
+	const float inv_len = 1.0f / length(q);
+	q.x *= inv_len;
+	q.y *= inv_len;
+	q.z *= inv_len;
+	q.w *= inv_len;
+	return q;
 }
 
-inline float& Quaternion::operator[](uint32_t i)
+/// Returns the conjugate of quaternion @a q.
+inline Quaternion conjugate(const Quaternion& q)
 {
-	CE_ASSERT(i < 4, "Index out of bounds");
-	return (&x)[i];
+	return quaternion(-q.x, -q.y, -q.z, q.w);
 }
 
-inline const float& Quaternion::operator[](uint32_t i) const
+/// Returns the inverse of quaternion @a q.
+inline Quaternion inverse(const Quaternion& q)
 {
-	CE_ASSERT(i < 4, "Index out of bounds");
-	return (&x)[i];
+	return conjugate(q) * (1.0f / length(q));
 }
 
-inline Quaternion& Quaternion::operator*=(const Quaternion& a)
+/// Returns the quaternion @a q raised to the power of @a exp.
+inline Quaternion power(const Quaternion& q, float exp)
 {
-	const float t_w = w*a.w - x*a.x - y*a.y - z*a.z;
-	const float t_x = w*a.x + x*a.w + y*a.z - z*a.y;
-	const float t_y = w*a.y + y*a.w + z*a.x - x*a.z;
-	const float t_z = w*a.z + z*a.w + x*a.y - y*a.x;
-
-	x = t_x;
-	y = t_y;
-	z = t_z;
-	w = t_w;
+	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);
+		tmp.x = q.x * mult;
+		tmp.y = q.y * mult;
+		tmp.z = q.z * mult;
+		return tmp;
+	}
 
-	return *this;
+	return q;
 }
 
 } // namespace crown

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

@@ -37,7 +37,7 @@ namespace sphere
 	{
 		for (uint32_t i = 0; i < num; ++i)
 		{
-			const float dist = vector3::squared_length(points[i] - s.c);
+			const float dist = squared_length(points[i] - s.c);
 			if (dist >= s.r*s.r)
 				s.r = sqrt(dist);
 		}
@@ -47,7 +47,7 @@ namespace sphere
 	{
 		for (uint32_t i = 0; i < num; ++i)
 		{
-			const float dist = vector3::squared_length(spheres[i].c - s.c);
+			const float dist = squared_length(spheres[i].c - s.c);
 
 			if (dist < (spheres[i].r + s.r) * (spheres[i].r + s.r))
 			{
@@ -59,20 +59,9 @@ namespace sphere
 
 	inline bool contains_point(const Sphere& s, const Vector3& p)
 	{
-		float dist = vector3::squared_length(p - s.c);
+		float dist = squared_length(p - s.c);
 		return dist < s.r*s.r;
 	}
 } // namespace sphere
 
-inline Sphere::Sphere()
-{
-	// Do nothing
-}
-
-inline Sphere::Sphere(const Vector3& nc, float nr)
-	: c(nc)
-	, r(nr)
-{
-}
-
 } // namespace crown

+ 74 - 144
src/core/math/vector2.h

@@ -13,224 +13,154 @@
 namespace crown
 {
 
-/// Negates @a a and returns the result.
-Vector2 operator-(const Vector2& a);
-
-/// Adds the vector @a a to @a b and returns the result.
-Vector2 operator+(Vector2 a, const Vector2& b);
-
-/// Subtracts the vector @a b from @a a and returns the result.
-Vector2 operator-(Vector2 a, const Vector2& b);
-
-/// Multiplies the vector @a a by the scalar @a k and returns the result.
-Vector2 operator*(Vector2 a, float k);
-
-/// @copydoc operator*(Vector2, float)
-Vector2 operator*(float k, Vector2 a);
-
-/// Divides the vector @a a by the scalar @a k and returns the result.
-Vector2 operator/(Vector2 a, float k);
-
-/// Returns true whether the vectors @a a and @a b are equal.
-bool operator==(const Vector2& a, const Vector2& b);
-
 /// Functions to manipulate Vector2.
 ///
 /// @ingroup Math
-namespace vector2
-{
-	const Vector2 ZERO = Vector2(0, 0);
-
-	/// Returns the dot product between the vectors @a a and @a b.
-	float dot(const Vector2& a, const Vector2& b);
-
-	/// Returns the lenght of @a a.
-	float length(const Vector2& a);
+const Vector2 VECTOR2_ZERO = { 0.0f, 0.0f };
 
-	/// Returns the squared length of @a a.
-	float squared_length(const Vector2& a);
-
-	/// Sets the lenght of @a a to @a len.
-	void set_length(Vector2& a, float len);
-
-	/// Normalizes @a a and returns the result.
-	Vector2 normalize(Vector2& a);
+inline Vector2 vector2(float x, float y)
+{
+	Vector2 v;
+	v.x = x;
+	v.y = y;
+	return v;
+}
 
-	/// Returns the distance between the points @a a and @a b.
-	float distance(const Vector2& a, const Vector2& b);
+inline Vector2& operator+=(Vector2& a, const Vector2& b)
+{
+	a.x += b.x;
+	a.y += b.y;
+	return a;
+}
 
-	/// Returns the angle between the vectors @a a and @a b.
-	float angle(const Vector2& a, const Vector2& b);
+inline Vector2& operator-=(Vector2& a, const Vector2& b)
+{
+	a.x -= b.x;
+	a.y -= b.y;
+	return a;
+}
 
-	/// Returns the pointer to the data of @a a.
-	float* to_float_ptr(Vector2& a);
+inline Vector2& operator*=(Vector2& a, float k)
+{
+	a.x *= k;
+	a.y *= k;
+	return a;
+}
 
-	/// @copydoc to_float_ptr(Vector2&)
-	const float* to_float_ptr(const Vector2& a);
-} // namespace vector2
+inline Vector2& operator/=(Vector2& a, float k)
+{
+	CE_ASSERT(k != (float)0.0, "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)
 {
-	return Vector2(-a.x, -a.y);
+	return vector2(-a.x, -a.y);
 }
 
+/// Adds the vector @a a to @a b and returns the result.
 inline Vector2 operator+(Vector2 a, const Vector2& b)
 {
 	a += b;
 	return a;
 }
 
+/// Subtracts the vector @a b from @a a and returns the result.
 inline Vector2 operator-(Vector2 a, const Vector2& b)
 {
 	a -= b;
 	return a;
 }
 
+/// Multiplies the vector @a a by the scalar @a k and returns the result.
 inline Vector2 operator*(Vector2 a, float k)
 {
 	a *= k;
 	return a;
 }
 
+/// @copydoc operator*(Vector2, float)
 inline Vector2 operator*(float k, Vector2 a)
 {
 	a *= k;
 	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)
 {
 	return equals(a.x, b.x) && equals(a.y, b.y);
 }
 
-namespace vector2
+/// Returns the dot product between the vectors @a a and @a b.
+inline float dot(const Vector2& a, const Vector2& b)
 {
-
-	inline float dot(const Vector2& a, const Vector2& b)
-	{
-		return a.x * b.x + a.y * b.y;
-	}
-
-	inline float length(const Vector2& a)
-	{
-		return sqrt(a.x * a.x + a.y * a.y);
-	}
-
-	inline float squared_length(const Vector2& a)
-	{
-		return a.x * a.x + a.y * a.y;
-	}
-
-	inline void set_length(Vector2& a, float len)
-	{
-		normalize(a);
-
-		a.x *= len;
-		a.y *= len;
-	}
-
-	inline Vector2 normalize(Vector2& a)
-	{
-		float inv_len = 1.0f / length(a);
-
-		a.x *= inv_len;
-		a.y *= inv_len;
-
-		return a;
-	}
-
-	inline float distance(const Vector2& a, const Vector2& b)
-	{
-		return length(b - a);
-	}
-
-	inline float angle(const Vector2& a, const Vector2& b)
-	{
-		return acos(dot(a, b) / (length(a) * length(b)));
-	}
-
-	inline float* to_float_ptr(Vector2& a)
-	{
-		return &a.x;
-	}
-
-	inline const float* to_float_ptr(const Vector2& a)
-	{
-		return &a.x;
-	}
-} // namespace vector2
-
-inline Vector2::Vector2()
-{
-	// Do not initialize
+	return a.x * b.x + a.y * b.y;
 }
 
-inline Vector2::Vector2(float val) : x(val), y(val)
+/// Returns the lenght of @a a.
+inline float length(const Vector2& a)
 {
+	return sqrt(a.x * a.x + a.y * a.y);
 }
 
-inline Vector2::Vector2(float nx, float ny) : x(nx), y(ny)
+/// Returns the squared length of @a a.
+inline float squared_length(const Vector2& a)
 {
+	return a.x * a.x + a.y * a.y;
 }
 
-inline Vector2::Vector2(const float a[2]) : x(a[0]), y(a[1])
+/// Normalizes @a a and returns the result.
+inline Vector2 normalize(Vector2& a)
 {
+	float inv_len = 1.0f / length(a);
+	a.x *= inv_len;
+	a.y *= inv_len;
+	return a;
 }
 
-inline const float& Vector2::operator[](uint32_t i) const
-{
-	CE_ASSERT(i < 2, "Index out of bounds");
-
-	return (&x)[i];
-}
-
-inline float& Vector2::operator[](uint32_t i)
+/// Sets the lenght of @a a to @a len.
+inline void set_length(Vector2& a, float len)
 {
-	CE_ASSERT(i < 2, "Index out of bounds");
+	normalize(a);
 
-	return (&x)[i];
+	a.x *= len;
+	a.y *= len;
 }
 
-inline Vector2& Vector2::operator+=(const Vector2& a)
+/// Returns the distance between the points @a a and @a b.
+inline float distance(const Vector2& a, const Vector2& b)
 {
-	x += a.x;
-	y += a.y;
-
-	return *this;
+	return length(b - a);
 }
 
-inline Vector2& Vector2::operator-=(const Vector2& a)
+/// Returns the angle between the vectors @a a and @a b.
+inline float angle(const Vector2& a, const Vector2& b)
 {
-	x -= a.x;
-	y -= a.y;
-
-	return *this;
+	return acos(dot(a, b) / (length(a) * length(b)));
 }
 
-inline Vector2& Vector2::operator*=(float k)
+/// Returns the pointer to the data of @a a.
+inline float* to_float_ptr(Vector2& a)
 {
-	x *= k;
-	y *= k;
-
-	return *this;
+	return &a.x;
 }
 
-inline Vector2& Vector2::operator/=(float k)
+/// @copydoc to_float_ptr(Vector2&)
+inline const float* to_float_ptr(const Vector2& a)
 {
-	CE_ASSERT(k != (float)0.0, "Division by zero");
-
-	float inv = (float)(1.0 / k);
-
-	x *= inv;
-	y *= inv;
-
-	return *this;
+	return &a.x;
 }
 
 } // namespace crown

+ 101 - 171
src/core/math/vector3.h

@@ -14,254 +14,184 @@
 namespace crown
 {
 
-/// 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);
-
 /// Functions to manipulate Vector3.
 ///
 /// @ingroup Math
-namespace vector3
-{
-	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);
-	const Vector3 FORWARD = Vector3(0, 0, 1);
-	const Vector3 BACKWARD = Vector3(0, 0, -1);
-	const Vector3 LEFT = Vector3(-1, 0, 0);
-	const Vector3 RIGHT = Vector3(1, 0, 0);
-	const Vector3 UP = Vector3(0, 1, 0);
-	const Vector3 DOWN = Vector3(0, -1, 0);
-
-	/// Returns the dot product between the vectors @a a and @a b.
-	float dot(const Vector3& a, const Vector3& b);
-
-	/// Returns the cross product between the vectors @a a and @a b.
-	Vector3 cross(const Vector3& a, const Vector3& b);
-
-	/// Returns the lenght of @a a.
-	float length(const Vector3& a);
-
-	/// Returns the squared length of @a a.
-	float squared_length(const Vector3& a);
-
-	/// Sets the lenght of @a a to @a len.
-	void set_length(Vector3& a, float len);
-
-	/// Normalizes @a a and returns the result.
-	Vector3 normalize(Vector3& a);
-
-	/// Returns the distance between the points @a a and @a b.
-	float distance(const Vector3& a, const Vector3& b);
-
-	/// Returns the angle between the vectors @a a and @a b.
-	float angle(const Vector3& a, const Vector3& b);
+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);
+
+inline Vector3 vector3(float x, float y, float z)
+{
+	Vector3 v;
+	v.x = x;
+	v.y = y;
+	v.z = z;
+	return v;
+}
+
+inline Vector3& operator+=(Vector3& a, const Vector3& b)
+{
+	a.x += b.x;
+	a.y += b.y;
+	a.z += b.z;
+	return a;
+}
 
-	/// Returns the pointer to the data of @a a.
-	float* to_float_ptr(Vector3& a);
+inline Vector3& operator-=(Vector3& a, const Vector3& b)
+{
+	a.x -= b.x;
+	a.y -= b.y;
+	a.z -= b.z;
+	return a;
+}
 
-	/// @copydoc to_float_ptr(Vector3&)
-	const float* to_float_ptr(const Vector3& a);
+inline Vector3& operator*=(Vector3& a, float k)
+{
+	a.x *= k;
+	a.y *= k;
+	a.z *= k;
+	return a;
+}
 
-	/// Returns the Vector2 portion of @a a. (i.e. truncates z)
-	Vector2 to_vector2(const Vector3& a);
-} // namespace vector3
+inline Vector3& operator/=(Vector3& a, float k)
+{
+	CE_ASSERT(k != (float)0.0, "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)
 {
-	return Vector3(-a.x, -a.y, -a.z);
+	return vector3(-a.x, -a.y, -a.z);
 }
 
+/// Adds the vector @a a to @a b and returns the result.
 inline Vector3 operator+(Vector3 a, const Vector3& b)
 {
 	a += b;
 	return a;
 }
 
+/// Subtracts the vector @a b from @a a and returns the result.
 inline Vector3 operator-(Vector3 a, const Vector3& b)
 {
 	a -= b;
 	return a;
 }
 
+/// Multiplies the vector @a a by the scalar @a k and returns the result.
 inline Vector3 operator*(Vector3 a, float k)
 {
 	a *= k;
 	return a;
 }
 
+/// @copydoc operator*(Vector3, float)
 inline Vector3 operator*(float k, Vector3 a)
 {
 	a *= k;
 	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)
 {
 	return equals(a.x, b.x) && equals(a.y, b.y) && equals(a.z, b.z);
 }
 
-namespace vector3
+/// Returns the dot product between the vectors @a a and @a b.
+inline float dot(const Vector3& a, const Vector3& b)
 {
-	inline float dot(const Vector3& a, const Vector3& b)
-	{
-		return a.x * b.x + a.y * b.y + a.z * b.z;
-	}
-
-	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);
-	}
-
-	inline float length(const Vector3& a)
-	{
-		return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
-	}
-
-	inline float squared_length(const Vector3& a)
-	{
-		return a.x * a.x + a.y * a.y + a.z * a.z;
-	}
-
-	inline void set_length(Vector3& a, float len)
-	{
-		normalize(a);
-
-		a.x *= len;
-		a.y *= len;
-		a.z *= len;
-	}
-
-	inline Vector3 normalize(Vector3& a)
-	{
-		float inv_len = 1.0f / length(a);
-
-		a.x *= inv_len;
-		a.y *= inv_len;
-		a.z *= inv_len;
-
-		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 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
+	return a.x * b.x + a.y * b.y + a.z * b.z;
+}
 
-inline Vector3::Vector3()
+/// Returns the cross product between the vectors @a a and @a b.
+inline Vector3 cross(const Vector3& a, const Vector3& b)
 {
-	// Do not initialize
+	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);
 }
 
-inline Vector3::Vector3(float val) : x(val), y(val), z(val)
+/// Returns the lenght of @a a.
+inline float length(const Vector3& a)
 {
+	return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
 }
 
-inline Vector3::Vector3(float nx, float ny, float nz) : x(nx), y(ny), z(nz)
+/// Returns the squared length of @a a.
+inline float squared_length(const Vector3& a)
 {
+	return a.x * a.x + a.y * a.y + a.z * a.z;
 }
 
-inline Vector3::Vector3(const float v[3]) : x(v[0]), y(v[1]), z(v[2])
+/// Normalizes @a a and returns the result.
+inline Vector3 normalize(Vector3& a)
 {
+	float inv_len = 1.0f / length(a);
+	a.x *= inv_len;
+	a.y *= inv_len;
+	a.z *= inv_len;
+	return a;
 }
 
-inline const float& Vector3::operator[](uint32_t i) const
+/// Sets the lenght of @a a to @a len.
+inline void set_length(Vector3& a, float len)
 {
-	CE_ASSERT(i < 3, "Index out of bounds");
+	normalize(a);
 
-	return (&x)[i];
+	a.x *= len;
+	a.y *= len;
+	a.z *= len;
 }
 
-inline float& Vector3::operator[](uint32_t i)
+/// Returns the distance between the points @a a and @a b.
+inline float distance(const Vector3& a, const Vector3& b)
 {
-	CE_ASSERT(i < 3, "Index out of bounds");
-
-	return (&x)[i];
+	return length(b - a);
 }
 
-inline Vector3& Vector3::operator+=(const Vector3& a)
+/// Returns the angle between the vectors @a a and @a b.
+inline float angle(const Vector3& a, const Vector3& b)
 {
-	x += a.x;
-	y += a.y;
-	z += a.z;
-
-	return *this;
+	return acos(dot(a, b) / (length(a) * length(b)));
 }
 
-inline Vector3& Vector3::operator-=(const Vector3& a)
+/// Returns the pointer to the data of @a a.
+inline float* to_float_ptr(Vector3& a)
 {
-	x -= a.x;
-	y -= a.y;
-	z -= a.z;
-
-	return *this;
+	return &a.x;
 }
 
-inline Vector3& Vector3::operator*=(float k)
+/// @copydoc to_float_ptr(Vector3&)
+inline const float* to_float_ptr(const Vector3& a)
 {
-	x *= k;
-	y *= k;
-	z *= k;
-
-	return *this;
+	return &a.x;
 }
 
-inline Vector3& Vector3::operator/=(float k)
+inline Vector2 to_vector2(const Vector3& a)
 {
-	CE_ASSERT(k != (float)0.0, "Division by zero");
-
-	float inv = (float)(1.0 / k);
-
-	x *= inv;
-	y *= inv;
-	z *= inv;
-
-	return *this;
+	return vector2(a.x, a.y);
 }
 
 } // namespace crown

+ 105 - 166
src/core/math/vector4.h

@@ -13,251 +13,190 @@
 namespace crown
 {
 
-/// Negates @a a and returns the result.
-Vector4 operator-(const Vector4& a);
-
-/// Adds the vector @a a to @a b and returns the result.
-Vector4 operator+(Vector4 a, const Vector4& b);
-
-/// Subtracts the vector @a b from @a a and returns the result.
-Vector4 operator-(Vector4 a, const Vector4& b);
-
-/// Multiplies the vector @a a by the scalar @a k and returns the result.
-Vector4 operator*(Vector4 a, float k);
-
-/// @copydoc operator*(Vector4, float)
-Vector4 operator*(float k, Vector4 a);
-
-/// Divides the vector @a a by the scalar @a k and returns the result.
-Vector4 operator/(Vector4 a, float k);
-
-/// Returns true whether the vectors @a a and @a b are equal.
-bool operator==(const Vector4& a, const Vector4& b);
-
 /// Functions to manipulate Vector4.
 ///
 /// @ingroup Math
-namespace vector4
-{
-	const Vector4 ZERO = Vector4(0, 0, 0, 0);
-	const Vector4 XAXIS = Vector4(1, 0, 0, 0);
-	const Vector4 YAXIS = Vector4(0, 1, 0, 0);
-	const Vector4 ZAXIS = Vector4(0, 0, 1, 0);
-	const Vector4 WAXIS = Vector4(0, 0, 0, 1);
-
-	/// Returns the dot product between the vectors @a a and @a b.
-	float dot(const Vector4& a, const Vector4& b);
-
-	/// Returns the lenght of @a a.
-	float length(const Vector4& a);
-
-	/// Returns the squared length of @a a.
-	float squared_length(const Vector4& a);
+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 };
 
-	/// Sets the lenght of @a a to @a len.
-	void set_length(Vector4& a, float len);
+/// Returns the Vector3 portion of @a a. (i.e. truncates w)
+Vector3 to_vector3(const Vector4& a);
 
-	/// Normalizes @a a and returns the result.
-	Vector4 normalize(Vector4& a);
+inline Vector4 vector4(float x, float y, float z, float w)
+{
+	Vector4 v;
+	v.x = x;
+	v.y = y;
+	v.z = z;
+	v.w = w;
+	return v;
+}
 
-	/// Returns the distance between the points @a a and @a b.
-	float distance(const Vector4& a, const Vector4& b);
+inline Vector4 vector4(const Vector3& a, float w)
+{
+	Vector4 v;
+	v.x = a.x;
+	v.y = a.y;
+	v.z = a.z;
+	v.w = w;
+	return v;
+}
 
-	/// Returns the angle between the vectors @a a and @a b.
-	float angle(const Vector4& a, const Vector4& b);
+inline Vector4& operator+=(Vector4& a,	const Vector4& b)
+{
+	a.x += b.x;
+	a.y += b.y;
+	a.z += b.z;
+	a.w += b.w;
+	return a;
+}
 
-	/// Returns the pointer to the data of @a a.
-	float* to_float_ptr(Vector4& a);
+inline Vector4& operator-=(Vector4& a,	const Vector4& b)
+{
+	a.x -= b.x;
+	a.y -= b.y;
+	a.z -= b.z;
+	a.w -= b.w;
+	return a;
+}
 
-	/// @copydoc to_float_ptr(Vector4&)
-	const float* to_float_ptr(const Vector4& a);
+inline Vector4& operator*=(Vector4& a, float k)
+{
+	a.x *= k;
+	a.y *= k;
+	a.z *= k;
+	a.w *= k;
+	return a;
+}
 
-	/// Returns the Vector3 portion of @a a. (i.e. truncates w)
-	Vector3 to_vector3(const Vector4& a);
-} // namespace vector4
+inline Vector4& operator/=(Vector4& a, float k)
+{
+	CE_ASSERT(k != (float)0.0, "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)
 {
-	return Vector4(-a.x, -a.y, -a.z, -a.w);
+	return vector4(-a.x, -a.y, -a.z, -a.w);
 }
 
+/// Adds the vector @a a to @a b and returns the result.
 inline Vector4 operator+(Vector4 a, const Vector4& b)
 {
 	a += b;
 	return a;
 }
 
+/// Subtracts the vector @a b from @a a and returns the result.
 inline Vector4 operator-(Vector4 a, const Vector4& b)
 {
 	a -= b;
 	return a;
 }
 
+/// Multiplies the vector @a a by the scalar @a k and returns the result.
 inline Vector4 operator*(Vector4 a, float k)
 {
 	a *= k;
 	return a;
 }
 
+/// @copydoc operator*(Vector4, float)
 inline Vector4 operator*(float k, Vector4 a)
 {
 	a *= k;
 	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)
 {
 	return equals(a.x, b.x) && equals(a.y, b.y) && equals(a.z, b.z) && equals(a.w, b.w);
 }
 
-namespace vector4
-{
-	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;
-	}
-
-	inline float length(const Vector4& a)
-	{
-		return sqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
-	}
-
-	inline float squared_length(const Vector4& a)
-	{
-		return a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w;
-	}
-
-	inline void set_length(Vector4& a, float len)
-	{
-		normalize(a);
-
-		a.x *= len;
-		a.y *= len;
-		a.z *= len;
-		a.w *= len;
-	}
-
-	inline Vector4 normalize(Vector4& a)
-	{
-		float inv_len = 1.0f / length(a);
-
-		a.x *= inv_len;
-		a.y *= inv_len;
-		a.z *= inv_len;
-		a.w *= inv_len;
-
-		return a;
-	}
-
-	inline float distance(const Vector4& a, const Vector4& b)
-	{
-		return length(b - a);
-	}
-
-	inline float angle(const Vector4& a, const Vector4& b)
-	{
-		return acos(dot(a, b) / (length(a) * length(b)));
-	}
-
-	inline float* to_float_ptr(Vector4& a)
-	{
-		return &a.x;
-	}
-
-	inline const float* to_float_ptr(const Vector4& a)
-	{
-		return &a.x;
-	}
-
-	inline Vector3 to_vector3(const Vector4& a)
-	{
-		return Vector3(a.x, a.y, a.z);
-	}
-}
-
-inline Vector4::Vector4()
+/// Returns the dot product between the vectors @a a and @a b.
+inline float dot(const Vector4& a, const Vector4& b)
 {
-	// Do not initialize
+	return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
 }
 
-inline Vector4::Vector4(const Vector3& a, float w) : x(a.x), y(a.y), z(a.z), w(w)
+/// Returns the lenght of @a a.
+inline float length(const Vector4& a)
 {
+	return sqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
 }
 
-inline Vector4::Vector4(float val) : x(val), y(val), z(val), w(val)
+/// Returns the squared length of @a a.
+inline float squared_length(const Vector4& a)
 {
+	return a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w;
 }
 
-inline Vector4::Vector4(float nx, float ny, float nz, float nw) : x(nx), y(ny), z(nz), w(nw)
-{
-}
-
-inline Vector4::Vector4(const float a[4]) : x(a[0]), y(a[1]), z(a[2]), w(a[3])
+/// Normalizes @a a and returns the result.
+inline Vector4 normalize(Vector4& a)
 {
+	float inv_len = 1.0f / length(a);
+	a.x *= inv_len;
+	a.y *= inv_len;
+	a.z *= inv_len;
+	a.w *= inv_len;
+	return a;
 }
 
-inline const float& Vector4::operator[](uint32_t i) const
+/// Sets the lenght of @a a to @a len.
+inline void set_length(Vector4& a, float len)
 {
-	CE_ASSERT(i < 4, "Index out of bounds");
+	normalize(a);
 
-	return (&x)[i];
+	a.x *= len;
+	a.y *= len;
+	a.z *= len;
+	a.w *= len;
 }
 
-inline float& Vector4::operator[](uint32_t i)
+/// Returns the distance between the points @a a and @a b.
+inline float distance(const Vector4& a, const Vector4& b)
 {
-	CE_ASSERT(i < 4, "Index out of bounds");
-
-	return (&x)[i];
+	return length(b - a);
 }
 
-inline Vector4& Vector4::operator+=(const Vector4& a)
+/// Returns the angle between the vectors @a a and @a b.
+inline float angle(const Vector4& a, const Vector4& b)
 {
-	x += a.x;
-	y += a.y;
-	z += a.z;
-	w += a.w;
-
-	return *this;
+	return acos(dot(a, b) / (length(a) * length(b)));
 }
 
-inline Vector4& Vector4::operator-=(const Vector4& a)
+/// Returns the pointer to the data of @a a.
+inline float* to_float_ptr(Vector4& a)
 {
-	x -= a.x;
-	y -= a.y;
-	z -= a.z;
-	w -= a.w;
-
-	return *this;
+	return &a.x;
 }
 
-inline Vector4& Vector4::operator*=(float k)
+/// @copydoc to_float_ptr(Vector4&)
+inline const float* to_float_ptr(const Vector4& a)
 {
-	x *= k;
-	y *= k;
-	z *= k;
-	w *= k;
-
-	return *this;
+	return &a.x;
 }
 
-inline Vector4& Vector4::operator/=(float k)
+inline Vector3 to_vector3(const Vector4& a)
 {
-	CE_ASSERT(k != (float)0.0, "Division by zero");
-
-	float inv = (float)(1.0 / k);
-
-	x *= inv;
-	y *= inv;
-	z *= inv;
-	w *= inv;
-
-	return *this;
+	return vector3(a.x, a.y, a.z);
 }
 
 } // namespace crown

+ 3 - 3
src/input/mouse.h

@@ -71,7 +71,7 @@ struct Mouse
 	/// to right and +Y extends from top to bottom.
 	Vector2 cursor_xy()
 	{
-		return Vector2(_x, _y);
+		return vector2(_x, _y);
 	}
 
 	/// Sets the position of the cursor in window space.
@@ -96,7 +96,7 @@ struct Mouse
 	/// maximum extent of the cosidered axis.
 	Vector2 cursor_relative_xy()
 	{
-		return Vector2((float) _x / _width, (float) _y / _height);
+		return vector2((float) _x / _width, (float) _y / _height);
 	}
 
 	/// Sets the relative position of the cursor in window space.
@@ -110,7 +110,7 @@ struct Mouse
 	/// maximum extent of the cosidered axis.
 	void set_cursor_relative_xy(const Vector2& position)
 	{
-		set_cursor_xy(Vector2(position.x * (float) _width, position.y * (float) _height));
+		set_cursor_xy(vector2(position.x * (float) _width, position.y * (float) _height));
 	}
 
 	/// Returns the mouse wheel state in the current frame.

+ 2 - 2
src/input/touch.h

@@ -62,8 +62,8 @@ struct Touch
 	/// to right and +Y extends from top to bottom.
 	Vector2 pointer_xy(uint8_t p)
 	{
-		if (p >= MAX_POINTER_IDS) return vector2::ZERO;
-		return Vector2(_x[p], _y[p]);
+		if (p >= MAX_POINTER_IDS) return VECTOR2_ZERO;
+		return vector2(_x[p], _y[p]);
 	}
 
 	void set_position(uint8_t p, uint16_t x, uint16_t y)

+ 4 - 4
src/lua/lua_color4.cpp

@@ -13,10 +13,10 @@ namespace crown
 static int color4_new(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_quaternion(Quaternion(stack.get_float(1),
-							stack.get_float(2),
-							stack.get_float(3),
-							stack.get_float(4)));
+	stack.push_quaternion(quaternion(stack.get_float(1),
+		stack.get_float(2),
+		stack.get_float(3),
+		stack.get_float(4)));
 	return 1;
 }
 

+ 7 - 9
src/lua/lua_matrix4x4.cpp

@@ -11,8 +11,6 @@
 namespace crown
 {
 
-using namespace matrix4x4;
-
 static int matrix4x4_new(lua_State* L)
 {
 	LuaStack stack(L);
@@ -32,7 +30,7 @@ static int matrix4x4_new(lua_State* L)
 	float m13 = stack.get_float(14);
 	float m14 = stack.get_float(15);
 	float m15 = stack.get_float(16);
-	stack.push_matrix4x4(Matrix4x4(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15));
+	stack.push_matrix4x4(matrix4x4(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15));
 	return 1;
 }
 
@@ -46,28 +44,28 @@ static int matrix4x4_ctor(lua_State* L)
 static int matrix4x4_from_quaternion(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_matrix4x4(Matrix4x4(stack.get_quaternion(1), Vector3(0, 0, 0)));
+	stack.push_matrix4x4(matrix4x4(stack.get_quaternion(1), vector3(0, 0, 0)));
 	return 1;
 }
 
 static int matrix4x4_from_translation(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_matrix4x4(Matrix4x4(quaternion::IDENTITY, stack.get_vector3(1)));
+	stack.push_matrix4x4(matrix4x4(QUATERNION_IDENTITY, stack.get_vector3(1)));
 	return 1;
 }
 
 static int matrix4x4_from_quaternion_translation(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_matrix4x4(Matrix4x4(stack.get_quaternion(1), stack.get_vector3(2)));
+	stack.push_matrix4x4(matrix4x4(stack.get_quaternion(1), stack.get_vector3(2)));
 	return 1;
 }
 
 static int matrix4x4_from_axes(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_matrix4x4(Matrix4x4(stack.get_vector3(1), stack.get_vector3(2), stack.get_vector3(3), stack.get_vector3(4)));
+	stack.push_matrix4x4(matrix4x4(stack.get_vector3(1), stack.get_vector3(2), stack.get_vector3(3), stack.get_vector3(4)));
 	return 1;
 }
 
@@ -186,7 +184,7 @@ static int matrix4x4_set_rotation(lua_State* L)
 static int matrix4x4_identity(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_matrix4x4(matrix4x4::IDENTITY);
+	stack.push_matrix4x4(MATRIX4X4_IDENTITY);
 	return 1;
 }
 
@@ -195,7 +193,7 @@ static int matrix4x4_to_string(lua_State* L)
 	LuaStack stack(L);
 	Matrix4x4& a = stack.get_matrix4x4(1);
 	stack.push_fstring("%.1f, %.1f, %.1f, %.1f\n%.1f, %.1f, %.1f, %.1f\n%.1f, %.1f, %.1f, %.1f\n%.1f, %.1f, %.1f, %.1f\n",
-						a[0], a[4], a[8], a[12], a[1], a[5], a[9], a[13], a[2], a[6], a[10], a[14], a[3], a[7], a[11], a[15]);
+						a.x.x, a.x.y, a.x.z, a.y.w, a.y.x, a.y.y, a.y.z, a.y.w, a.z.x, a.z.y, a.z.z, a.z.w, a.t.x, a.t.y, a.t.z, a.t.w);
 	return 1;
 }
 

+ 10 - 12
src/lua/lua_quaternion.cpp

@@ -15,7 +15,7 @@ namespace crown
 static int quaternion_new(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_quaternion(Quaternion(stack.get_vector3(1), stack.get_float(2)));
+	stack.push_quaternion(quaternion(stack.get_vector3(1), stack.get_float(2)));
 	return 1;
 }
 
@@ -36,35 +36,35 @@ static int quaternion_negate(lua_State* L)
 static int quaternion_identity(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_quaternion(quaternion::IDENTITY);
+	stack.push_quaternion(QUATERNION_IDENTITY);
 	return 1;
 }
 
 static int quaternion_length(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(quaternion::length(stack.get_quaternion(1)));
+	stack.push_float(length(stack.get_quaternion(1)));
 	return 1;
 }
 
 static int quaternion_normalize(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_quaternion(quaternion::normalize(stack.get_quaternion(1)));
+	stack.push_quaternion(normalize(stack.get_quaternion(1)));
 	return 1;
 }
 
 static int quaternion_conjugate(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_quaternion(quaternion::conjugate(stack.get_quaternion(1)));
+	stack.push_quaternion(conjugate(stack.get_quaternion(1)));
 	return 1;
 }
 
 static int quaternion_inverse(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_quaternion(quaternion::inverse(stack.get_quaternion(1)));
+	stack.push_quaternion(inverse(stack.get_quaternion(1)));
 	return 1;
 }
 
@@ -85,7 +85,7 @@ static int quaternion_multiply_by_scalar(lua_State* L)
 static int quaternion_power(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_quaternion(quaternion::power(stack.get_quaternion(1), stack.get_float(2)));
+	stack.push_quaternion(power(stack.get_quaternion(1), stack.get_float(2)));
 	return 1;
 }
 
@@ -104,12 +104,10 @@ static int quaternionbox_new(lua_State* L)
 {
 	LuaStack stack(L);
 
-	if (stack.num_args() == 0)
-		stack.push_quaternionbox(Quaternion());
-	else if (stack.num_args() == 1)
+	if (stack.num_args() == 1)
 		stack.push_quaternionbox(stack.get_quaternion(1));
 	else
-		stack.push_quaternionbox(Quaternion(stack.get_float(1)
+		stack.push_quaternionbox(quaternion(stack.get_float(1)
 			, stack.get_float(2)
 			, stack.get_float(3)
 			, stack.get_float(4)));
@@ -133,7 +131,7 @@ static int quaternionbox_store(lua_State* L)
 	if (stack.num_args() == 2)
 		q = stack.get_quaternion(2);
 	else
-		q = Quaternion(stack.get_float(2)
+		q = quaternion(stack.get_float(2)
 			, stack.get_float(3)
 			, stack.get_float(4)
 			, stack.get_float(5));

+ 3 - 3
src/lua/lua_stack.cpp

@@ -18,7 +18,7 @@ Vector2 LuaStack::get_vector2(int i)
 {
 	void* v = CHECKLIGHTDATA(L, i, is_vector3, "Vector2");
 	Vector3& vv = *(Vector3*)v;
-	return Vector2(vv.x, vv.y);
+	return vector2(vv.x, vv.y);
 }
 
 Vector3& LuaStack::get_vector3(int i)
@@ -44,12 +44,12 @@ Color4 LuaStack::get_color4(int i)
 	// Color4 represented as Quaternion
 	void* c = CHECKLIGHTDATA(L, i, is_quaternion, "Color4");
 	Quaternion& q = *(Quaternion*)c;
-	return Color4(q.x, q.y, q.z, q.w);
+	return color4(q.x, q.y, q.z, q.w);
 }
 
 void LuaStack::push_vector2(const Vector2& v)
 {
-	push_vector3(Vector3(v.x, v.y, 0.0f));
+	push_vector3(vector3(v.x, v.y, 0.0f));
 }
 
 void LuaStack::push_vector3(const Vector3& v)

+ 18 - 18
src/lua/lua_vector3.cpp

@@ -14,7 +14,7 @@ namespace crown
 static int vector3_new(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector3(Vector3(stack.get_float(1), stack.get_float(2), stack.get_float(3)));
+	stack.push_vector3(vector3(stack.get_float(1), stack.get_float(2), stack.get_float(3)));
 	return 1;
 }
 
@@ -108,14 +108,14 @@ static int vector3_divide(lua_State* L)
 static int vector3_dot(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(vector3::dot(stack.get_vector3(1), stack.get_vector3(2)));
+	stack.push_float(dot(stack.get_vector3(1), stack.get_vector3(2)));
 	return 1;
 }
 
 static int vector3_cross(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector3(vector3::cross(stack.get_vector3(1), stack.get_vector3(2)));
+	stack.push_vector3(cross(stack.get_vector3(1), stack.get_vector3(2)));
 	return 1;
 }
 
@@ -129,91 +129,91 @@ static int vector3_equal(lua_State* L)
 static int vector3_length(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(vector3::length(stack.get_vector3(1)));
+	stack.push_float(length(stack.get_vector3(1)));
 	return 1;
 }
 
 static int vector3_squared_length(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(vector3::squared_length(stack.get_vector3(1)));
+	stack.push_float(squared_length(stack.get_vector3(1)));
 	return 1;
 }
 
 static int vector3_set_length(lua_State* L)
 {
 	LuaStack stack(L);
-	vector3::set_length(stack.get_vector3(1), stack.get_float(2));
+	set_length(stack.get_vector3(1), stack.get_float(2));
 	return 0;
 }
 
 static int vector3_normalize(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector3(vector3::normalize(stack.get_vector3(1)));
+	stack.push_vector3(normalize(stack.get_vector3(1)));
 	return 1;
 }
 
 static int vector3_distance(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(vector3::distance(stack.get_vector3(1), stack.get_vector3(2)));
+	stack.push_float(distance(stack.get_vector3(1), stack.get_vector3(2)));
 	return 1;
 }
 
 static int vector3_angle(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_float(vector3::angle(stack.get_vector3(1), stack.get_vector3(2)));
+	stack.push_float(angle(stack.get_vector3(1), stack.get_vector3(2)));
 	return 1;
 }
 
 static int vector3_forward(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector3(vector3::FORWARD);
+	stack.push_vector3(VECTOR3_FORWARD);
 	return 1;
 }
 
 static int vector3_backward(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector3(vector3::BACKWARD);
+	stack.push_vector3(VECTOR3_BACKWARD);
 	return 1;
 }
 
 static int vector3_left(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector3(vector3::LEFT);
+	stack.push_vector3(VECTOR3_LEFT);
 	return 1;
 }
 
 static int vector3_right(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector3(vector3::RIGHT);
+	stack.push_vector3(VECTOR3_RIGHT);
 	return 1;
 }
 
 static int vector3_up(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector3(vector3::UP);
+	stack.push_vector3(VECTOR3_UP);
 	return 1;
 }
 
 static int vector3_down(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector3(vector3::DOWN);
+	stack.push_vector3(VECTOR3_DOWN);
 	return 1;
 }
 
 static int vector2_new(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_vector2(Vector2(stack.get_float(1), stack.get_float(2)));
+	stack.push_vector2(vector2(stack.get_float(1), stack.get_float(2)));
 	return 1;
 }
 
@@ -233,7 +233,7 @@ static int vector3box_new(lua_State* L)
 	else if (stack.num_args() == 1)
 		stack.push_vector3box(stack.get_vector3(1));
 	else
-		stack.push_vector3box(Vector3(stack.get_float(1)
+		stack.push_vector3box(vector3(stack.get_float(1)
 			, stack.get_float(2)
 			, stack.get_float(3)));
 
@@ -256,7 +256,7 @@ static int vector3box_store(lua_State* L)
 	if (stack.num_args() == 2)
 		v = stack.get_vector3(2);
 	else
-		v = Vector3(stack.get_float(2)
+		v = vector3(stack.get_float(2)
 			, stack.get_float(3)
 			, stack.get_float(4));
 

+ 3 - 3
src/lua/lua_world.cpp

@@ -21,8 +21,8 @@ static int world_spawn_unit(lua_State* L)
 	LuaStack stack(L);
 	World* world = stack.get_world(1);
 	const StringId64 name = stack.get_resource_id(2);
-	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;
+	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;
 
 	LUA_ASSERT(device()->resource_manager()->can_get(UNIT_TYPE, name), stack, "Unit not found");
 
@@ -108,7 +108,7 @@ static int world_play_sound(lua_State* L)
 	const int32_t nargs = stack.num_args();
 	const bool loop = nargs > 2 ? stack.get_bool(3) : false;
 	const float volume = nargs > 3 ? stack.get_float(4) : 1.0f;
-	const Vector3& pos = nargs > 4 ? stack.get_vector3(5) : vector3::ZERO;
+	const Vector3& pos = nargs > 4 ? stack.get_vector3(5) : VECTOR3_ZERO;
 	const float range = nargs > 5 ? stack.get_float(6) : 1000.0f;
 
 	LUA_ASSERT(device()->resource_manager()->can_get(SOUND_TYPE, name), stack, "Sound not found");

+ 10 - 12
src/physics/actor.cpp

@@ -49,7 +49,7 @@ void Actor::create_objects()
 	// Create rigid body
 	TransformInstance ti = m_scene_graph.get(m_unit);
 	const Matrix4x4 tr = m_scene_graph.world_pose(ti);
-	const PxMat44 pose((PxReal*) matrix4x4::to_float_ptr(tr));
+	const PxMat44 pose((PxReal*) to_float_ptr(tr));
 
 	if (actor_class->flags & PhysicsActor2::DYNAMIC)
 	{
@@ -182,19 +182,19 @@ void Actor::destroy_objects()
 Vector3 Actor::world_position() const
 {
 	const PxTransform tr = m_actor->getGlobalPose();
-	return Vector3(tr.p.x, tr.p.y, tr.p.z);
+	return vector3(tr.p.x, tr.p.y, tr.p.z);
 }
 
 Quaternion Actor::world_rotation() const
 {
 	const PxTransform tr = m_actor->getGlobalPose();
-	return Quaternion(tr.q.x, tr.q.y, tr.q.z, tr.q.w);
+	return quaternion(tr.q.x, tr.q.y, tr.q.z, tr.q.w);
 }
 
 Matrix4x4 Actor::world_pose() const
 {
 	const PxTransform tr = m_actor->getGlobalPose();
-	return Matrix4x4(Quaternion(tr.q.x, tr.q.y, tr.q.z, tr.q.w), Vector3(tr.p.x, tr.p.y, tr.p.z));
+	return matrix4x4(quaternion(tr.q.x, tr.q.y, tr.q.z, tr.q.w), vector3(tr.p.x, tr.p.y, tr.p.z));
 }
 
 void Actor::teleport_world_position(const Vector3& p)
@@ -218,8 +218,6 @@ void Actor::teleport_world_rotation(const Quaternion& r)
 
 void Actor::teleport_world_pose(const Matrix4x4& m)
 {
-	using namespace matrix4x4;
-
 	const PxVec3 x(m.x.x, m.x.y, m.x.z);
 	const PxVec3 y(m.y.x, m.y.y, m.y.z);
 	const PxVec3 z(m.z.x, m.z.y, m.z.z);
@@ -230,10 +228,10 @@ void Actor::teleport_world_pose(const Matrix4x4& m)
 Vector3 Actor::center_of_mass() const
 {
 	if (is_static())
-		return Vector3(0, 0, 0);
+		return vector3(0, 0, 0);
 
 	const PxTransform tr = static_cast<PxRigidBody*>(m_actor)->getCMassLocalPose();
-	return Vector3(tr.p.x, tr.p.y, tr.p.z);
+	return vector3(tr.p.x, tr.p.y, tr.p.z);
 }
 
 void Actor::enable_gravity()
@@ -376,10 +374,10 @@ void Actor::set_angular_damping(float rate)
 Vector3 Actor::linear_velocity() const
 {
 	if (is_static())
-		return Vector3(0, 0, 0);
+		return vector3(0, 0, 0);
 
 	const PxVec3 vel = static_cast<PxRigidBody*>(m_actor)->getLinearVelocity();
-	return Vector3(vel.x, vel.y, vel.z);
+	return vector3(vel.x, vel.y, vel.z);
 }
 
 void Actor::set_linear_velocity(const Vector3& vel)
@@ -394,10 +392,10 @@ void Actor::set_linear_velocity(const Vector3& vel)
 Vector3 Actor::angular_velocity() const
 {
 	if (is_static())
-		return Vector3(0, 0, 0);
+		return vector3(0, 0, 0);
 
 	const PxVec3 vel = static_cast<PxRigidBody*>(m_actor)->getAngularVelocity();
-	return Vector3(vel.x, vel.y, vel.z);
+	return vector3(vel.x, vel.y, vel.z);
 }
 
 void Actor::set_angular_velocity(const Vector3& vel)

+ 1 - 1
src/physics/controller.cpp

@@ -71,7 +71,7 @@ void Controller::set_height(float height)
 Vector3 Controller::position() const
 {
 	PxExtendedVec3 pos = m_controller->getPosition();
-	return Vector3(pos.x, pos.y, pos.z);
+	return vector3(pos.x, pos.y, pos.z);
 }
 
 bool Controller::collides_up() const

+ 2 - 2
src/physics/physics_callback.h

@@ -87,8 +87,8 @@ public:
 
 			post_collision_event((Actor*) pair_header.actors[0]->userData,
 				(Actor*) pair_header.actors[1]->userData,
-				Vector3(where.x, where.y, where.z),
-				Vector3(normal.x, normal.y, normal.z),
+				vector3(where.x, where.y, where.z),
+				vector3(normal.x, normal.y, normal.z),
 				(cp.events & PxPairFlag::eNOTIFY_TOUCH_FOUND) ?
 					physics_world::CollisionEvent::BEGIN_TOUCH :
 					physics_world::CollisionEvent::END_TOUCH);

+ 7 - 7
src/physics/physics_world.cpp

@@ -317,7 +317,7 @@ Raycast* PhysicsWorld::get_raycast(RaycastId id)
 Vector3 PhysicsWorld::gravity() const
 {
 	PxVec3 g = m_scene->getGravity();
-	return Vector3(g.x, g.y, g.z);
+	return vector3(g.x, g.y, g.z);
 }
 
 void PhysicsWorld::set_gravity(const Vector3& g)
@@ -379,10 +379,10 @@ void PhysicsWorld::update(float dt)
 		if (active_transforms[i].userData == NULL) continue;
 
 		const PxTransform tr = active_transforms[i].actor2World;
-		const Vector3 pos(tr.p.x, tr.p.y, tr.p.z);
-		const Quaternion rot(tr.q.x, tr.q.y, tr.q.z, tr.q.w);
+		const Vector3 pos = vector3(tr.p.x, tr.p.y, tr.p.z);
+		const Quaternion rot = quaternion(tr.q.x, tr.q.y, tr.q.z, tr.q.w);
 
-		static_cast<Actor*>(active_transforms[i].userData)->update(Matrix4x4(rot, pos));
+		static_cast<Actor*>(active_transforms[i].userData)->update(matrix4x4(rot, pos));
 	}
 
 	// Update controllers
@@ -400,9 +400,9 @@ void PhysicsWorld::draw_debug(DebugLine& lines)
 	for(PxU32 i = 0; i < rb.getNbLines(); i++)
 	{
 		const PxDebugLine& pxline = rb.getLines()[i];
-		lines.add_line(Vector3(pxline.pos0.x, pxline.pos0.y, pxline.pos0.z),
-						Vector3(pxline.pos1.x, pxline.pos1.y, pxline.pos1.z),
-						Color4(pxline.color0));
+		lines.add_line(vector3(pxline.pos0.x, pxline.pos0.y, pxline.pos0.z),
+			vector3(pxline.pos1.x, pxline.pos1.y, pxline.pos1.z),
+			color4(pxline.color0, pxline.color0, pxline.color0, 1.0f));
 	}
 
 	lines.commit();

+ 12 - 12
src/renderers/debug_line.cpp

@@ -138,12 +138,12 @@ void DebugLine::add_line(const Vector3& start, const Vector3& end, const Color4&
 	_lines[_num].p0[0] = start.x;
 	_lines[_num].p0[1] = start.y;
 	_lines[_num].p0[2] = start.z;
-	_lines[_num].c0    = color4::to_abgr(color);
+	_lines[_num].c0    = to_abgr(color);
 
 	_lines[_num].p1[0] = end.x;
 	_lines[_num].p1[1] = end.y;
 	_lines[_num].p1[2] = end.z;
-	_lines[_num].c1    = color4::to_abgr(color);
+	_lines[_num].c1    = to_abgr(color);
 
 	_num++;
 }
@@ -158,28 +158,28 @@ void DebugLine::add_sphere(const Vector3& center, const float radius, const Colo
 		const float rad1 = to_rad((float) deg + deg_step);
 
 		// XZ plane
-		const Vector3 start0(cos(rad0) * radius, 0, -sin(rad0) * radius);
-		const Vector3 end0  (cos(rad1) * radius, 0, -sin(rad1) * radius);
+		const Vector3 start0 = vector3(cos(rad0) * radius, 0, -sin(rad0) * radius);
+		const Vector3 end0   = vector3(cos(rad1) * radius, 0, -sin(rad1) * radius);
 		add_line(center + start0, center + end0, color);
 
 		// XY plane
-		const Vector3 start1(cos(rad0) * radius, sin(rad0) * radius, 0);
-		const Vector3 end1  (cos(rad1) * radius, sin(rad1) * radius, 0);
+		const Vector3 start1 = vector3(cos(rad0) * radius, sin(rad0) * radius, 0);
+		const Vector3 end1   = vector3(cos(rad1) * radius, sin(rad1) * radius, 0);
 		add_line(center + start1, center + end1, color);
 
 		// YZ plane
-		const Vector3 start2(0, sin(rad0) * radius, -cos(rad0) * radius);
-		const Vector3 end2  (0, sin(rad1) * radius, -cos(rad1) * radius);
+		const Vector3 start2 = vector3(0, sin(rad0) * radius, -cos(rad0) * radius);
+		const Vector3 end2   = vector3(0, sin(rad1) * radius, -cos(rad1) * radius);
 		add_line(center + start2, center + end2, color);
 	}
 }
 
 void DebugLine::add_obb(const Matrix4x4& tm, const Vector3& extents, const Color4& color)
 {
-	const Vector3 o = Vector3(tm.t.x, tm.t.y, tm.t.z);
-	const Vector3 x = Vector3(tm.x.x, tm.x.y, tm.x.z) * (extents.x * 0.5f);
-	const Vector3 y = Vector3(tm.y.x, tm.y.y, tm.y.z) * (extents.y * 0.5f);
-	const Vector3 z = Vector3(tm.z.x, tm.z.y, tm.z.z) * (extents.z * 0.5f);
+	const Vector3 o = vector3(tm.t.x, tm.t.y, tm.t.z);
+	const Vector3 x = vector3(tm.x.x, tm.x.y, tm.x.z) * (extents.x * 0.5f);
+	const Vector3 y = vector3(tm.y.x, tm.y.y, tm.y.z) * (extents.y * 0.5f);
+	const Vector3 z = vector3(tm.z.x, tm.z.y, tm.z.z) * (extents.z * 0.5f);
 
 	// Back face
 	add_line(o - x - y - z, o + x - y - z, color);

+ 7 - 9
src/renderers/gui.cpp

@@ -16,8 +16,6 @@
 namespace crown
 {
 
-using namespace matrix4x4;
-
 struct VertexData
 {
 	float x;
@@ -89,7 +87,7 @@ void Gui::init()
 Gui::Gui(uint16_t width, uint16_t height, const char* material)
 	: m_width(width)
 	, m_height(height)
-	, m_pose(matrix4x4::IDENTITY)
+	, m_pose(MATRIX4X4_IDENTITY)
 {
 	set_orthographic(m_projection, 0, width, 0, height, -0.01f, 100.0f);
 
@@ -108,18 +106,18 @@ void Gui::set_id(const GuiId id)
 
 Vector2 Gui::resolution() const
 {
-	return Vector2(m_width, m_height);
+	return vector2(m_width, m_height);
 }
 
 void Gui::move(const Vector2& pos)
 {
 	set_identity(m_pose);
-	set_translation(m_pose, Vector3(pos.x, pos.y, 0));
+	set_translation(m_pose, vector3(pos.x, pos.y, 0));
 }
 
 Vector2 Gui::screen_to_gui(const Vector2& pos)
 {
-	return Vector2(pos.x, m_height - pos.y);
+	return vector2(pos.x, m_height - pos.y);
 }
 
 void Gui::draw_rectangle(const Vector3& pos, const Vector2& size, const Color4& color)
@@ -148,7 +146,7 @@ void Gui::draw_rectangle(const Vector3& pos, const Vector2& size, const Color4&
 	inds[5] = 3;
 
 	material_manager::get()->lookup_material(m_material)->bind();
-	bgfx::setViewTransform(1, matrix4x4::to_float_ptr(matrix4x4::IDENTITY), matrix4x4::to_float_ptr(m_projection));
+	bgfx::setViewTransform(1, to_float_ptr(MATRIX4X4_IDENTITY), to_float_ptr(m_projection));
 	bgfx::setViewRect(1, 0, 0, m_width, m_height);
 	bgfx::setState(BGFX_STATE_DEFAULT);
 	bgfx::setVertexBuffer(&tvb);
@@ -158,7 +156,7 @@ void Gui::draw_rectangle(const Vector3& pos, const Vector2& size, const Color4&
 
 void Gui::draw_image(const char* material, const Vector3& pos, const Vector2& size, const Color4& color)
 {
-	draw_image_uv(material, pos, size, Vector2(0, 0), Vector2(1, 1), color);
+	draw_image_uv(material, pos, size, vector2(0, 0), vector2(1, 1), color);
 }
 
 void Gui::draw_image_uv(const char* material, const Vector3& pos, const Vector2& size, const Vector2& uv0, const Vector2& uv1, const Color4& color)
@@ -201,7 +199,7 @@ void Gui::draw_image_uv(const char* material, const Vector3& pos, const Vector2&
 	Material* mat = material_manager::get()->lookup_material(res_id.name);
 	mat->bind();*/
 
-	bgfx::setViewTransform(1, matrix4x4::to_float_ptr(matrix4x4::IDENTITY), matrix4x4::to_float_ptr(m_projection));
+	bgfx::setViewTransform(1, to_float_ptr(MATRIX4X4_IDENTITY), to_float_ptr(m_projection));
 	bgfx::setViewRect(1, 0, 0, m_width, m_height);
 	bgfx::setState(BGFX_STATE_DEFAULT);
 	bgfx::setVertexBuffer(&tvb);

+ 4 - 4
src/renderers/gui.h

@@ -33,19 +33,19 @@ struct Gui
 
 	/// Draws a rectangle of size @a size at @a pos.
 	/// @note Higher values of pos.z make the object appear in front of other objects.
-	void draw_rectangle(const Vector3& pos, const Vector2& size, const Color4& color = color4::WHITE);
+	void draw_rectangle(const Vector3& pos, const Vector2& size, const Color4& color = COLOR4_WHITE);
 
 	/// Draws an image with the given @a material.
 	/// @note Higher values of pos.z make the object appear in front of other objects.
-	void draw_image(const char* material, const Vector3& pos, const Vector2& size, const Color4& color = color4::WHITE);
+	void draw_image(const char* material, const Vector3& pos, const Vector2& size, const Color4& color = COLOR4_WHITE);
 
 	/// Draws an image with the given @a material and @a uv0 and @a uv1 coordinates.
 	/// @note Higher values of pos.z make the object appear in front of other objects.
-	void draw_image_uv(const char* material, const Vector3& pos, const Vector2& size, const Vector2& uv0, const Vector2& uv1, const Color4& color = color4::WHITE);
+	void draw_image_uv(const char* material, const Vector3& pos, const Vector2& size, const Vector2& uv0, const Vector2& uv1, const Color4& color = COLOR4_WHITE);
 
 	/// Draws the text @a str with the given @a font and @a font_size.
 	/// @note Higher values of pos.z make the object appear in front of other objects.
-	void draw_text(const char* str, const char* font, uint32_t font_size, const Vector3& pos, const Color4& color = color4::WHITE);
+	void draw_text(const char* str, const char* font, uint32_t font_size, const Vector3& pos, const Color4& color = COLOR4_WHITE);
 
 public:
 

+ 1 - 1
src/renderers/render_world.cpp

@@ -75,7 +75,7 @@ void RenderWorld::update(const Matrix4x4& view, const Matrix4x4& projection, uin
 		, 0);
 
 	// Set view and projection matrix for view 0.
-	bgfx::setViewTransform(0, matrix4x4::to_float_ptr(view), matrix4x4::to_float_ptr(projection));
+	bgfx::setViewTransform(0, to_float_ptr(view), to_float_ptr(projection));
 	bgfx::setViewRect(0, 0, 0, width, height);
 
 	// This dummy draw call is here to make sure that view 0 is cleared

+ 1 - 1
src/renderers/sprite.cpp

@@ -58,7 +58,7 @@ void Sprite::render()
 	bgfx::setVertexBuffer(m_resource->vb);
 	bgfx::setIndexBuffer(m_resource->ib, m_frame * 6, 6);
 	TransformInstance ti = m_scene_graph.get(_unit_id);
-	bgfx::setTransform(matrix4x4::to_float_ptr(m_scene_graph.world_pose(ti)));
+	bgfx::setTransform(to_float_ptr(m_scene_graph.world_pose(ti)));
 	bgfx::submit(0, _depth);
 }
 

+ 3 - 3
src/resource/mesh_resource.cpp

@@ -97,17 +97,17 @@ namespace mesh_resource
 			MeshVertex v;
 
 			uint16_t p_idx = position_index[i] * 3;
-			v.position = Vector3(positions[p_idx], positions[p_idx + 1], positions[p_idx + 2]);
+			v.position = vector3(positions[p_idx], positions[p_idx + 1], positions[p_idx + 2]);
 
 			if (has_normal)
 			{
 				uint16_t n_idx = normal_index[i] * 3;
-				v.normal = Vector3(normals[n_idx], normals[n_idx + 1], normals[n_idx + 2]);
+				v.normal = vector3(normals[n_idx], normals[n_idx + 1], normals[n_idx + 2]);
 			}
 			if (has_texcoord)
 			{
 				uint16_t t_idx = texcoord_index[i] * 2;
-				v.texcoord = Vector2(texcoords[t_idx], texcoords[t_idx + 1]);
+				v.texcoord = vector2(texcoords[t_idx], texcoords[t_idx + 1]);
 			}
 
 			uint32_t f_idx = 0;

+ 2 - 2
src/resource/physics_resource.cpp

@@ -181,8 +181,8 @@ namespace physics_resource
 			pj.type         = joint_type_to_enum(jtype.c_str());
 			pj.actor_0      = joint.key("actor_0").to_string_id();
 			pj.actor_1      = joint.key("actor_1").to_string_id();
-			pj.anchor_0     = joint.key_or_nil("anchor_0").to_vector3(vector3::ZERO);
-			pj.anchor_1     = joint.key_or_nil("anchor_1").to_vector3(vector3::ZERO);
+			pj.anchor_0     = joint.key_or_nil("anchor_0").to_vector3(VECTOR3_ZERO);
+			pj.anchor_1     = joint.key_or_nil("anchor_1").to_vector3(VECTOR3_ZERO);
 			pj.restitution  = joint.key_or_nil("restitution").to_float(0.5f);
 			pj.spring       = joint.key_or_nil("spring").to_float(100.0f);
 			pj.damping      = joint.key_or_nil("damping").to_float(0.0f);

+ 3 - 5
src/resource/unit_resource.cpp

@@ -140,10 +140,8 @@ namespace unit_resource
 				gn.parent = parent_name.to_string_id();
 			}
 
-			JSONElement pos = node.key("position");
-			JSONElement rot = node.key("rotation");
-			gn.position = Vector3(pos[0].to_float(), pos[1].to_float(), pos[2].to_float());
-			gn.rotation = Quaternion(Vector3(rot[0].to_float(), rot[1].to_float(), rot[2].to_float()), rot[3].to_float());
+			gn.position = node.key("position").to_vector3();
+			gn.rotation = node.key("rotation").to_quaternion();
 
 			GraphNodeDepth gnd;
 			gnd.name = gn.name;
@@ -355,7 +353,7 @@ namespace unit_resource
 			UnitNode un;
 			un.name = node.name;
 			un.parent = find_node_parent_index(i, m_nodes, m_node_depths);
-			un.pose = Matrix4x4(node.rotation, node.position);
+			un.pose = matrix4x4(node.rotation, node.position);
 
 			opts.write(un.name);
 			opts.write(un.pose);

+ 6 - 10
src/world/camera.cpp

@@ -45,7 +45,7 @@ const Matrix4x4& Camera::projection_matrix() const
 Matrix4x4 Camera::view_matrix() const
 {
 	Matrix4x4 view = _scene_graph.world_pose(_scene_graph.get(_unit_id));
-	matrix4x4::invert(view);
+	invert(view);
 	return view;
 }
 
@@ -113,28 +113,24 @@ void Camera::set_viewport_metrics(uint16_t x, uint16_t y, uint16_t width, uint16
 
 Vector3 Camera::screen_to_world(const Vector3& pos)
 {
-	using namespace matrix4x4;
-
 	Matrix4x4 mvp = view_matrix() * _projection;
 	invert(mvp);
 
-	Vector4 ndc( (2 * (pos.x - 0)) / _view_width - 1,
+	Vector4 ndc = vector4( (2 * (pos.x - 0)) / _view_width - 1,
 				 (2 * (_view_height - pos.y)) / _view_height - 1,
 				 (2 * pos.z) - 1, 1);
 
 	Vector4 tmp = ndc * mvp;
 	tmp *= 1.0f / tmp.w;
 
-	return Vector3(tmp.x, tmp.y, tmp.z);
+	return vector3(tmp.x, tmp.y, tmp.z);
 }
 
 Vector3 Camera::world_to_screen(const Vector3& pos)
 {
-	using namespace matrix4x4;
-
 	Vector3 ndc = pos * (view_matrix() * _projection);
 
-	return Vector3( (_view_x + _view_width * (ndc.x + 1.0f)) / 2.0f,
+	return vector3( (_view_x + _view_width * (ndc.x + 1.0f)) / 2.0f,
 					(_view_y + _view_height * (ndc.y + 1.0f)) / 2.0f,
 					(ndc.z + 1.0f) / 2.0f);
 }
@@ -145,12 +141,12 @@ void Camera::update_projection_matrix()
 	{
 		case ProjectionType::ORTHOGRAPHIC:
 		{
-			matrix4x4::set_orthographic(_projection, _left, _right, _bottom, _top, _near, _far);
+			set_orthographic(_projection, _left, _right, _bottom, _top, _near, _far);
 			break;
 		}
 		case ProjectionType::PERSPECTIVE:
 		{
-			matrix4x4::set_perspective(_projection, _FOV, _aspect, _near, _far);
+			set_perspective(_projection, _FOV, _aspect, _near, _far);
 			break;
 		}
 		default:

+ 4 - 8
src/world/scene_graph.cpp

@@ -16,10 +16,6 @@
 namespace crown
 {
 
-using namespace vector3;
-using namespace matrix3x3;
-using namespace matrix4x4;
-
 SceneGraph::SceneGraph(Allocator& a)
 	: _allocator(a)
 	, _map(a)
@@ -129,7 +125,7 @@ void SceneGraph::set_local_position(TransformInstance i, const Vector3& pos)
 
 void SceneGraph::set_local_rotation(TransformInstance i, const Quaternion& rot)
 {
-	_data.local[i.i].rotation = Matrix3x3(rot);
+	_data.local[i.i].rotation = matrix3x3(rot);
 	set_local(i);
 }
 
@@ -162,7 +158,7 @@ Vector3 SceneGraph::local_scale(TransformInstance i) const
 
 Matrix4x4 SceneGraph::local_pose(TransformInstance i) const
 {
-	Matrix4x4 tr(rotation(_data.local[i.i].rotation), _data.local[i.i].position);
+	Matrix4x4 tr = matrix4x4(rotation(_data.local[i.i].rotation), _data.local[i.i].position);
 	set_scale(tr, _data.local[i.i].scale);
 	return tr;
 }
@@ -234,7 +230,7 @@ void SceneGraph::link(TransformInstance child, TransformInstance parent)
 	const Matrix4x4 rel_tr = child_tr * get_inverted(parent_tr);
 
 	_data.local[child.i].position = translation(rel_tr);
-	_data.local[child.i].rotation = rotation(rel_tr);
+	_data.local[child.i].rotation = to_matrix3x3(rel_tr);
 	_data.local[child.i].scale = cs;
 	_data.parent[child.i] = parent;
 
@@ -267,7 +263,7 @@ bool SceneGraph::is_valid(TransformInstance i)
 void SceneGraph::set_local(TransformInstance i)
 {
 	TransformInstance parent = _data.parent[i.i];
-	Matrix4x4 parent_tm = is_valid(parent) ? _data.world[parent.i] : matrix4x4::IDENTITY;
+	Matrix4x4 parent_tm = is_valid(parent) ? _data.world[parent.i] : MATRIX4X4_IDENTITY;
 	transform(parent_tm, i);
 }
 

+ 1 - 4
src/world/scene_graph.h

@@ -99,9 +99,6 @@ public:
 	{
 		Pose& operator=(const Matrix4x4& m)
 		{
-			using namespace matrix3x3;
-			using namespace matrix4x4;
-			using namespace vector3;
 			Matrix3x3 rotm = to_matrix3x3(m);
 			normalize(rotm.x);
 			normalize(rotm.y);
@@ -109,7 +106,7 @@ public:
 
 			position = translation(m);
 			rotation = rotm;
-			scale = matrix4x4::scale(m);
+			scale = crown::scale(m);
 			return *this;
 		}
 

+ 1 - 1
src/world/world.cpp

@@ -61,7 +61,7 @@ UnitId World::spawn_unit(const UnitResource* ur, const Vector3& pos, const Quate
 {
 	Unit* u = (Unit*) m_unit_pool.allocate(sizeof(Unit), CE_ALIGNOF(Unit));
 	const UnitId unit_id = id_array::create(m_units, u);
-	new (u) Unit(*this, unit_id, ur, *_scene_graph, Matrix4x4(rot, pos));
+	new (u) Unit(*this, unit_id, ur, *_scene_graph, matrix4x4(rot, pos));
 
 	post_unit_spawned_event(unit_id);
 	return unit_id;

+ 2 - 2
src/world/world.h

@@ -40,7 +40,7 @@ public:
 	~World();
 
 	/// Spawns a new instance of the unit @a name at the given @a position and @a rotation.
-	UnitId spawn_unit(const UnitResource* ur, const Vector3& position = vector3::ZERO, const Quaternion& rotation = quaternion::IDENTITY);
+	UnitId spawn_unit(const UnitResource* ur, const Vector3& position = VECTOR3_ZERO, const Quaternion& rotation = QUATERNION_IDENTITY);
 	UnitId spawn_unit(StringId64 name, const Vector3& pos, const Quaternion& rot);
 
 	/// Destroys the unit with the given @a id.
@@ -87,7 +87,7 @@ public:
 
 	/// Plays the sound with the given @a name at the given @a position, with the given
 	/// @a volume and @a range. @a loop controls whether the sound must loop or not.
-	SoundInstanceId play_sound(const SoundResource* sr, bool loop = false, float volume = 1.0f, const Vector3& position = vector3::ZERO, float range = 50.0f);
+	SoundInstanceId play_sound(const SoundResource* sr, bool loop = false, float volume = 1.0f, const Vector3& position = VECTOR3_ZERO, float range = 50.0f);
 	SoundInstanceId play_sound(StringId64 name, const bool loop, const float volume, const Vector3& pos, const float range);
 
 	/// Stops the sound with the given @a id.