瀏覽代碼

Refactoring Math lib

Panagiotis Christopoulos Charitos 14 年之前
父節點
當前提交
c038417df4
共有 65 個文件被更改,包括 1128 次插入1084 次删除
  1. 3 1
      .cproject
  2. 2 2
      docs/doxyfile
  3. 15 15
      src/Main.cpp
  4. 3 3
      src/cln/Plane.cpp
  5. 1 1
      src/cln/Sphere.inl.h
  6. 14 10
      src/m/Axisang.h
  7. 34 19
      src/m/Axisang.inl.h
  8. 0 32
      src/m/Common.h
  9. 13 16
      src/m/Euler.h
  10. 20 15
      src/m/Euler.inl.h
  11. 0 42
      src/m/Funcs.h
  12. 42 44
      src/m/Mat3.h
  13. 120 92
      src/m/Mat3.inl.h
  14. 53 57
      src/m/Mat4.h
  15. 134 169
      src/m/Mat4.inl.h
  16. 9 8
      src/m/Math.cpp
  17. 52 14
      src/m/Math.h
  18. 17 22
      src/m/Math.inl.h
  19. 3 0
      src/m/MathCommonIncludes.h
  20. 1 5
      src/m/MathCommonSrc.h
  21. 18 0
      src/m/MathForward.h
  22. 9 0
      src/m/MathSimd.h
  23. 17 19
      src/m/Quat.h
  24. 62 26
      src/m/Quat.inl.h
  25. 9 10
      src/m/Transform.h
  26. 19 14
      src/m/Transform.inl.h
  27. 27 32
      src/m/Vec2.h
  28. 71 36
      src/m/Vec2.inl.h
  29. 30 34
      src/m/Vec3.h
  30. 75 39
      src/m/Vec3.inl.h
  31. 30 34
      src/m/Vec4.h
  32. 92 47
      src/m/Vec4.inl.h
  33. 1 1
      src/misc/TestHeader.cpp
  34. 3 9
      src/phys/Character.cpp
  35. 6 14
      src/phys/Character.h
  36. 2 2
      src/phys/Convertors.h
  37. 2 8
      src/phys/MotionState.h
  38. 5 11
      src/phys/PhysWorld.cpp
  39. 5 12
      src/phys/PhysWorld.h
  40. 2 8
      src/phys/RigidBody.cpp
  41. 5 13
      src/phys/RigidBody.h
  42. 1 1
      src/r/CollisionDbgDrawer.cpp
  43. 5 5
      src/r/Dbg.cpp
  44. 1 1
      src/r/SceneDbgDrawer.cpp
  45. 1 1
      src/rsrc/LightRsrc.cpp
  46. 1 1
      src/rsrc/MeshData.cpp
  47. 1 0
      src/rsrc/MeshData.h
  48. 3 3
      src/rsrc/ParticleEmitterRsrc.cpp
  49. 2 2
      src/rsrc/ShaderProgramPrePreprocessor.h
  50. 1 1
      src/scene/Particle.cpp
  51. 4 6
      src/scene/Particle.h
  52. 7 7
      src/scene/ParticleEmitterNode.cpp
  53. 3 3
      src/scene/PerspectiveCamera.cpp
  54. 1 1
      src/scene/Scene.cpp
  55. 8 8
      src/scene/Scene.h
  56. 5 3
      src/scene/SkinNode.cpp
  57. 13 19
      src/ui/UiFont.cpp
  58. 12 17
      src/ui/UiFont.h
  59. 6 12
      src/ui/UiFtFontLoader.cpp
  60. 4 10
      src/ui/UiFtFontLoader.h
  61. 9 15
      src/ui/UiPainter.cpp
  62. 5 11
      src/ui/UiPainter.h
  63. 4 10
      src/ui/UiPainterDevice.cpp
  64. 4 10
      src/ui/UiPainterDevice.h
  65. 1 1
      src/util/Accessors.h

+ 3 - 1
.cproject

@@ -291,6 +291,8 @@
 			</profile>
 		</scannerConfigBuildInfo>
 	</storageModule>
-	<storageModule moduleId="refreshScope"/>
+	<storageModule moduleId="refreshScope" versionNumber="1">
+		<resource resourceType="PROJECT" workspacePath="/anki"/>
+	</storageModule>
 	<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
 </cproject>

+ 2 - 2
docs/doxyfile

@@ -271,7 +271,7 @@ DISTRIBUTE_GROUP_DOC   = NO
 # NO to prevent subgrouping. Alternatively, this can be done per class using 
 # the \nosubgrouping command.
 
-SUBGROUPING            = YES
+SUBGROUPING            = NO
 
 # When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum 
 # is documented as struct, union, or enum with the name of the typedef. So 
@@ -313,7 +313,7 @@ EXTRACT_ALL            = NO
 # If the EXTRACT_PRIVATE tag is set to YES all private members of a class 
 # will be included in the documentation.
 
-EXTRACT_PRIVATE        = YES
+EXTRACT_PRIVATE        = NO
 
 # If the EXTRACT_STATIC tag is set to YES all static members of a file 
 # will be included in the documentation.

+ 15 - 15
src/Main.cpp

@@ -7,7 +7,7 @@
 #include "scene/OrthographicCamera.h"
 #include "m/Math.h"
 #include "r/Renderer.h"
-#include "ui/Painter.h"
+#include "ui/UiPainter.h"
 #include "core/App.h"
 #include "rsrc/Mesh.h"
 #include "scene/Light.h"
@@ -37,8 +37,8 @@
 #include "rsrc/Skin.h"
 #include "scene/MaterialRuntime.h"
 #include "core/Globals.h"
-#include "ui/FtFontLoader.h"
-#include "ui/Font.h"
+#include "ui/UiFtFontLoader.h"
+#include "ui/UiFont.h"
 #include "event/EventManager.h"
 #include "event/SceneColorEvent.h"
 #include "event/MainRendererPpsHdrEvent.h"
@@ -56,9 +56,9 @@ SkinNode* imp;
 PointLight* point_lights[10];
 SpotLight* spot_lights[2];
 ParticleEmitterNode* partEmitter;
-phys::Character* character;
+Character* character;
 
-ui::Painter* painter;
+UiPainter* painter;
 
 
 // Physics
@@ -84,12 +84,12 @@ void initPhysics()
 	groundTransform.setIdentity();
 	groundTransform.setOrigin(Vec3(0,-50, 0));
 
-	phys::RigidBody::Initializer init;
+	RigidBody::Initializer init;
 	init.mass = 0.0;
 	init.shape = groundShape;
 	init.startTrf = groundTransform;
 
-	new phys::RigidBody(SceneSingleton::get().getPhysMasterContainer(), init);
+	new RigidBody(SceneSingleton::get().getPhysPhysWorld(), init);
 
 
 	/*{
@@ -132,14 +132,14 @@ void init()
 
 	srand(unsigned(time(NULL)));
 
-	painter = new ui::Painter(Vec2(AppSingleton::get().getWindowWidth(),
-	                               AppSingleton::get().getWindowHeight()));
+	painter = new UiPainter(Vec2(AppSingleton::get().getWindowWidth(),
+		AppSingleton::get().getWindowHeight()));
 	painter->setFont("engine-rsrc/ModernAntiqua.ttf", 25, 25);
 
 	// camera
 	PerspectiveCamera* cam = new PerspectiveCamera(false, NULL);
 	//cam->setAll(toRad(100.0), toRad(100.0) / r::MainRendererSingleton::get().getAspectRatio(), 0.5, 200.0);
-	cam->setAll(MainRendererSingleton::get().getAspectRatio()*toRad(60.0), toRad(60.0), 0.5, 200.0);
+	cam->setAll(MainRendererSingleton::get().getAspectRatio()*Math::toRad(60.0), Math::toRad(60.0), 0.5, 200.0);
 	cam->moveLocalY(3.0);
 	cam->moveLocalZ(5.7);
 	cam->moveLocalX(-0.3);
@@ -159,10 +159,10 @@ void init()
 
 	spot_lights[0] = new SpotLight(false, NULL);
 	spot_lights[0]->init("maps/temple/light2.light");
-	spot_lights[0]->setLocalTransform(Transform(Vec3(1.3, 4.3, 3.0), Mat3(Euler(toRad(-20), toRad(20), 0.0)), 1.0));
+	spot_lights[0]->setLocalTransform(Transform(Vec3(1.3, 4.3, 3.0), Mat3(Euler(Math::toRad(-20), Math::toRad(20), 0.0)), 1.0));
 	spot_lights[1] = new SpotLight(false, NULL);
 	spot_lights[1]->init("maps/temple/light3.light");
-	spot_lights[1]->setLocalTransform(Transform(Vec3(-2.3, 6.3, 2.9), Mat3(Euler(toRad(-70), toRad(-20), 0.0)), 1.0));
+	spot_lights[1]->setLocalTransform(Transform(Vec3(-2.3, 6.3, 2.9), Mat3(Euler(Math::toRad(-70), Math::toRad(-20), 0.0)), 1.0));
 
 
 	// horse
@@ -271,7 +271,7 @@ void mainLoopExtra()
 	InputSingleton::get().handleEvents();
 
 	float dist = 0.2;
-	float ang = toRad(3.0);
+	float ang = Math::toRad(3.0);
 	float scale = 0.01;
 
 	// move the camera
@@ -380,7 +380,7 @@ void mainLoop()
 		mainLoopExtra();
 		void execStdinScpripts();
 		execStdinScpripts();
-		SceneSingleton::get().getPhysMasterContainer().update(prevUpdateTime, crntTime);
+		SceneSingleton::get().getPhysPhysWorld().update(prevUpdateTime, crntTime);
 		SceneSingleton::get().updateAllWorldStuff(prevUpdateTime, crntTime);
 		SceneSingleton::get().doVisibilityTests(*AppSingleton::get().getActiveCam());
 		SceneSingleton::get().updateAllControllers();
@@ -523,7 +523,7 @@ void initSubsystems(int argc, char* argv[])
 	parallel::ManagerSingleton::get().init(4);
 
 	// Add drawer to physics
-	SceneSingleton::get().getPhysMasterContainer().setDebugDrawer(
+	SceneSingleton::get().getPhysPhysWorld().setDebugDrawer(
 		new PhysDbgDrawer(MainRendererSingleton::get().getDbg()));
 }
 

+ 3 - 3
src/cln/Plane.cpp

@@ -14,7 +14,7 @@ void Plane::setFrom3Points(const Vec3& p0, const Vec3& p1, const Vec3& p2)
 	normal = u.cross(v);
 
 	// length of normal had better not be zero
-	ASSERT(!isZero(normal.getLengthSquared()));
+	ASSERT(!Math::isZero(normal.getLengthSquared()));
 
 	normal.normalize();
 	offset = normal.dot(p0); // ToDo: correct??
@@ -29,10 +29,10 @@ void Plane::setFromPlaneEquation(float a, float b, float c, float d)
 	// normalize for cheap distance checks
 	float lensq = a * a + b * b + c * c;
 	// length of normal had better not be zero
-	ASSERT(!isZero(lensq));
+	ASSERT(!Math::isZero(lensq));
 
 	// recover gracefully
-	if(isZero(lensq))
+	if(Math::isZero(lensq))
 	{
 		normal = Vec3(1.0, 0.0, 0.0);
 		offset = 0.0;

+ 1 - 1
src/cln/Sphere.inl.h

@@ -46,5 +46,5 @@ void Sphere::set(const Container& container)
 		}
 	}
 
-	radius = m::sqrt(maxDist);
+	radius = Math::sqrt(maxDist);
 }

+ 14 - 10
src/m/Axisang.h

@@ -1,11 +1,12 @@
-#ifndef M_AXISANG_H
-#define M_AXISANG_H
+#ifndef AXISANG_H
+#define AXISANG_H
 
-#include "Common.h"
+#include "Vec3.h"
+#include "MathCommonIncludes.h"
 
 
-namespace m {
-
+/// @addtogroup Math
+/// @{
 
 /// Used for rotations
 class Axisang
@@ -15,7 +16,7 @@ class Axisang
 		/// @{
 		explicit Axisang();
 		         Axisang(const Axisang& b);
-		explicit Axisang(float rad, const Vec3& axis_);
+		explicit Axisang(const float rad, const Vec3& axis_);
 		explicit Axisang(const Quat& q);
 		explicit Axisang(const Mat3& m3);
 		/// @}
@@ -24,7 +25,7 @@ class Axisang
 		/// @{
 		float getAngle() const;
 		float& getAngle();
-		void setAngle(float a);
+		void setAngle(const float a);
 		
 		const Vec3& getAxis() const;
 		Vec3& getAxis();
@@ -36,6 +37,11 @@ class Axisang
 		Axisang& operator=(const Axisang& b);
 		/// @}
 
+		/// @name Friends
+		/// @{
+		friend std::ostream& operator<<(std::ostream& s, const Axisang& a);
+		/// @}
+
 	private:
 		/// @name Data
 		/// @{
@@ -43,9 +49,7 @@ class Axisang
 		Vec3 axis;
 		/// @}
 };
-
-
-} // end namespace
+/// @}
 
 
 #include "Axisang.inl.h"

+ 34 - 19
src/m/Axisang.inl.h

@@ -1,7 +1,4 @@
-#include "Common.inl.h"
-
-
-namespace m {
+#include "MathCommonSrc.h"
 
 
 //==============================================================================
@@ -14,24 +11,27 @@ inline Axisang::Axisang()
 	axis(0.0)
 {}
 
+
 // Copy
 inline Axisang::Axisang(const Axisang& b)
 :	ang(b.ang),
 	axis(b.axis)
 {}
 
+
 // float, axis
-inline Axisang::Axisang(float rad, const Vec3& axis_)
+inline Axisang::Axisang(const float rad, const Vec3& axis_)
 :	ang(rad),
 	axis(axis_)
 {}
 
+
 // Quat
 inline Axisang::Axisang(const Quat& q)
 {
 	ang = 2.0 * acos(q.w());
-	float length = m::sqrt(1.0 - q.w() * q.w());
-	if(isZero(length))
+	float length = Math::sqrt(1.0 - q.w() * q.w());
+	if(Math::isZero(length))
 	{
 		axis = Vec3(0.0);
 	}
@@ -42,12 +42,13 @@ inline Axisang::Axisang(const Quat& q)
 	}
 }
 
+
 // constructor [mat3]
 inline Axisang::Axisang(const Mat3& m3)
 {
-	if((fabs(m3(0, 1) - m3(1, 0)) < EPSILON) &&
-		(fabs(m3(0, 2) - m3(2, 0)) < EPSILON) &&
-		(fabs(m3(1, 2) - m3(2, 1)) < EPSILON))
+	if((fabs(m3(0, 1) - m3(1, 0)) < Math::EPSILON) &&
+		(fabs(m3(0, 2) - m3(2, 0)) < Math::EPSILON) &&
+		(fabs(m3(1, 2) - m3(2, 1)) < Math::EPSILON))
 	{
 
 		if((fabs(m3(0, 1) + m3(1, 0)) < 0.1) &&
@@ -60,11 +61,11 @@ inline Axisang::Axisang(const Mat3& m3)
 			return;
 		}
 
-		ang = PI;
+		ang = Math::PI;
 		axis.x() = (m3(0, 0)+1) / 2.0;
 		if(axis.x() > 0.0)
 		{
-			axis.x() = m::sqrt(axis.x());
+			axis.x() = Math::sqrt(axis.x());
 		}
 		else
 		{
@@ -73,7 +74,7 @@ inline Axisang::Axisang(const Mat3& m3)
 		axis.y() = (m3(1, 1)+1)/2;
 		if(axis.y() > 0)
 		{
-			axis.y() = m::sqrt(axis.y());
+			axis.y() = Math::sqrt(axis.y());
 		}
 		else
 		{
@@ -83,16 +84,16 @@ inline Axisang::Axisang(const Mat3& m3)
 		axis.z() = (m3(2, 2)+1)/2;
 		if(axis.z() > 0)
 		{
-			axis.z() = m::sqrt(axis.z());
+			axis.z() = Math::sqrt(axis.z());
 		}
 		else
 		{
 			axis.z() = 0.0;
 		}
 
-		bool xZero = (fabs(axis.x()) < EPSILON);
-		bool yZero = (fabs(axis.y()) < EPSILON);
-		bool zZero = (fabs(axis.z()) < EPSILON);
+		bool xZero = (fabs(axis.x()) < Math::EPSILON);
+		bool yZero = (fabs(axis.y()) < Math::EPSILON);
+		bool zZero = (fabs(axis.z()) < Math::EPSILON);
 		bool xyPositive = (m3(0, 1) > 0);
 		bool xzPositive = (m3(0, 2) > 0);
 		bool yzPositive = (m3(1, 2) > 0);
@@ -121,7 +122,7 @@ inline Axisang::Axisang(const Mat3& m3)
 		return;
 	}
 
-	float s = m::sqrt((m3(2, 1) - m3(1, 2)) * (m3(2, 1) - m3(1, 2)) +
+	float s = Math::sqrt((m3(2, 1) - m3(1, 2)) * (m3(2, 1) - m3(1, 2)) +
 		(m3(0, 2) - m3(2, 0)) * (m3(0, 2) - m3(2, 0)) +
 		(m3(1, 0) - m3(0, 1)) * (m3(1, 0) - m3(0, 1)));
 
@@ -146,26 +147,31 @@ inline float Axisang::getAngle() const
 	return ang;
 }
 
+
 inline float& Axisang::getAngle()
 {
 	return ang;
 }
 
+
 inline void Axisang::setAngle(float a)
 {
 	ang = a;
 }
 
+
 inline const Vec3& Axisang::getAxis() const
 {
 	return axis;
 }
 
+
 inline Vec3& Axisang::getAxis()
 {
 	return axis;
 }
 
+
 inline void Axisang::setAxis(const Vec3& a)
 {
 	axis = a;
@@ -185,4 +191,13 @@ inline Axisang& Axisang::operator=(const Axisang& b)
 }
 
 
-} // end namaspace
+//==============================================================================
+// Friends                                                                     =
+//==============================================================================
+
+// Print
+inline std::ostream& operator<<(std::ostream& s, const Axisang& a)
+{
+	s << "axis: " << a.getAxis() << ", angle: " << a.getAngle();
+	return s;
+}

+ 0 - 32
src/m/Common.h

@@ -1,32 +0,0 @@
-/// @file
-/// For Internal use in math lib
-
-#ifndef M_COMMON_H
-#define M_COMMON_H
-
-#include "util/StdTypes.h"
-#include "util/Accessors.h"
-#if defined(MATH_INTEL_SIMD)
-#	include <smmintrin.h>
-#endif
-#include <iostream>
-#include <boost/array.hpp>
-
-
-// Forward delcs
-namespace m {
-
-class Vec2;
-class Vec3;
-class Vec4;
-class Quat;
-class Euler;
-class Axisang;
-class Mat3;
-class Mat4;
-class Transform;
-
-}
-
-
-#endif

+ 13 - 16
src/m/Euler.h

@@ -1,11 +1,11 @@
-#ifndef M_EULER_H
-#define M_EULER_H
+#ifndef EULER_H
+#define EULER_H
 
-#include "Common.h"
+#include "MathCommonIncludes.h"
 
 
-namespace m {
-
+/// @addtogroup Math
+///
 
 /// Used for rotations. It cannot describe a rotation accurately though
 class Euler
@@ -14,7 +14,7 @@ class Euler
 		/// @name Constructors
 		/// @{
 		explicit Euler();
-		explicit Euler(float x, float y, float z);
+		explicit Euler(const float x, const float y, const float z);
 		         Euler(const Euler& b);
 		explicit Euler(const Quat& q);
 		explicit Euler(const Mat3& m3);
@@ -22,8 +22,8 @@ class Euler
 
 		/// @name Accessors
 		/// @{
-		float& operator [](uint i);
-		float operator [](uint i) const;
+		float& operator [](const size_t i);
+		float operator [](const size_t i) const;
 		float& x();
 		float x() const;
 		float& y();
@@ -37,6 +37,11 @@ class Euler
 		Euler& operator=(const Euler& b);
 		/// @}
 
+		/// @name Friends
+		/// @{
+		friend std::ostream& operator<<(std::ostream& s, const Euler& e);
+		/// @}
+
 	private:
 		/// @name Data
 		/// @{
@@ -51,17 +56,9 @@ class Euler
 		};
 		/// @}
 };
-
-
-/// @name Other operators
-/// @{
-extern std::ostream& operator<<(std::ostream& s, const Euler& e);
 /// @}
 
 
-} // end namespace
-
-
 #include "Euler.inl.h"
 
 

+ 20 - 15
src/m/Euler.inl.h

@@ -1,7 +1,4 @@
-#include "Common.inl.h"
-
-
-namespace m {
+#include "MathCommonSrc.h"
 
 
 //==============================================================================
@@ -14,14 +11,16 @@ inline Euler::Euler()
 	x() = y() = z() = 0.0;
 }
 
+
 // float, float, float
-inline Euler::Euler(float x_, float y_, float z_)
+inline Euler::Euler(const float x_, const float y_, const float z_)
 {
 	x() = x_;
 	y() = y_;
 	z() = z_;
 }
 
+
 // Copy
 inline Euler::Euler(const Euler& b)
 {
@@ -30,6 +29,7 @@ inline Euler::Euler(const Euler& b)
 	z() = b.z();
 }
 
+
 // Quat
 inline Euler::Euler(const Quat& q)
 {
@@ -37,14 +37,14 @@ inline Euler::Euler(const Quat& q)
 	if(test > 0.499)
 	{
 		y() = 2.0 * atan2(q.x(), q.w());
-		z() = PI / 2.0;
+		z() = Math::PI / 2.0;
 		x() = 0.0;
 		return;
 	}
 	if(test < -0.499)
 	{
 		y() = -2.0 * atan2(q.x(), q.w());
-		z() = -PI / 2.0;
+		z() = -Math::PI / 2.0;
 		x() = 0.0;
 		return;
 	}
@@ -59,6 +59,7 @@ inline Euler::Euler(const Quat& q)
 	    1.0 - 2.0 * sqx - 2.0 * sqz);
 }
 
+
 // mat3
 inline Euler::Euler(const Mat3& m3)
 {
@@ -67,9 +68,9 @@ inline Euler::Euler(const Mat3& m3)
 	float cz, sz;
 
 	sy = m3(0, 2);
-	cy = m::sqrt(1.0 - sy*sy);
+	cy = Math::sqrt(1.0 - sy * sy);
 	// normal case
-	if (!isZero(cy))
+	if (!Math::isZero(cy))
 	{
 		float factor = 1.0/cy;
 		sx = -m3(1, 2) * factor;
@@ -96,41 +97,48 @@ inline Euler::Euler(const Mat3& m3)
 // Accessors                                                                   =
 //==============================================================================
 
-inline float& Euler::operator [](uint i)
+inline float& Euler::operator [](const size_t i)
 {
 	return arr[i];
 }
 
-inline float Euler::operator [](uint i) const
+
+inline float Euler::operator [](const size_t i) const
 {
 	return arr[i];
 }
 
+
 inline float& Euler::x()
 {
 	return vec.x;
 }
 
+
 inline float Euler::x() const
 {
 	return vec.x;
 }
 
+
 inline float& Euler::y()
 {
 	return vec.y;
 }
 
+
 inline float Euler::y() const
 {
 	return vec.y;
 }
 
+
 inline float& Euler::z()
 {
 	return vec.z;
 }
 
+
 inline float Euler::z() const
 {
 	return vec.z;
@@ -152,7 +160,7 @@ inline Euler& Euler::operator=(const Euler& b)
 
 
 //==============================================================================
-// Print                                                                       =
+// Friends                                                                     =
 //==============================================================================
 
 inline std::ostream& operator<<(std::ostream& s, const Euler& e)
@@ -160,6 +168,3 @@ inline std::ostream& operator<<(std::ostream& s, const Euler& e)
 	s << e.x() << ' ' << e.y() << ' ' << e.z();
 	return s;
 }
-
-
-} // end namespace

+ 0 - 42
src/m/Funcs.h

@@ -1,42 +0,0 @@
-#ifndef M_FUNCS_H
-#define M_FUNCS_H
-
-#include "Common.h"
-
-
-/// Math library namespace
-namespace m {
-
-
-const float PI = 3.14159265358979323846;
-const float EPSILON = 1.0e-6;
-
-/// A fast func that given the angle in rads it returns the sin and cos
-void  sinCos(float rad, float& sin_, float& cos_);
-float sqrt(float f); ///< Square root
-float toRad(float degrees);
-float toDegrees(float rad);
-float sin(float rad);
-float cos(float rad);
-bool  isZero(float f); ///< The proper way to test if a float is zero
-
-/// mat4(t0,r0,s0)*mat4(t1,r1,s1) == mat4(tf,rf,sf)
-void combineTransformations(
-	const Vec3& t0, const Mat3& r0, float s0, // in 0
-	const Vec3& t1, const Mat3& r1, float s1, // in 1
-	Vec3& tf, Mat3& rf, float& sf); // out
-
-/// mat4(t0,r0, 1.0)*mat4(t1,r1, 1.0) == mat4(tf,rf,sf)
-void combineTransformations(
-	const Vec3& t0, const Mat3& r0, // in 0
-	const Vec3& t1, const Mat3& r1, // in 1
-	Vec3& tf, Mat3& rf); // out
-
-
-} // end namespace
-
-
-#include "Funcs.inl.h"
-
-
-#endif

+ 42 - 44
src/m/Mat3.h

@@ -1,24 +1,25 @@
-#ifndef M_MAT3_H
-#define M_MAT3_H
+#ifndef MAT3_H
+#define MAT3_H
 
-#include "Common.h"
+#include "MathCommonIncludes.h"
 
 
-namespace m {
-
+/// @addtogroup Math
+/// @{
 
 /// Mainly used for rotations. It includes many helpful member functions.
 /// Its row major
 class Mat3
 {
 	public:
-		/// @name Constructors & distructors
+		/// @name Constructors
 		/// @{
 		explicit Mat3() {};
-		explicit Mat3(float f);
-		explicit Mat3(float m00, float m01, float m02, float m10, float m11,
-			float m12, float m20, float m21, float m22);
-		explicit Mat3(float arr[]);
+		explicit Mat3(const float f);
+		explicit Mat3(const float m00, const float m01, const float m02,
+			const float m10, const float m11, const float m12,
+			const float m20, const float m21, const float m22);
+		explicit Mat3(const float arr[]);
 		         Mat3(const Mat3& b);
 		explicit Mat3(const Quat& q); ///< Quat to Mat3. 12 muls, 12 adds
 		explicit Mat3(const Euler& eu);
@@ -27,10 +28,10 @@ class Mat3
 
 		/// @name Accessors
 		/// @{
-		float& operator()(const uint i, const uint j);
-		const float& operator()(const uint i, const uint j) const;
-		float& operator[](const uint i);
-		const float& operator[](const uint i) const;
+		float& operator()(const size_t i, const size_t j);
+		const float& operator()(const size_t i, const size_t j) const;
+		float& operator[](const size_t i);
+		const float& operator[](const size_t i) const;
 		/// @}
 
 		/// @name Operators with same
@@ -50,14 +51,14 @@ class Mat3
 
 		/// @name Operators with float
 		/// @{
-		Mat3 operator+(float f) const;
-		Mat3& operator+=(float f);
-		Mat3 operator-(float f) const;
-		Mat3& operator-=(float f);
-		Mat3 operator*(float f) const;
-		Mat3& operator*=(float f);
-		Mat3 operator/(float f) const;
-		Mat3& operator/=(float f);
+		Mat3 operator+(const float f) const;
+		Mat3& operator+=(const float f);
+		Mat3 operator-(const float f) const;
+		Mat3& operator-=(const float f);
+		Mat3 operator*(const float f) const;
+		Mat3& operator*=(const float f);
+		Mat3 operator/(const float f) const;
+		Mat3& operator/=(const float f);
 		/// @}
 
 		/// @name Operators with others
@@ -68,27 +69,27 @@ class Mat3
 		/// @name Other
 		/// @{
 		void setRows(const Vec3& a, const Vec3& b, const Vec3& c);
-		void setRow(const uint i, const Vec3& v);
+		void setRow(const size_t i, const Vec3& v);
 		void getRows(Vec3& a, Vec3& b, Vec3& c) const;
-		Vec3 getRow(const uint i) const;
+		Vec3 getRow(const size_t i) const;
 		void setColumns(const Vec3& a, const Vec3& b, const Vec3& c);
-		void setColumn(const uint i, const Vec3& v);
+		void setColumn(const size_t i, const Vec3& v);
 		void getColumns(Vec3& a, Vec3& b, Vec3& c) const;
-		Vec3 getColumn(const uint i) const;
+		Vec3 getColumn(const size_t i) const;
 		Vec3 getXAxis() const;
 		Vec3 getYAxis() const;
 		Vec3 getZAxis() const;
 		void setXAxis(const Vec3& v3);
 		void setYAxis(const Vec3& v3);
 		void setZAxis(const Vec3& v3);
-		void setRotationX(float rad);
-		void setRotationY(float rad);
-		void setRotationZ(float rad);
+		void setRotationX(const float rad);
+		void setRotationY(const float rad);
+		void setRotationZ(const float rad);
 		/// It rotates "this" in the axis defined by the rotation AND not the
 		/// world axis
-		void rotateXAxis(float rad);
-		void rotateYAxis(float rad);
-		void rotateZAxis(float rad);
+		void rotateXAxis(const float rad);
+		void rotateYAxis(const float rad);
+		void rotateZAxis(const float rad);
 		void transpose();
 		Mat3 getTransposed() const;
 		void reorthogonalize();
@@ -101,6 +102,15 @@ class Mat3
 		static const Mat3& getIdentity();
 		/// @}
 
+		/// @name Friends
+		/// @{
+		friend Mat3 operator+(float f, const Mat3& m3);
+		friend Mat3 operator-(float f, const Mat3& m3);
+		friend Mat3 operator*(float f, const Mat3& m3);
+		friend Mat3 operator/(float f, const Mat3& m3);
+		friend std::ostream& operator<<(std::ostream& s, const Mat3& m);
+		/// @}
+
 	private:
 		/// @name Data members
 		/// @{
@@ -111,21 +121,9 @@ class Mat3
 		};
 		/// @}
 };
-
-
-/// @name Other Mat3 operators
-/// @{
-extern Mat3 operator+(float f, const Mat3& m3);
-extern Mat3 operator-(float f, const Mat3& m3);
-extern Mat3 operator*(float f, const Mat3& m3);
-extern Mat3 operator/(float f, const Mat3& m3);
-extern std::ostream& operator<<(std::ostream& s, const Mat3& m);
 /// @}
 
 
-} // end namespace
-
-
 #include "Mat3.inl.h"
 
 

+ 120 - 92
src/m/Mat3.inl.h

@@ -1,7 +1,4 @@
-#include "Common.inl.h"
-
-
-namespace m {
+#include "MathCommonSrc.h"
 
 
 //==============================================================================
@@ -9,7 +6,7 @@ namespace m {
 //==============================================================================
 
 // constructor [float]
-inline Mat3::Mat3(float f)
+inline Mat3::Mat3(const float f)
 {
 	for(int i = 0; i < 9; i++)
 	{
@@ -17,8 +14,9 @@ inline Mat3::Mat3(float f)
 	}
 }
 
+
 // float[]
-inline Mat3::Mat3(float arr [])
+inline Mat3::Mat3(const float arr [])
 {
 	for(int i = 0; i < 9; i++)
 	{
@@ -26,9 +24,11 @@ inline Mat3::Mat3(float arr [])
 	}
 }
 
+
 // many floats
-inline Mat3::Mat3(float m00, float m01, float m02, float m10, float m11,
-	float m12, float m20, float m21, float m22)
+inline Mat3::Mat3(const float m00, const float m01, const float m02,
+	const float m10, const float m11, const float m12,
+	const float m20, const float m21, const float m22)
 {
 	(*this)(0, 0) = m00;
 	(*this)(0, 1) = m01;
@@ -41,6 +41,7 @@ inline Mat3::Mat3(float m00, float m01, float m02, float m10, float m11,
 	(*this)(2, 2) = m22;
 }
 
+
 // Copy
 inline Mat3::Mat3(const Mat3& b)
 {
@@ -50,6 +51,7 @@ inline Mat3::Mat3(const Mat3& b)
 	}
 }
 
+
 // Quat
 inline Mat3::Mat3(const Quat& q)
 {
@@ -84,13 +86,14 @@ inline Mat3::Mat3(const Quat& q)
 	(*this)(2, 2) = 1.0 - (xx + yy);
 }
 
+
 // Euler
 inline Mat3::Mat3(const Euler& e)
 {
 	float ch, sh, ca, sa, cb, sb;
-	sinCos(e.y(), sh, ch);
-	sinCos(e.z(), sa, ca);
-	sinCos(e.x(), sb, cb);
+	Math::sinCos(e.y(), sh, ch);
+	Math::sinCos(e.z(), sa, ca);
+	Math::sinCos(e.x(), sb, cb);
 
 	(*this)(0, 0) = ch * ca;
 	(*this)(0, 1) = sh * sb - ch * sa * cb;
@@ -103,13 +106,15 @@ inline Mat3::Mat3(const Euler& e)
 	(*this)(2, 2) = -sh * sa * sb + ch * cb;
 }
 
+
 // Axisang
 inline Mat3::Mat3(const Axisang& axisang)
 {
-	ASSERT(isZero(1.0 - axisang.getAxis().getLength())); // Not normalized axis
+	// Not normalized axis
+	ASSERT(Math::isZero(1.0 - axisang.getAxis().getLength()));
 
 	float c, s;
-	sinCos(axisang.getAngle(), s, c);
+	Math::sinCos(axisang.getAngle(), s, c);
 	float t = 1.0 - c;
 
 	const Vec3& axis = axisang.getAxis();
@@ -135,22 +140,25 @@ inline Mat3::Mat3(const Axisang& axisang)
 // Accessors                                                                   =
 //==============================================================================
 
-inline float& Mat3::operator()(const uint i, const uint j)
+inline float& Mat3::operator()(const size_t i, const size_t j)
 {
 	return arr2[i][j];
 }
 
-inline const float& Mat3::operator()(const uint i, const uint j) const
+
+inline const float& Mat3::operator()(const size_t i, const size_t j) const
 {
 	return arr2[i][j];
 }
 
-inline float& Mat3::operator[](const uint i)
+
+inline float& Mat3::operator[](const size_t i)
 {
 	return arr1[i];
 }
 
-inline const float& Mat3::operator[](const uint i) const
+
+inline const float& Mat3::operator[](const size_t i) const
 {
 	return arr1[i];
 }
@@ -170,6 +178,7 @@ inline Mat3& Mat3::operator=(const Mat3& b)
 	return (*this);
 }
 
+
 // +
 inline Mat3 Mat3::operator+(const Mat3& b) const
 {
@@ -181,6 +190,7 @@ inline Mat3 Mat3::operator+(const Mat3& b) const
 	return c;
 }
 
+
 // +=
 inline Mat3& Mat3::operator+=(const Mat3& b)
 {
@@ -191,6 +201,7 @@ inline Mat3& Mat3::operator+=(const Mat3& b)
 	return (*this);
 }
 
+
 // -
 inline Mat3 Mat3::operator-(const Mat3& b) const
 {
@@ -202,6 +213,7 @@ inline Mat3 Mat3::operator-(const Mat3& b) const
 	return c;
 }
 
+
 // -=
 inline Mat3& Mat3::operator-=(const Mat3& b)
 {
@@ -212,6 +224,7 @@ inline Mat3& Mat3::operator-=(const Mat3& b)
 	return (*this);
 }
 
+
 // *
 inline Mat3 Mat3::operator*(const Mat3& b) const
 {
@@ -237,6 +250,7 @@ inline Mat3 Mat3::operator*(const Mat3& b) const
 	return c;
 }
 
+
 // *=
 inline Mat3& Mat3::operator*=(const Mat3& b)
 {
@@ -244,12 +258,13 @@ inline Mat3& Mat3::operator*=(const Mat3& b)
 	return (*this);
 }
 
+
 // ==
 inline bool Mat3::operator==(const Mat3& b) const
 {
 	for(int i = 0; i < 9; i++)
 	{
-		if(!isZero((*this)[i]-b[i]))
+		if(!Math::isZero((*this)[i]-b[i]))
 		{
 			return false;
 		}
@@ -257,12 +272,13 @@ inline bool Mat3::operator==(const Mat3& b) const
 	return true;
 }
 
+
 // !=
 inline bool Mat3::operator!=(const Mat3& b) const
 {
 	for(int i = 0; i < 9; i++)
 	{
-		if(!isZero((*this)[i]-b[i]))
+		if(!Math::isZero((*this)[i]-b[i]))
 		{
 			return true;
 		}
@@ -276,122 +292,89 @@ inline bool Mat3::operator!=(const Mat3& b) const
 //==============================================================================
 
 // 3x3 + float
-inline Mat3 Mat3::operator+(float f) const
+inline Mat3 Mat3::operator+(const float f) const
 {
 	Mat3 c;
-	for(uint i = 0; i < 9; i++)
+	for(size_t i = 0; i < 9; i++)
 	{
 		c[i] = (*this)[i] + f;
 	}
 	return c;
 }
 
-// float + 3x3
-inline Mat3 operator+(float f, const Mat3& m3)
-{
-	return m3 + f;
-}
 
 // 3x3 += float
-inline Mat3& Mat3::operator+=(float f)
+inline Mat3& Mat3::operator+=(const float f)
 {
-	for(uint i = 0; i < 9; i++)
+	for(size_t i = 0; i < 9; i++)
 	{
 		(*this)[i] += f;
 	}
 	return (*this);
 }
 
+
 // 3x3 - float
-inline Mat3 Mat3::operator-(float f) const
+inline Mat3 Mat3::operator-(const float f) const
 {
 	Mat3 c;
-	for(uint i = 0; i < 9; i++)
+	for(size_t i = 0; i < 9; i++)
 	{
 		c[i] = (*this)[i] - f;
 	}
 	return c;
 }
 
-// float - 3x3
-inline Mat3 operator-(float f, const Mat3& m3)
-{
-	Mat3 out;
-	for(uint i = 0; i < 9; i++)
-	{
-		out[i] = f - m3[i];
-	}
-	return out;
-}
-
 // 3x3 -= float
-inline Mat3& Mat3::operator-=(float f)
+inline Mat3& Mat3::operator-=(const float f)
 {
-	for(uint i = 0; i < 9; i++)
+	for(size_t i = 0; i < 9; i++)
 	{
 		(*this)[i] -= f;
 	}
 	return (*this);
 }
 
+
 // 3x3 * float
-inline Mat3 Mat3::operator*(float f) const
+inline Mat3 Mat3::operator*(const float f) const
 {
 	Mat3 c;
-	for(uint i = 0; i < 9; i++)
+	for(size_t i = 0; i < 9; i++)
 	{
 		c[i] = (*this)[i] * f;
 	}
 	return c;
 }
 
-// float * 3x3
-inline Mat3 operator*(float f, const Mat3& m3)
-{
-	Mat3 out;
-	for(uint i = 0; i < 9; i++)
-	{
-		out[i] = f * m3[i];
-	}
-	return out;
-}
 
 // 3x3 *= float
-inline Mat3& Mat3::operator*=(float f)
+inline Mat3& Mat3::operator*=(const float f)
 {
-	for(uint i = 0; i < 9; i++)
+	for(size_t i = 0; i < 9; i++)
 	{
 		(*this)[i] *= f;
 	}
 	return (*this);
 }
 
+
 // 3x3 / float
-inline Mat3 Mat3::operator/(float f) const
+inline Mat3 Mat3::operator/(const float f) const
 {
 	Mat3 c;
-	for(uint i = 0; i < 9; i++)
+	for(size_t i = 0; i < 9; i++)
 	{
 		c[i] = (*this)[i] / f;
 	}
 	return c;
 }
 
-// float / 3x3
-inline Mat3 operator/(float f, const Mat3& m3)
-{
-	Mat3 out;
-	for(uint i = 0; i < 9; i++)
-	{
-		out[i] = f / m3[i];
-	}
-	return out;
-}
 
 // 3x3 / float (self)
-inline Mat3& Mat3::operator/=(float f)
+inline Mat3& Mat3::operator/=(const float f)
 {
-	for(uint i = 0; i < 9; i++)
+	for(size_t i = 0; i < 9; i++)
 	{
 		(*this)[i] /= f;
 	}
@@ -475,7 +458,7 @@ inline void Mat3::getColumns(Vec3& a, Vec3& b, Vec3& c) const
 }
 
 // setRow
-inline void Mat3::setRow(const uint i, const Vec3& v)
+inline void Mat3::setRow(const size_t i, const Vec3& v)
 {
 	(*this)(i, 0) = v.x();
 	(*this)(i, 1) = v.y();
@@ -483,13 +466,13 @@ inline void Mat3::setRow(const uint i, const Vec3& v)
 }
 
 // getRow
-inline Vec3 Mat3::getRow(const uint i) const
+inline Vec3 Mat3::getRow(const size_t i) const
 {
 	return Vec3((*this)(i, 0), (*this)(i, 1), (*this)(i, 2));
 }
 
 // setColumn
-inline void Mat3::setColumn(const uint i, const Vec3& v)
+inline void Mat3::setColumn(const size_t i, const Vec3& v)
 {
 	(*this)(0, i) = v.x();
 	(*this)(1, i) = v.y();
@@ -497,7 +480,7 @@ inline void Mat3::setColumn(const uint i, const Vec3& v)
 }
 
 // getColumn
-inline Vec3 Mat3::getColumn(const uint i) const
+inline Vec3 Mat3::getColumn(const size_t i) const
 {
 	return Vec3((*this)(0,i), (*this)(1,i), (*this)(2,i));
 }
@@ -539,10 +522,10 @@ inline void Mat3::setZAxis(const Vec3& v3)
 }
 
 // setRotationX
-inline void Mat3::setRotationX(float rad)
+inline void Mat3::setRotationX(const float rad)
 {
 	float sintheta, costheta;
-	sinCos(rad, sintheta, costheta);
+	Math::sinCos(rad, sintheta, costheta);
 
 	(*this)(0, 0) = 1.0;
 	(*this)(0, 1) = 0.0;
@@ -556,10 +539,10 @@ inline void Mat3::setRotationX(float rad)
 }
 
 // setRotationY
-inline void Mat3::setRotationY(float rad)
+inline void Mat3::setRotationY(const float rad)
 {
 	float sintheta, costheta;
-	sinCos(rad, sintheta, costheta);
+	Math::sinCos(rad, sintheta, costheta);
 
 	(*this)(0, 0) = costheta;
 	(*this)(0, 1) = 0.0;
@@ -573,10 +556,10 @@ inline void Mat3::setRotationY(float rad)
 }
 
 // loadRotationZ
-inline void Mat3::setRotationZ(float rad)
+inline void Mat3::setRotationZ(const float rad)
 {
 	float sintheta, costheta;
-	sinCos(rad, sintheta, costheta);
+	Math::sinCos(rad, sintheta, costheta);
 
 	(*this)(0, 0) = costheta;
 	(*this)(0, 1) = -sintheta;
@@ -597,10 +580,10 @@ inline void Mat3::setRotationZ(float rad)
  * mat3.colomn[0] == i*mat3. rotateXAxis() rotates rad angle not from i vector
  * (aka x axis) but from the vector from colomn 0
  */
-inline void Mat3::rotateXAxis(float rad)
+inline void Mat3::rotateXAxis(const float rad)
 {
 	float sina, cosa;
-	sinCos(rad, sina, cosa);
+	Math::sinCos(rad, sina, cosa);
 
 	/*Vec3 xAxis, yAxis, zAxis;
 	getColumns(xAxis, yAxis, zAxis);*/
@@ -638,10 +621,10 @@ inline void Mat3::rotateXAxis(float rad)
 }
 
 // rotateYAxis
-inline void Mat3::rotateYAxis(float rad)
+inline void Mat3::rotateYAxis(const float rad)
 {
 	float sina, cosa;
-	sinCos(rad, sina, cosa);
+	Math::sinCos(rad, sina, cosa);
 
 	/*Vec3 xAxis, yAxis, zAxis;
 	getColumns(xAxis, yAxis, zAxis);*/
@@ -678,10 +661,10 @@ inline void Mat3::rotateYAxis(float rad)
 
 
 // rotateZAxis
-inline void Mat3::rotateZAxis(float rad)
+inline void Mat3::rotateZAxis(const float rad)
 {
 	float sina, cosa;
-	sinCos(rad, sina, cosa);
+	Math::sinCos(rad, sina, cosa);
 
 	/*Vec3 xAxis, yAxis, zAxis;
 	getColumns(xAxis, yAxis, zAxis);*/
@@ -804,7 +787,7 @@ inline Mat3 Mat3::getInverse() const
 		(*this)(2, 0) *
 		cofactor6;
 
-	ASSERT(!isZero(det)); // Cannot invert det == 0
+	ASSERT(!Math::isZero(det)); // Cannot invert det == 0
 
 	// create adjoint matrix and multiply by 1/det to get inverse
 	float invDet = 1.0 / det;
@@ -856,7 +839,55 @@ inline const Mat3& Mat3::getIdentity()
 	return ident;
 }
 
-// print
+
+//==============================================================================
+// Friends                                                                     =
+//==============================================================================
+
+// float + 3x3
+inline Mat3 operator+(const float f, const Mat3& m3)
+{
+	return m3 + f;
+}
+
+
+// float - 3x3
+inline Mat3 operator-(const float f, const Mat3& m3)
+{
+	Mat3 out;
+	for(size_t i = 0; i < 9; i++)
+	{
+		out[i] = f - m3[i];
+	}
+	return out;
+}
+
+
+// float * 3x3
+inline Mat3 operator*(const float f, const Mat3& m3)
+{
+	Mat3 out;
+	for(size_t i = 0; i < 9; i++)
+	{
+		out[i] = f * m3[i];
+	}
+	return out;
+}
+
+
+// float / 3x3
+inline Mat3 operator/(const float f, const Mat3& m3)
+{
+	Mat3 out;
+	for(size_t i = 0; i < 9; i++)
+	{
+		out[i] = f / m3[i];
+	}
+	return out;
+}
+
+
+// Print
 inline std::ostream& operator<<(std::ostream& s, const Mat3& m)
 {
 	for(int i=0; i<3; i++)
@@ -873,6 +904,3 @@ inline std::ostream& operator<<(std::ostream& s, const Mat3& m)
 	}
 	return s;
 }
-
-
-} // end namespace

+ 53 - 57
src/m/Mat4.h

@@ -1,47 +1,45 @@
-#ifndef M_MAT4_H
-#define M_MAT4_H
+#ifndef MAT4_H
+#define MAT4_H
 
-#include "Common.h"
+#include "MathCommonIncludes.h"
 
 
-namespace m {
-
+/// @addtogroup Math
+/// @{
 
 /// Used mainly for transformations but not necessarily. Its row major
 class Mat4
 {
-	friend Mat4 operator+(float f, const Mat4& m4);
-	friend Mat4 operator-(float f, const Mat4& m4);
-	friend Mat4 operator*(float f, const Mat4& m4);
-	friend Mat4 operator/(float f, const Mat4& m4);
-
 	public:
-		/// @name Constructors & distructors
+		/// @name Constructors
 		/// @{
 		explicit Mat4() {}
-		explicit Mat4(float f);
-		explicit Mat4(float m00, float m01, float m02, float m03, float m10,
-			float m11, float m12, float m13, float m20, float m21, float m22,
-			float m23, float m30, float m31, float m32, float m33);
+		explicit Mat4(const float f);
+		explicit Mat4(const float m00, const float m01, const float m02,
+			const float m03, const float m10, const float m11,
+			const float m12, const float m13, const float m20,
+			const float m21, const float m22, const float m23,
+			const float m30, const float m31, const float m32,
+			const float m33);
 		explicit Mat4(const float arr[]);
 		         Mat4(const Mat4& b);
 		explicit Mat4(const Mat3& m3);
 		explicit Mat4(const Vec3& v);
 		explicit Mat4(const Vec4& v);
 		explicit Mat4(const Vec3& transl, const Mat3& rot);
-		explicit Mat4(const Vec3& transl, const Mat3& rot, float scale);
+		explicit Mat4(const Vec3& transl, const Mat3& rot, const float scale);
 		explicit Mat4(const Transform& t);
 		/// @}
 
 		/// @name Accessors
 		/// @{
-		float& operator()(const uint i, const uint j);
-		const float& operator()(const uint i, const uint j) const;
-		float& operator[](const uint i);
-		const float& operator[](const uint i) const;
+		float& operator()(const size_t i, const size_t j);
+		const float& operator()(const size_t i, const size_t j) const;
+		float& operator[](const size_t i);
+		const float& operator[](const size_t i) const;
 #if defined(MATH_INTEL_SIMD)
-		__m128& getMm(uint i);
-		const __m128& getMm(uint i) const;
+		__m128& getMm(const size_t i);
+		const __m128& getMm(const size_t i) const;
 #endif
 		/// @}
 
@@ -62,14 +60,14 @@ class Mat4
 
 		/// @name Operators with float
 		/// @{
-		Mat4  operator+(float f) const;
-		Mat4& operator+=(float f);
-		Mat4  operator-(float f) const;
-		Mat4& operator-=(float f);
-		Mat4  operator*(float f) const;
-		Mat4& operator*=(float f);
-		Mat4  operator/(float f) const;
-		Mat4& operator/=(float f);
+		Mat4  operator+(const float f) const;
+		Mat4& operator+=(const float f);
+		Mat4  operator-(const float f) const;
+		Mat4& operator-=(const float f);
+		Mat4  operator*(const float f) const;
+		Mat4& operator*=(const float f);
+		Mat4  operator/(const float f) const;
+		Mat4& operator/=(const float f);
 		/// @}
 
 		/// @name Operators with other types
@@ -79,25 +77,25 @@ class Mat4
 
 		/// @name Other
 		/// @{
-		void  setRows(const Vec4& a, const Vec4& b, const Vec4& c,
+		void setRows(const Vec4& a, const Vec4& b, const Vec4& c,
 			const Vec4& d);
-		void  setRow(uint i, const Vec4& v);
-		void  setColumns(const Vec4& a, const Vec4& b, const Vec4& c,
+		void setRow(const size_t i, const Vec4& v);
+		void setColumns(const Vec4& a, const Vec4& b, const Vec4& c,
 			const Vec4& d);
-		void  setColumn(uint i, const Vec4& v);
-		void  setRotationPart(const Mat3& m3);
-		void  setTranslationPart(const Vec4& v4);
-		Mat3  getRotationPart() const;
-		void  setTranslationPart(const Vec3& v3);
-		Vec3  getTranslationPart() const;
-		void  transpose();
-		Mat4  getTransposed() const;
+		void setColumn(const size_t i, const Vec4& v);
+		void setRotationPart(const Mat3& m3);
+		void setTranslationPart(const Vec4& v4);
+		Mat3 getRotationPart() const;
+		void setTranslationPart(const Vec3& v3);
+		Vec3 getTranslationPart() const;
+		void transpose();
+		Mat4 getTransposed() const;
 		float getDet() const;
-		Mat4  getInverse() const; ///< Invert using Cramer's rule
-		void  invert(); ///< See getInverse
-		Mat4  getInverseTransformation() const;
-		Mat4  lerp(const Mat4& b, float t) const;
-		void  setIdentity();
+		Mat4 getInverse() const; ///< Invert using Cramer's rule
+		void invert(); ///< See getInverse
+		Mat4 getInverseTransformation() const;
+		Mat4 lerp(const Mat4& b, float t) const;
+		void setIdentity();
 		/// 12 muls, 27 adds. Something like m4 = m0 * m1 but without touching
 		/// the 4rth row and allot faster
 		static Mat4 combineTransformations(const Mat4& m0, const Mat4& m1);
@@ -105,6 +103,15 @@ class Mat4
 		static const Mat4& getZero();
 		/// @}
 
+		/// @name Friends
+		/// @{
+		friend Mat4 operator+(const float f, const Mat4& m4);
+		friend Mat4 operator-(const float f, const Mat4& m4);
+		friend Mat4 operator*(const float f, const Mat4& m4);
+		friend Mat4 operator/(const float f, const Mat4& m4);
+		friend std::ostream& operator<<(std::ostream& s, const Mat4& m);
+		/// @}
+
 	private:
 		/// @name Data
 		/// @{
@@ -118,19 +125,8 @@ class Mat4
 		};
 		/// @}
 };
-
-
-/// @name Other operators
-/// @{
-extern Mat4 operator+(float f, const Mat4& m4);
-extern Mat4 operator-(float f, const Mat4& m4);
-extern Mat4 operator*(float f, const Mat4& m4);
-extern Mat4 operator/(float f, const Mat4& m4);
-extern std::ostream& operator<<(std::ostream& s, const Mat4& m);
 /// @}
 
-} // end namespace
-
 
 #include "Mat4.inl.h"
 

+ 134 - 169
src/m/Mat4.inl.h

@@ -1,7 +1,4 @@
-#include "Common.inl.h"
-
-
-namespace m {
+#include "MathCommonSrc.h"
 
 
 //==============================================================================
@@ -24,6 +21,7 @@ inline Mat4::Mat4(const Mat4& b)
 #endif
 }
 
+
 // float
 inline Mat4::Mat4(const float f)
 {
@@ -40,6 +38,7 @@ inline Mat4::Mat4(const float f)
 #endif
 }
 
+
 // float[]
 inline Mat4::Mat4(const float arr_[])
 {
@@ -49,10 +48,14 @@ inline Mat4::Mat4(const float arr_[])
 	}
 }
 
+
 // many floats
-inline Mat4::Mat4(float m00, float m01, float m02, float m03, float m10,
-	float m11, float m12, float m13, float m20, float m21, float m22,
-	float m23, float m30, float m31, float m32, float m33)
+inline Mat4::Mat4(const float m00, const float m01, const float m02,
+	const float m03, const float m10, const float m11,
+	const float m12, const float m13, const float m20,
+	const float m21, const float m22, const float m23,
+	const float m30, const float m31, const float m32,
+	const float m33)
 {
 	(*this)(0, 0) = m00;
 	(*this)(0, 1) = m01;
@@ -72,6 +75,7 @@ inline Mat4::Mat4(float m00, float m01, float m02, float m03, float m10,
 	(*this)(3, 3) = m33;
 }
 
+
 // Mat3
 inline Mat4::Mat4(const Mat3& m3)
 {
@@ -89,6 +93,7 @@ inline Mat4::Mat4(const Mat3& m3)
 	(*this)(3, 3) = 1.0;
 }
 
+
 // Vec3
 inline Mat4::Mat4(const Vec3& v)
 {
@@ -110,6 +115,7 @@ inline Mat4::Mat4(const Vec3& v)
 	(*this)(3, 3) = 1.0;
 }
 
+
 // vec4
 inline Mat4::Mat4(const Vec4& v)
 {
@@ -131,6 +137,7 @@ inline Mat4::Mat4(const Vec4& v)
 	(*this)(3, 3) = v.w();
 }
 
+
 // Vec3, Mat3
 inline Mat4::Mat4(const Vec3& transl, const Mat3& rot)
 {
@@ -140,10 +147,11 @@ inline Mat4::Mat4(const Vec3& transl, const Mat3& rot)
 	(*this)(3, 3) = 1.0;
 }
 
+
 // Vec3, Mat3, float
-inline Mat4::Mat4(const Vec3& translate, const Mat3& rotate, float scale)
+inline Mat4::Mat4(const Vec3& translate, const Mat3& rotate, const float scale)
 {
-	if(!isZero(scale - 1.0))
+	if(!Math::isZero(scale - 1.0))
 	{
 		setRotationPart(rotate * scale);
 	}
@@ -158,6 +166,7 @@ inline Mat4::Mat4(const Vec3& translate, const Mat3& rotate, float scale)
 	(*this)(3, 3) = 1.0;
 }
 
+
 // Transform
 inline Mat4::Mat4(const Transform& t)
 {
@@ -169,33 +178,37 @@ inline Mat4::Mat4(const Transform& t)
 // Accessors                                                                   =
 //==============================================================================
 
-inline float& Mat4::operator()(const uint i, const uint j)
+inline float& Mat4::operator()(const size_t i, const size_t j)
 {
 	return arr2[i][j];
 }
 
-inline const float& Mat4::operator()(const uint i, const uint j) const
+
+inline const float& Mat4::operator()(const size_t i, const size_t j) const
 {
 	return arr2[i][j];
 }
 
-inline float& Mat4::operator[](const uint i)
+
+inline float& Mat4::operator[](const size_t i)
 {
 	return arr1[i];
 }
 
-inline const float& Mat4::operator[](const uint i) const
+
+inline const float& Mat4::operator[](const size_t i) const
 {
 	return arr1[i];
 }
 
+
 #if defined(MATH_INTEL_SIMD)
-inline const __m128& Mat4::getMm(uint i) const
+inline const __m128& Mat4::getMm(const size_t i) const
 {
 	return arrMm[i];
 }
 
-inline __m128& Mat4::getMm(uint i)
+inline __m128& Mat4::getMm(const size_t i)
 {
 	return arrMm[i];
 }
@@ -222,6 +235,7 @@ inline Mat4& Mat4::operator=(const Mat4& b)
 	return (*this);
 }
 
+
 // +
 inline Mat4 Mat4::operator+(const Mat4& b) const
 {
@@ -240,6 +254,7 @@ inline Mat4 Mat4::operator+(const Mat4& b) const
 	return c;
 }
 
+
 // +=
 inline Mat4& Mat4::operator+=(const Mat4& b)
 {
@@ -257,6 +272,7 @@ inline Mat4& Mat4::operator+=(const Mat4& b)
 	return (*this);
 }
 
+
 // -
 inline Mat4 Mat4::operator-(const Mat4& b) const
 {
@@ -275,6 +291,7 @@ inline Mat4 Mat4::operator-(const Mat4& b) const
 	return c;
 }
 
+
 // -=
 inline Mat4& Mat4::operator-=(const Mat4& b)
 {
@@ -292,6 +309,7 @@ inline Mat4& Mat4::operator-=(const Mat4& b)
 	return (*this);
 }
 
+
 // *
 inline Mat4 Mat4::operator*(const Mat4& b) const
 {
@@ -319,6 +337,7 @@ inline Mat4 Mat4::operator*(const Mat4& b) const
 	return c;
 }
 
+
 // *=
 inline Mat4& Mat4::operator*=(const Mat4& b)
 {
@@ -326,12 +345,13 @@ inline Mat4& Mat4::operator*=(const Mat4& b)
 	return (*this);
 }
 
+
 // ==
 inline bool Mat4::operator==(const Mat4& b) const
 {
 	for(int i = 0; i < 16; i++)
 	{
-		if(!isZero((*this)[i] - b[i]))
+		if(!Math::isZero((*this)[i] - b[i]))
 		{
 			return false;
 		}
@@ -339,12 +359,13 @@ inline bool Mat4::operator==(const Mat4& b) const
 	return true;
 }
 
+
 // !=
 inline bool Mat4::operator!=(const Mat4& b) const
 {
 	for(int i = 0; i < 16; i++)
 	{
-		if(!isZero((*this)[i]-b[i]))
+		if(!Math::isZero((*this)[i]-b[i]))
 		{
 			return true;
 		}
@@ -352,12 +373,13 @@ inline bool Mat4::operator!=(const Mat4& b) const
 	return false;
 }
 
+
 //==============================================================================
 // Operators with float                                                        =
 //==============================================================================
 
 // 4x4 + float
-inline Mat4 Mat4::operator+(float f) const
+inline Mat4 Mat4::operator+(const float f) const
 {
 	Mat4 c;
 #if defined(MATH_INTEL_SIMD)
@@ -376,14 +398,9 @@ inline Mat4 Mat4::operator+(float f) const
 	return c;
 }
 
-// float + 4x4
-inline Mat4 operator+(float f, const Mat4& m4)
-{
-	return m4 + f;
-}
 
 // 4x4 += float
-inline Mat4& Mat4::operator+=(float f)
+inline Mat4& Mat4::operator+=(const float f)
 {
 #if defined(MATH_INTEL_SIMD)
 	__m128 mm;
@@ -401,8 +418,9 @@ inline Mat4& Mat4::operator+=(float f)
 	return (*this);
 }
 
+
 // 4x4 - float
-inline Mat4 Mat4::operator-(float f) const
+inline Mat4 Mat4::operator-(const float f) const
 {
 	Mat4 r;
 #if defined(MATH_INTEL_SIMD)
@@ -421,28 +439,9 @@ inline Mat4 Mat4::operator-(float f) const
 	return r;
 }
 
-// float - 4x4
-inline Mat4 operator-(float f, const Mat4& m4)
-{
-	Mat4 r;
-#if defined(MATH_INTEL_SIMD)
-	__m128 mm;
-	mm = _mm_set1_ps(f);
-	for(int i = 0; i < 4; i++)
-	{
-		r.arrMm[i] = _mm_sub_ps(mm, m4.arrMm[i]);
-	}
-#else
-	for(int i = 0; i < 16; i++)
-	{
-		r[i] = f - m4[i];
-	}
-#endif
-	return r;
-}
 
 // 4x4 -= float
-inline Mat4& Mat4::operator-=(float f)
+inline Mat4& Mat4::operator-=(const float f)
 {
 #if defined(MATH_INTEL_SIMD)
 	__m128 mm;
@@ -460,8 +459,9 @@ inline Mat4& Mat4::operator-=(float f)
 	return (*this);
 }
 
+
 // 4x4 * float
-inline Mat4 Mat4::operator*(float f) const
+inline Mat4 Mat4::operator*(const float f) const
 {
 	Mat4 r;
 #if defined(MATH_INTEL_SIMD)
@@ -480,14 +480,9 @@ inline Mat4 Mat4::operator*(float f) const
 	return r;
 }
 
-// float * 4x4
-inline Mat4 operator*(float f, const Mat4& m4)
-{
-	return m4 * f;
-}
 
 // 4x4 *= float
-inline Mat4& Mat4::operator*=(float f)
+inline Mat4& Mat4::operator*=(const float f)
 {
 #if defined(MATH_INTEL_SIMD)
 	__m128 mm;
@@ -505,8 +500,9 @@ inline Mat4& Mat4::operator*=(float f)
 	return (*this);
 }
 
+
 // 4x4 / float
-inline Mat4 Mat4::operator/(float f) const
+inline Mat4 Mat4::operator/(const float f) const
 {
 	Mat4 r;
 #if defined(MATH_INTEL_SIMD)
@@ -525,28 +521,9 @@ inline Mat4 Mat4::operator/(float f) const
 	return r;
 }
 
-// float / 4x4
-inline Mat4 operator/(float f, const Mat4& m4)
-{
-	Mat4 r;
-#if defined(MATH_INTEL_SIMD)
-	__m128 mm;
-	mm = _mm_set1_ps(f);
-	for(int i = 0; i < 4; i++)
-	{
-		r.arrMm[i] = _mm_div_ps(mm, m4.arrMm[i]);
-	}
-#else
-	for(int i = 0; i < 16; i++)
-	{
-		r[i] = f / m4[i];
-	}
-#endif
-	return r;
-}
 
 // 4x4 /= float
-inline Mat4& Mat4::operator/=(float f)
+inline Mat4& Mat4::operator/=(const float f)
 {
 #if defined(MATH_INTEL_SIMD)
 	__m128 mm;
@@ -593,7 +570,7 @@ inline Vec4 Mat4::operator*(const Vec4& b) const
 
 
 //==============================================================================
-// Misc methods                                                                =
+// Other                                                                       =
 //==============================================================================
 
 // setRows
@@ -625,8 +602,9 @@ inline void Mat4::setRows(const Vec4& a, const Vec4& b, const Vec4& c,
 #endif
 }
 
+
 // setRow
-inline void Mat4::setRow(uint i, const Vec4& v)
+inline void Mat4::setRow(const size_t i, const Vec4& v)
 {
 #if defined(MATH_INTEL_SIMD)
 	arrMm[i] = v.getMm();
@@ -638,6 +616,7 @@ inline void Mat4::setRow(uint i, const Vec4& v)
 #endif
 }
 
+
 // setColumns
 inline void Mat4::setColumns(const Vec4& a, const Vec4& b, const Vec4& c,
 	const Vec4& d)
@@ -660,8 +639,9 @@ inline void Mat4::setColumns(const Vec4& a, const Vec4& b, const Vec4& c,
 	(*this)(3, 3) = d.w();
 }
 
+
 // setColumn
-inline void Mat4::setColumn(uint i, const Vec4& v)
+inline void Mat4::setColumn(const size_t i, const Vec4& v)
 {
 	(*this)(0, i) = v.x();
 	(*this)(1, i) = v.y();
@@ -669,6 +649,7 @@ inline void Mat4::setColumn(uint i, const Vec4& v)
 	(*this)(3, i) = v.w();
 }
 
+
 // transpose
 inline void Mat4::transpose()
 {
@@ -696,6 +677,7 @@ inline void Mat4::transpose()
 #endif
 }
 
+
 // getTransposed
 inline Mat4 Mat4::getTransposed() const
 {
@@ -719,6 +701,7 @@ inline Mat4 Mat4::getTransposed() const
 	return m4;
 }
 
+
 // setRotationPart
 inline void Mat4::setRotationPart(const Mat3& m3)
 {
@@ -733,6 +716,7 @@ inline void Mat4::setRotationPart(const Mat3& m3)
 	(*this)(2, 2) = m3(2, 2);
 }
 
+
 // getRotationPart
 inline Mat3 Mat4::getRotationPart() const
 {
@@ -749,6 +733,7 @@ inline Mat3 Mat4::getRotationPart() const
 	return m3;
 }
 
+
 // setTranslationPart
 inline void Mat4::setTranslationPart(const Vec4& v)
 {
@@ -758,6 +743,7 @@ inline void Mat4::setTranslationPart(const Vec4& v)
 	(*this)(3, 3) = v.w();
 }
 
+
 // setTranslationPart
 inline void Mat4::setTranslationPart(const Vec3& v)
 {
@@ -766,12 +752,14 @@ inline void Mat4::setTranslationPart(const Vec3& v)
 	(*this)(2, 3) = v.z();
 }
 
+
 // getTranslationPart
 inline Vec3 Mat4::getTranslationPart() const
 {
 	return Vec3((*this)(0, 3), (*this)(1, 3), (*this)(2, 3));
 }
 
+
 // getIdentity
 inline const Mat4& Mat4::getIdentity()
 {
@@ -780,6 +768,7 @@ inline const Mat4& Mat4::getIdentity()
 	return ident;
 }
 
+
 // getZero
 inline const Mat4& Mat4::getZero()
 {
@@ -787,6 +776,7 @@ inline const Mat4& Mat4::getZero()
 	return zero;
 }
 
+
 // Determinant
 inline float Mat4::getDet() const
 {
@@ -817,93 +807,10 @@ inline float Mat4::getDet() const
 		t(0, 0) * t(1, 1) * t(2, 2) * t(3, 3);
 }
 
+
 // getInverse
 inline Mat4 Mat4::getInverse() const
 {
-	/// @todo test this
-/*#if !defined(MATH_INTEL_SIMD)
-	Mat4 r((*this));
-	__m128 minor0, minor1, minor2, minor3;
-	__m128 det, tmp1;
-
-	// Transpose
-	r.transpose();
-
-	// Calc coeffs
-	tmp1 = _mm_mul_ps(r.arrMm[2], r.arrMm[3]);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
-	minor0 = _mm_mul_ps(r.arrMm[1], tmp1);
-	minor1 = _mm_mul_ps(r.arrMm[0], tmp1);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
-	minor0 = _mm_sub_ps(_mm_mul_ps(r.arrMm[1], tmp1), minor0);
-	minor1 = _mm_sub_ps(_mm_mul_ps(r.arrMm[0], tmp1), minor1);
-	minor1 = _mm_shuffle_ps(minor1, minor1, 0x4E);
-
-	tmp1 = _mm_mul_ps(r.arrMm[1], r.arrMm[2]);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
-	minor0 = _mm_add_ps(_mm_mul_ps(r.arrMm[3], tmp1), minor0);
-	minor3 = _mm_mul_ps(r.arrMm[0], tmp1);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
-	minor0 = _mm_sub_ps(minor0, _mm_mul_ps(r.arrMm[3], tmp1));
-	minor3 = _mm_sub_ps(_mm_mul_ps(r.arrMm[0], tmp1), minor3);
-	minor3 = _mm_shuffle_ps(minor3, minor3, 0x4E);
-
-	tmp1 = _mm_mul_ps(_mm_shuffle_ps(r.arrMm[1], r.arrMm[1], 0x4E),
-		r.arrMm[3]);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
-	r.arrMm[2] = _mm_shuffle_ps(r.arrMm[2], r.arrMm[2], 0x4E);
-	minor0 = _mm_add_ps(_mm_mul_ps(r.arrMm[2], tmp1), minor0);
-	minor2 = _mm_mul_ps(r.arrMm[0], tmp1);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
-	minor0 = _mm_sub_ps(minor0, _mm_mul_ps(r.arrMm[2], tmp1));
-	minor2 = _mm_sub_ps(_mm_mul_ps(r.arrMm[0], tmp1), minor2);
-	minor2 = _mm_shuffle_ps(minor2, minor2, 0x4E);
-
-	tmp1 = _mm_mul_ps(r.arrMm[0], r.arrMm[1]);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
-	minor2 = _mm_add_ps(_mm_mul_ps(r.arrMm[3], tmp1), minor2);
-	minor3 = _mm_sub_ps(_mm_mul_ps(r.arrMm[2], tmp1), minor3);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
-	minor2 = _mm_sub_ps(_mm_mul_ps(r.arrMm[3], tmp1), minor2);
-	minor3 = _mm_sub_ps(minor3, _mm_mul_ps(r.arrMm[2], tmp1));
-
-	tmp1 = _mm_mul_ps(r.arrMm[0], r.arrMm[3]);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
-	minor1 = _mm_sub_ps(minor1, _mm_mul_ps(r.arrMm[2], tmp1));
-	minor2 = _mm_add_ps(_mm_mul_ps(r.arrMm[1], tmp1), minor2);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
-	minor1 = _mm_add_ps(_mm_mul_ps(r.arrMm[2], tmp1), minor1);
-	minor2 = _mm_sub_ps(minor2, _mm_mul_ps(r.arrMm[1], tmp1));
-
-	tmp1 = _mm_mul_ps(r.arrMm[0], r.arrMm[2]);
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0xB1);
-	minor1 = _mm_add_ps(_mm_mul_ps(r.arrMm[3], tmp1), minor1);
-	minor3 = _mm_sub_ps(minor3, _mm_mul_ps(r.arrMm[1], tmp1));
-	tmp1 = _mm_shuffle_ps(tmp1, tmp1, 0x4E);
-	minor1 = _mm_sub_ps(minor1, _mm_mul_ps(r.arrMm[3], tmp1));
-	minor3 = _mm_add_ps(_mm_mul_ps(r.arrMm[1], tmp1), minor3);
-
-	// 1 / det
-	det = _mm_mul_ps(r.arrMm[0], minor0);
-	det = _mm_add_ps(_mm_shuffle_ps(det, det, 0x4E), det);
-	det = _mm_add_ss(_mm_shuffle_ps(det, det, 0xB1), det);
-	tmp1 = _mm_rcp_ss(det);
-	det = _mm_sub_ss(_mm_add_ss(tmp1, tmp1),
-		_mm_mul_ss(det, _mm_mul_ss(tmp1, tmp1)));
-	det = _mm_shuffle_ps(det, det, 0x00);
-
-	// Mul and store
-	minor0 = _mm_mul_ps(det, minor0);
-	r.arrMm[0] = minor0;
-	minor1 = _mm_mul_ps(det, minor1);
-	r.arrMm[1] = minor1;
-	minor2 = _mm_mul_ps(det, minor2);
-	r.arrMm[2] = minor2;
-	minor3 = _mm_mul_ps(det, minor3);
-	r.arrMm[3] = minor3;
-
-	return r;
-#else*/
 	float tmp[12];
 	float det;
 	const Mat4& in = (*this);
@@ -972,13 +879,13 @@ inline Mat4 Mat4::getInverse() const
 	det = (*this)(0, 0) * m4(0, 0) + (*this)(1, 0) * m4(0, 1) +
 		(*this)(2, 0) * m4(0, 2) + (*this)(3, 0) * m4(0, 3);
 
-	ASSERT(!isZero(det)); // Cannot invert, det == 0
+	ASSERT(!Math::isZero(det)); // Cannot invert, det == 0
 	det = 1.0 / det;
 	m4 *= det;
 	return m4;
-//#endif
 }
 
+
 // invert
 inline void Mat4::invert()
 {
@@ -995,18 +902,21 @@ inline Mat4 Mat4::getInverseTransformation() const
 	return Mat4(invertedTsl, invertedRot);
 }
 
+
 // lerp
-inline Mat4 Mat4::lerp(const Mat4& b, float t) const
+inline Mat4 Mat4::lerp(const Mat4& b, const float t) const
 {
 	return ((*this) * (1.0 - t)) + (b * t);
 }
 
+
 // setIdentity
 inline void Mat4::setIdentity()
 {
 	(*this) = getIdentity();
 }
 
+
 // combineTransformations
 inline Mat4 Mat4::combineTransformations(const Mat4& m0, const Mat4& m1)
 {
@@ -1021,8 +931,8 @@ inline Mat4 Mat4::combineTransformations(const Mat4& m0, const Mat4& m1)
 	*/
 
 	// one of the 2 mat4 doesnt represent transformation
-	ASSERT(isZero(m0(3, 0) + m0(3, 1) + m0(3, 2) + m0(3, 3)-1.0) &&
-		isZero(m1(3, 0) + m1(3, 1) + m1(3, 2) + m1(3, 3)-1.0));
+	ASSERT(Math::isZero(m0(3, 0) + m0(3, 1) + m0(3, 2) + m0(3, 3)-1.0) &&
+		Math::isZero(m1(3, 0) + m1(3, 1) + m1(3, 2) + m1(3, 3)-1.0));
 
 	Mat4 m4;
 
@@ -1053,8 +963,66 @@ inline Mat4 Mat4::combineTransformations(const Mat4& m0, const Mat4& m1)
 
 
 //==============================================================================
-// Print                                                                       =
+// Friends                                                                     =
 //==============================================================================
+
+// float + 4x4
+inline Mat4 operator+(const float f, const Mat4& m4)
+{
+	return m4 + f;
+}
+
+
+// float - 4x4
+inline Mat4 operator-(const float f, const Mat4& m4)
+{
+	Mat4 r;
+#if defined(MATH_INTEL_SIMD)
+	__m128 mm;
+	mm = _mm_set1_ps(f);
+	for(int i = 0; i < 4; i++)
+	{
+		r.arrMm[i] = _mm_sub_ps(mm, m4.arrMm[i]);
+	}
+#else
+	for(int i = 0; i < 16; i++)
+	{
+		r[i] = f - m4[i];
+	}
+#endif
+	return r;
+}
+
+
+// float * 4x4
+inline Mat4 operator*(const float f, const Mat4& m4)
+{
+	return m4 * f;
+}
+
+
+// float / 4x4
+inline Mat4 operator/(const float f, const Mat4& m4)
+{
+	Mat4 r;
+#if defined(MATH_INTEL_SIMD)
+	__m128 mm;
+	mm = _mm_set1_ps(f);
+	for(int i = 0; i < 4; i++)
+	{
+		r.arrMm[i] = _mm_div_ps(mm, m4.arrMm[i]);
+	}
+#else
+	for(int i = 0; i < 16; i++)
+	{
+		r[i] = f / m4[i];
+	}
+#endif
+	return r;
+}
+
+
+// Print
 inline std::ostream& operator<<(std::ostream& s, const Mat4& m)
 {
 	for(int i = 0; i < 4; i++)
@@ -1071,6 +1039,3 @@ inline std::ostream& operator<<(std::ostream& s, const Mat4& m)
 	}
 	return s;
 }
-
-
-} // end namespace

+ 9 - 8
src/m/Funcs.cpp → src/m/Math.cpp

@@ -1,14 +1,18 @@
-#include "Funcs.h"
+#include "MathCommonSrc.h"
 
 
-namespace m {
+//==============================================================================
+// Statics                                                                     =
+//==============================================================================
 
+const float Math::PI = 3.14159265358979323846;
+const float Math::EPSILON = 1.0e-6;
 
 
 //==============================================================================
 // polynomialSinQuadrant                                                       =
 //==============================================================================
-static float polynomialSinQuadrant(float a)
+float Math::polynomialSinQuadrant(float a)
 {
 	return a * (1.0 + a * a * (-0.16666 + a * a *
 		(0.0083143 - a * a * 0.00018542)));
@@ -18,7 +22,7 @@ static float polynomialSinQuadrant(float a)
 //==============================================================================
 // sinCos                                                                      =
 //==============================================================================
-void sinCos(float a, float& sina, float& cosa)
+void Math::sinCos(float a, float& sina, float& cosa)
 {
 	bool negative = false;
 	if(a < 0.0)
@@ -26,7 +30,7 @@ void sinCos(float a, float& sina, float& cosa)
 		a = -a;
 		negative = true;
 	}
-	const float kTwoOverPi = 1.0 / (PI/2.0);
+	const float kTwoOverPi = 1.0 / (Math::PI / 2.0);
 	float floatA = kTwoOverPi * a;
 	int intA = (int)floatA;
 
@@ -62,6 +66,3 @@ void sinCos(float a, float& sina, float& cosa)
 		sina = -sina;
 	}
 }
-
-
-} // end namespace

+ 52 - 14
src/m/Math.h

@@ -1,21 +1,59 @@
-#ifndef M_MATH_H
-#define M_MATH_H
+#ifndef MATH_H
+#define MATH_H
 
+#include "MathCommonIncludes.h"
 
-#include <math.h>
-#include "Vec2.h"
-#include "Vec3.h"
-#include "Vec4.h"
-#include "Quat.h"
-#include "Axisang.h"
-#include "Euler.h"
-#include "Mat3.h"
-#include "Mat4.h"
-#include "Funcs.h"
-#include "Transform.h"
 
+/// @addtogroup Math
+/// @{
 
-using namespace m;
+/// Useful and optimized math functions
+class Math
+{
+	public:
+		static const float PI;
+		static const float EPSILON;
+
+		/// A fast func that given the angle in rads it returns the sin and cos
+		static void sinCos(float rad, float& sin_, float& cos_);
+
+		/// Optimized square root
+		static float sqrt(float f);
+
+		/// Convert
+		static float toRad(float degrees);
+
+		/// Convert
+		static float toDegrees(float rad);
+
+		/// Optimized sine
+		static float sin(float rad);
+
+		/// Optimized cosine
+		static float cos(float rad);
+
+		/// The proper way to test if a float is zero
+		static bool isZero(float f);
+
+		/// Mat4(t0,r0,s0) * Mat4(t1, r1, s1) == Mat4(tf, rf, sf)
+		static void combineTransformations(
+			const Vec3& t0, const Mat3& r0, float s0, // in 0
+			const Vec3& t1, const Mat3& r1, float s1, // in 1
+			Vec3& tf, Mat3& rf, float& sf); // out
+
+		/// Mat4(t0, r0, 1.0) * Mat4(t1, r1, 1.0) == Mat4(tf, rf, sf)
+		static void combineTransformations(
+			const Vec3& t0, const Mat3& r0, // in 0
+			const Vec3& t1, const Mat3& r1, // in 1
+			Vec3& tf, Mat3& rf); // out
+
+	private:
+		static float polynomialSinQuadrant(float a);
+};
+/// @}
+
+
+#include "Math.inl.h"
 
 
 #endif

+ 17 - 22
src/m/Funcs.inl.h → src/m/Math.inl.h

@@ -1,13 +1,11 @@
-#include "Common.inl.h"
-
-
-namespace m {
+#include "MathCommonSrc.h"
+#include <cmath>
 
 
 //==============================================================================
 // Small funcs                                                                 =
 //==============================================================================
-inline float sqrt(float f)
+inline float Math::sqrt(float f)
 {
 #if defined(MATH_INTEL_SIMD)
 	__m128 mm = _mm_set_ss(f);
@@ -21,39 +19,38 @@ inline float sqrt(float f)
 }
 
 
-inline float toRad(float degrees)
+inline float Math::toRad(float degrees)
 {
-	return degrees * (PI / 180.0);
+	return degrees * (Math::PI / 180.0);
 }
 
 
-inline float toDegrees(float rad)
+inline float Math::toDegrees(float rad)
 {
-	return rad * (180.0 / PI);
+	return rad * (180.0 / Math::PI);
 }
 
 
-inline float sin(float rad)
+inline float Math::sin(float rad)
 {
 	return ::sin(rad);
 }
 
 
-inline float cos(float rad)
+inline float Math::cos(float rad)
 {
 	return ::cos(rad);
 }
 
 
-inline bool isZero(float f)
+inline bool Math::isZero(float f)
 {
-	return fabs(f) < EPSILON;
+	return fabs(f) < Math::EPSILON;
 }
 
 
-//  combineTransformations
-//  mat4(t0,r0,s0)*mat4(t1,r1,s1) == mat4(tf,rf,sf)
-inline void combineTransformations(const Vec3& t0, const Mat3& r0, float s0,
+inline void Math::combineTransformations(
+	const Vec3& t0, const Mat3& r0, float s0,
 	const Vec3& t1, const Mat3& r1, float s1,
 	Vec3& tf, Mat3& rf, float& sf)
 {
@@ -63,13 +60,11 @@ inline void combineTransformations(const Vec3& t0, const Mat3& r0, float s0,
 }
 
 
-//  combineTransformations as the above but without scale
-inline void combineTransformations(const Vec3& t0, const Mat3& r0,
-	const Vec3& t1, const Mat3& r1, Vec3& tf, Mat3& rf)
+inline void Math::combineTransformations(
+	const Vec3& t0, const Mat3& r0,
+	const Vec3& t1, const Mat3& r1,
+	Vec3& tf, Mat3& rf)
 {
 	tf = t1.getTransformed(t0, r0);
 	rf = r0 * r1;
 }
-
-
-} // end namespace

+ 3 - 0
src/m/MathCommonIncludes.h

@@ -0,0 +1,3 @@
+#include "MathForward.h"
+#include "MathSimd.h"
+#include <boost/array.hpp>

+ 1 - 5
src/m/Common.inl.h → src/m/MathCommonSrc.h

@@ -1,6 +1,3 @@
-/// @file
-/// For Internal use in math lib
-
 #include "Vec2.h"
 #include "Vec3.h"
 #include "Vec4.h"
@@ -9,8 +6,7 @@
 #include "Euler.h"
 #include "Mat3.h"
 #include "Mat4.h"
-#include "Funcs.h"
 #include "Transform.h"
-
+#include "Math.h"
 #include "util/Assert.h"
 #include <cmath>

+ 18 - 0
src/m/MathForward.h

@@ -0,0 +1,18 @@
+#ifndef MATH_FORWARD_H
+#define MATH_FORWARD_H
+
+#include <iosfwd>
+
+
+class Vec2;
+class Vec3;
+class Vec4;
+class Quat;
+class Euler;
+class Axisang;
+class Mat3;
+class Mat4;
+class Transform;
+
+
+#endif

+ 9 - 0
src/m/MathSimd.h

@@ -0,0 +1,9 @@
+#ifndef MATH_SIMD_H
+#define MATH_SIMD_H
+
+#if defined(MATH_INTEL_SIMD)
+#	include <smmintrin.h>
+#endif
+
+
+#endif

+ 17 - 19
src/m/Quat.h

@@ -1,23 +1,24 @@
-#ifndef M_QUAT_H
-#define M_QUAT_H
+#ifndef QUAT_H
+#define QUAT_H
 
-#include "Common.h"
+#include "MathCommonIncludes.h"
 
 
-namespace m {
-
+/// @addtogroup Math
+/// @{
 
 /// Used in rotations
 class Quat
 {
 	public:
-		/// @name Constructors & destructors
+		/// @name Constructors
 		/// @{
 		explicit Quat();
-		explicit Quat(float f);
-		explicit Quat(float x, float y, float z, float w);
-		explicit Quat(const Vec2& v2, float z, float w);
-		explicit Quat(const Vec3& v3, float w);
+		explicit Quat(const float f);
+		explicit Quat(const float x, const float y, const float z,
+			const float w);
+		explicit Quat(const Vec2& v2, const float z, const float w);
+		explicit Quat(const Vec3& v3, const float w);
 		explicit Quat(const Vec4& v4);
 		         Quat(const Quat& b);
 		explicit Quat(const Mat3& m3);
@@ -60,13 +61,18 @@ class Quat
 		Quat  getNormalized() const;
 		float dot(const Quat& b) const;
 		/// Returns slerp(this, q1, t)
-		Quat  slerp(const Quat& q1, float t) const;
+		Quat  slerp(const Quat& q1, const float t) const;
 		Quat  getRotated(const Quat& b) const; ///< The same as Quat * Quat
 		void  rotate(const Quat& b); ///< @see getRotated
 		void  setIdentity();
 		static const Quat& getIdentity();
 		/// @}
 
+		/// @name Friends
+		/// @{
+		friend std::ostream& operator<<(std::ostream& s, const Quat& q);
+		/// @}
+
 	private:
 		/// @name Data
 		/// @{
@@ -76,17 +82,9 @@ class Quat
 		} vec;
 		/// @}
 };
-
-
-/// @name Other operators
-/// @{
-extern std::ostream& operator<<(std::ostream& s, const Quat& q);
 /// @}
 
 
-} // end namespace
-
-
 #include "Quat.inl.h"
 
 

+ 62 - 26
src/m/Quat.inl.h

@@ -1,7 +1,4 @@
-#include "Common.inl.h"
-
-
-namespace m {
+#include "MathCommonSrc.h"
 
 
 //==============================================================================
@@ -14,14 +11,17 @@ inline Quat::Quat()
 	x() = y() = z() = w() = 0.0;
 }
 
+
 // float
-inline Quat::Quat(float f)
+inline Quat::Quat(const float f)
 {
 	x() = y() = z() = w() = f;
 }
 
+
 // float, float, float, float
-inline Quat::Quat(float x_, float y_, float z_, float w_)
+inline Quat::Quat(const float x_, const float y_, const float z_,
+	const float w_)
 {
 	x() = x_;
 	y() = y_;
@@ -29,8 +29,9 @@ inline Quat::Quat(float x_, float y_, float z_, float w_)
 	w() = w_;
 }
 
+
 // constructor [vec2, float, float]
-inline Quat::Quat(const Vec2& v, float z_, float w_)
+inline Quat::Quat(const Vec2& v, const float z_, const float w_)
 {
 	x() = v.x();
 	y() = v.y();
@@ -38,8 +39,9 @@ inline Quat::Quat(const Vec2& v, float z_, float w_)
 	w() = w_;
 }
 
+
 // constructor [vec3, float]
-inline Quat::Quat(const Vec3& v, float w_)
+inline Quat::Quat(const Vec3& v, const float w_)
 {
 	x() = v.x();
 	y() = v.y();
@@ -47,6 +49,7 @@ inline Quat::Quat(const Vec3& v, float w_)
 	w() = w_;
 }
 
+
 // constructor [vec4]
 inline Quat::Quat(const Vec4& v)
 {
@@ -56,6 +59,7 @@ inline Quat::Quat(const Vec4& v)
 	w() = v.w();
 }
 
+
 // Copy
 inline Quat::Quat(const Quat& b)
 {
@@ -65,11 +69,12 @@ inline Quat::Quat(const Quat& b)
 	w() = b.w();
 }
 
+
 // mat3
 inline Quat::Quat(const Mat3& m3)
 {
 	float trace = m3(0, 0) + m3(1, 1) + m3(2, 2) + 1.0;
-	if(trace > EPSILON)
+	if(trace > Math::EPSILON)
 	{
 		float s = 0.5 / sqrt(trace);
 		w() = 0.25 / s;
@@ -106,17 +111,18 @@ inline Quat::Quat(const Mat3& m3)
 	}
 }
 
+
 // euler
 inline Quat::Quat(const Euler& eu)
 {
 	float cx, sx;
-	sinCos(eu.y() * 0.5, sx, cx);
+	Math::sinCos(eu.y() * 0.5, sx, cx);
 
 	float cy, sy;
-	sinCos(eu.z() * 0.5, sy, cy);
+	Math::sinCos(eu.z() * 0.5, sy, cy);
 
 	float cz, sz;
-	sinCos(eu.x() * 0.5, sz, cz);
+	Math::sinCos(eu.x() * 0.5, sz, cz);
 
 	float cxcy = cx * cy;
 	float sxsy = sx * sy;
@@ -126,11 +132,12 @@ inline Quat::Quat(const Euler& eu)
 	w() = cxcy * cz - sxsy * sz;
 }
 
+
 // euler
 inline Quat::Quat(const Axisang& axisang)
 {
 	float lengthsq = axisang.getAxis().getLengthSquared();
-	if(isZero(lengthsq))
+	if(Math::isZero(lengthsq))
 	{
 		(*this) = getIdentity();
 		return;
@@ -139,7 +146,7 @@ inline Quat::Quat(const Axisang& axisang)
 	float rad = axisang.getAngle() * 0.5;
 
 	float sintheta, costheta;
-	sinCos(rad, sintheta, costheta);
+	Math::sinCos(rad, sintheta, costheta);
 
 	float scalefactor = sintheta / sqrt(lengthsq);
 
@@ -165,31 +172,37 @@ inline float& Quat::x()
 	return vec.x;
 }
 
+
 inline float Quat::y() const
 {
 	return vec.y;
 }
 
+
 inline float& Quat::y()
 {
 	return vec.y;
 }
 
+
 inline float Quat::z() const
 {
 	return vec.z;
 }
 
+
 inline float& Quat::z()
 {
 	return vec.z;
 }
 
+
 inline float Quat::w() const
 {
 	return vec.w;
 }
 
+
 inline float& Quat::w()
 {
 	return vec.w;
@@ -210,6 +223,7 @@ inline Quat& Quat::operator=(const Quat& b)
 	return *this;
 }
 
+
 // *
 inline Quat Quat::operator *(const Quat& b) const
 {
@@ -220,6 +234,7 @@ inline Quat Quat::operator *(const Quat& b) const
 	);
 }
 
+
 // *=
 inline Quat& Quat::operator *=(const Quat& b)
 {
@@ -227,18 +242,24 @@ inline Quat& Quat::operator *=(const Quat& b)
 	return (*this);
 }
 
+
 // ==
 inline bool Quat::operator ==(const Quat& b) const
 {
-	return isZero(x() - b.x()) && isZero(y() - b.y()) && isZero(z() - b.z()) &&
-		isZero(w() - b.w());
+	return Math::isZero(x() - b.x()) &&
+		Math::isZero(y() - b.y()) &&
+		Math::isZero(z() - b.z()) &&
+		Math::isZero(w() - b.w());
 }
 
+
 // !=
 inline bool Quat::operator !=(const Quat& b) const
 {
-	return !(isZero(x() - b.x()) && isZero(y() - b.y()) &&
-		isZero(z() - b.z()) && isZero(w() - b.w()));
+	return !(Math::isZero(x() - b.x()) &&
+		Math::isZero(y() - b.y()) &&
+		Math::isZero(z() - b.z()) &&
+		Math::isZero(w() - b.w()));
 }
 
 
@@ -254,28 +275,32 @@ inline void Quat::conjugate()
 	z() = -z();
 }
 
+
 // getConjugated
 inline Quat Quat::getConjugated() const
 {
 	return Quat(-x(), -y(), -z(), w());
 }
 
+
 // Normalized
 inline Quat Quat::getNormalized() const
 {
 	return Quat(Vec4((*this)).getNormalized());
 }
 
+
 // normalize
 inline void Quat::normalize()
 {
 	(*this) = getNormalized();
 }
 
+
 // getLength
 inline float Quat::getLength() const
 {
-	return m::sqrt(w() * w() + x() * x() + y() * y() + z() * z());
+	return Math::sqrt(w() * w() + x() * x() + y() * y() + z() * z());
 }
 
 
@@ -284,18 +309,20 @@ inline Quat Quat::getInverted() const
 {
 	float norm = w() * w() + x() * x() + y() * y() + z() * z();
 
-	ASSERT(!isZero(norm)); // Norm is zero
+	ASSERT(!Math::isZero(norm)); // Norm is zero
 
 	float normi = 1.0 / norm;
 	return Quat(-normi * x(), -normi * y(), -normi * z(), normi * w());
 }
 
+
 // invert
 inline void Quat::invert()
 {
 	(*this) = getInverted();
 }
 
+
 // CalcFromVecVec
 inline void Quat::setFrom2Vec3(const Vec3& from, const Vec3& to)
 {
@@ -304,7 +331,7 @@ inline void Quat::setFrom2Vec3(const Vec3& from, const Vec3& to)
 	normalize();
 	w() += 1.0;
 
-	if(w() <= EPSILON)
+	if(w() <= Math::EPSILON)
 	{
 		if(from.z() * from.z() > from.x() * from.x())
 		{
@@ -318,26 +345,30 @@ inline void Quat::setFrom2Vec3(const Vec3& from, const Vec3& to)
 	normalize();
 }
 
+
 // getRotated
 inline Quat Quat::getRotated(const Quat& b) const
 {
 	return (*this) * b;
 }
 
+
 // rotate
 inline void Quat::rotate(const Quat& b)
 {
 	(*this) = getRotated(b);
 }
 
+
 // dot
 inline float Quat::dot(const Quat& b) const
 {
 	return w() * b.w() + x() * b.x() + y() * b.y() + z() * b.z();
 }
 
+
 // SLERP
-inline Quat Quat::slerp(const Quat& q1_, float t) const
+inline Quat Quat::slerp(const Quat& q1_, const float t) const
 {
 	const Quat& q0 = (*this);
 	Quat q1(q1_);
@@ -348,13 +379,14 @@ inline Quat Quat::slerp(const Quat& q1_, float t) const
 		q1 = Quat(-Vec4(q1)); // quat changes
 		cosHalfTheta = -cosHalfTheta;
 	}
+
 	if(fabs(cosHalfTheta) >= 1.0f)
 	{
 		return Quat(q0);
 	}
 
 	float halfTheta = acos(cosHalfTheta);
-	float sinHalfTheta = m::sqrt(1.0 - cosHalfTheta*cosHalfTheta);
+	float sinHalfTheta = Math::sqrt(1.0 - cosHalfTheta*cosHalfTheta);
 
 	if(fabs(sinHalfTheta) < 0.001)
 	{
@@ -370,6 +402,7 @@ inline Quat Quat::slerp(const Quat& q1_, float t) const
 	return Quat(sum);
 }
 
+
 // setIdentity
 inline void Quat::setIdentity()
 {
@@ -377,6 +410,7 @@ inline void Quat::setIdentity()
 	w() = 1.0;
 }
 
+
 // getIdentity
 inline const Quat& Quat::getIdentity()
 {
@@ -384,12 +418,14 @@ inline const Quat& Quat::getIdentity()
 	return ident;
 }
 
+
+//==============================================================================
+// Friends                                                                     =
+//==============================================================================
+
 // print
 inline std::ostream& operator<<(std::ostream& s, const Quat& q)
 {
 	s << q.w() << ' ' << q.x() << ' ' << q.y() << ' ' << q.z();
 	return s;
 }
-
-
-} // end namespace

+ 9 - 10
src/m/Transform.h

@@ -1,11 +1,13 @@
-#ifndef M_TRANSFORM_H
-#define M_TRANSFORM_H
+#ifndef TRANSFORM_H
+#define TRANSFORM_H
 
-#include "Common.h"
+#include "Vec3.h"
+#include "Mat3.h"
+#include "MathCommonIncludes.h"
 
 
-namespace m {
-
+/// @addtogroup Math
+/// @{
 
 /// For transformations
 class Transform
@@ -17,7 +19,7 @@ class Transform
 		         Transform(const Transform& b);
 		explicit Transform(const Mat4& m4);
 		explicit Transform(const Vec3& origin, const Mat3& rotation_,
-			float scale_);
+			const float scale_);
 		/// @}
 
 		/// @name Accessors
@@ -32,7 +34,7 @@ class Transform
 		
 		float getScale() const;
 		float& getScale();
-		void setScale(float s);
+		void setScale(const float s);
 		/// @}
 
 		/// @name Operators with same
@@ -58,9 +60,6 @@ class Transform
 };
 
 
-} // end namespace
-
-
 #include "Transform.inl.h"
 
 

+ 19 - 14
src/m/Transform.inl.h

@@ -1,10 +1,4 @@
-#include "Common.inl.h"
-
-
-#define ME (*this)
-
-
-namespace m {
+#include "MathCommonSrc.h"
 
 
 //==============================================================================
@@ -15,6 +9,7 @@ namespace m {
 inline Transform::Transform()
 {}
 
+
 // Copy
 inline Transform::Transform(const Transform& b)
 :	origin(b.origin),
@@ -22,6 +17,7 @@ inline Transform::Transform(const Transform& b)
 	scale(b.scale)
 {}
 
+
 // Mat4
 inline Transform::Transform(const Mat4& m4)
 {
@@ -30,9 +26,10 @@ inline Transform::Transform(const Mat4& m4)
 	scale = 1.0;
 }
 
+
 // Vec3, Quat, float
 inline Transform::Transform(const Vec3& origin, const Mat3& rotation_,
-	float scale_)
+	const float scale_)
 :	origin(origin),
 	rotation(rotation_),
 	scale(scale_)
@@ -48,42 +45,50 @@ inline const Vec3& Transform::getOrigin() const
 	return origin;
 }
 
+
 inline Vec3& Transform::getOrigin()
 {
 	return origin;
 }
 
+
 inline void Transform::setOrigin(const Vec3 o)
 {
 	origin = o;
 }
 
+
 inline const Mat3& Transform::getRotation() const
 {
 	return rotation;
 }
 
+
 inline Mat3& Transform::getRotation()
 {
 	return rotation;
 }
 
+
 inline void Transform::setRotation(const Mat3& r)
 {
 	rotation = r;
 }
 
+
 inline float Transform::getScale() const
 {
 	return scale;
 }
 
+
 inline float& Transform::getScale()
 {
 	return scale;
 }
 
-inline void Transform::setScale(float s)
+
+inline void Transform::setScale(const float s)
 {
 	scale = s;
 }
@@ -110,9 +115,10 @@ inline Transform& Transform::operator=(const Transform& b)
 // setIdentity
 inline void Transform::setIdentity()
 {
-	ME = getIdentity();
+	(*this) = getIdentity();
 }
 
+
 // getIdentity
 inline const Transform& Transform::getIdentity()
 {
@@ -120,18 +126,17 @@ inline const Transform& Transform::getIdentity()
 	return ident;
 }
 
+
 // combineTransformations
 inline Transform Transform::combineTransformations(const Transform& a,
 	const Transform& b)
 {
 	Transform out;
 
-	m::combineTransformations(a.origin, a.rotation, a.scale,
+	Math::combineTransformations(
+		a.origin, a.rotation, a.scale,
 		b.origin, b.rotation, b.scale,
 		out.origin, out.rotation, out.scale);
 
 	return out;
 }
-
-
-} // end namespace

+ 27 - 32
src/m/Vec2.h

@@ -1,22 +1,22 @@
-#ifndef M_VEC2_H
-#define M_VEC2_H
+#ifndef VEC2_H
+#define VEC2_H
 
-#include "Common.h"
+#include "MathCommonIncludes.h"
 
 
-namespace m {
-
+/// @addtogroup Math
+/// @{
 
 /// 2D vector
 class Vec2
 {
 	public:
-		/// @name Constructors & distructors
+		/// @name Constructors
 		/// @{
 		explicit Vec2();
-		explicit Vec2(float x, float y);
-		explicit Vec2(float f);
-		explicit Vec2(float arr[]);
+		explicit Vec2(const float x, const float y);
+		explicit Vec2(const float f);
+		explicit Vec2(const float arr[]);
 		         Vec2(const Vec2& b);
 		explicit Vec2(const Vec3& v3);
 		explicit Vec2(const Vec4& v4);
@@ -28,8 +28,8 @@ class Vec2
 		float x() const;
 		float& y();
 		float y() const;
-		float& operator[](uint i);
-		float operator[](uint i) const;
+		float& operator[](const size_t i);
+		float operator[](const size_t i) const;
 		/// @}
 
 		/// @name Operators with same type
@@ -50,14 +50,14 @@ class Vec2
 
 		/// @name Operators with float
 		/// @{
-		Vec2 operator+(float f) const;
-		Vec2& operator+=(float f);
-		Vec2 operator-(float f) const;
-		Vec2& operator-=(float f);
-		Vec2 operator*(float f) const;
-		Vec2& operator*=(float f);
-		Vec2 operator/(float f) const;
-		Vec2& operator/=(float f);
+		Vec2 operator+(const float f) const;
+		Vec2& operator+=(const float f);
+		Vec2 operator-(const float f) const;
+		Vec2& operator-=(const float f);
+		Vec2 operator*(const float f) const;
+		Vec2& operator*=(const float f);
+		Vec2 operator/(const float f) const;
+		Vec2& operator/=(const float f);
 		/// @}
 
 		/// @name Other
@@ -68,6 +68,14 @@ class Vec2
 		float dot(const Vec2& b) const;
 		/// @}
 
+		/// @name Friends
+		friend Vec2 operator+(const float f, const Vec2& v2);
+		friend Vec2 operator-(const float f, const Vec2& v2);
+		friend Vec2 operator*(const float f, const Vec2& v2);
+		friend Vec2 operator/(const float f, const Vec2& v2);
+		friend std::ostream& operator<<(std::ostream& s, const Vec2& v);
+		///@]
+
 	private:
 		/// @name Data members
 		/// @{
@@ -84,19 +92,6 @@ class Vec2
 };
 
 
-/// @name Other operators
-/// @{
-extern Vec2 operator+(float f, const Vec2& v2);
-extern Vec2 operator-(float f, const Vec2& v2);
-extern Vec2 operator*(float f, const Vec2& v2);
-extern Vec2 operator/(float f, const Vec2& v2);
-extern std::ostream& operator<<(std::ostream& s, const Vec2& v);
-/// @}
-
-
-} // end namespace
-
-
 #include "Vec2.inl.h"
 
 

+ 71 - 36
src/m/Vec2.inl.h

@@ -1,7 +1,4 @@
-#include "Common.inl.h"
-
-
-namespace m {
+#include "MathCommonSrc.h"
 
 
 //==============================================================================
@@ -14,26 +11,30 @@ inline Vec2::Vec2()
 	x() = y() = 0.0;
 }
 
+
 // float
-inline Vec2::Vec2(float f)
+inline Vec2::Vec2(const float f)
 {
 	x() = y() = f;
 }
 
+
 // float, float
-inline Vec2::Vec2(float x_, float y_)
+inline Vec2::Vec2(const float x_, const float y_)
 {
 	x() = x_;
 	y() = y_;
 }
 
+
 // float[]
-inline Vec2::Vec2(float arr[])
+inline Vec2::Vec2(const float arr[])
 {
 	x() = arr[0];
 	y() = arr[1];
 }
 
+
 // Copy
 inline Vec2::Vec2(const Vec2& b)
 {
@@ -41,6 +42,7 @@ inline Vec2::Vec2(const Vec2& b)
 	y() = b.y();
 }
 
+
 // vec3
 inline Vec2::Vec2(const Vec3& v3)
 {
@@ -48,6 +50,7 @@ inline Vec2::Vec2(const Vec3& v3)
 	y() = v3.y();
 }
 
+
 // vec4
 inline Vec2::Vec2(const Vec4& v4)
 {
@@ -65,27 +68,32 @@ inline float& Vec2::x()
 	return vec.x;
 }
 
+
 inline float Vec2::x() const
 {
 	return vec.x;
 }
 
+
 inline float& Vec2::y()
 {
 	return vec.y;
 }
 
+
 inline float Vec2::y() const
 {
 	return vec.y;
 }
 
-inline float& Vec2::operator[](uint i)
+
+inline float& Vec2::operator[](const size_t i)
 {
 	return arr[i];
 }
 
-inline float Vec2::operator[](uint i) const
+
+inline float Vec2::operator[](const size_t i) const
 {
 	return arr[i];
 }
@@ -103,12 +111,14 @@ inline Vec2& Vec2::operator=(const Vec2& b)
 	return *this;
 }
 
+
 // +
 inline Vec2 Vec2::operator+(const Vec2& b) const
 {
 	return Vec2(x() + b.x(), y() + b.y());
 }
 
+
 // +=
 inline Vec2& Vec2::operator+=(const Vec2& b)
 {
@@ -117,12 +127,14 @@ inline Vec2& Vec2::operator+=(const Vec2& b)
 	return (*this);
 }
 
+
 // -
 inline Vec2 Vec2::operator-(const Vec2& b) const
 {
 	return Vec2(x() - b.x(), y() - b.y());
 }
 
+
 // -=
 inline Vec2& Vec2::operator-=(const Vec2& b)
 {
@@ -131,12 +143,14 @@ inline Vec2& Vec2::operator-=(const Vec2& b)
 	return (*this);
 }
 
+
 // *
 inline Vec2 Vec2::operator*(const Vec2& b) const
 {
 	return Vec2(x() * b.x(), y() * b.y());
 }
 
+
 // *=
 inline Vec2& Vec2::operator*=(const Vec2& b)
 {
@@ -145,12 +159,14 @@ inline Vec2& Vec2::operator*=(const Vec2& b)
 	return (*this);
 }
 
+
 // /
 inline Vec2 Vec2::operator/(const Vec2& b) const
 {
 	return Vec2(x() / b.x(), y() / b.y());
 }
 
+
 // /=
 inline Vec2& Vec2::operator/=(const Vec2& b)
 {
@@ -159,22 +175,27 @@ inline Vec2& Vec2::operator/=(const Vec2& b)
 	return (*this);
 }
 
+
 // negative
 inline Vec2 Vec2::operator-() const
 {
 	return Vec2(-x(), -y());
 }
 
+
 // ==
 inline bool Vec2::operator==(const Vec2& b) const
 {
-	return isZero(x() - b.x()) && isZero(y() - b.y());
+	return Math::isZero(x() - b.x()) &&
+		Math::isZero(y() - b.y());
 }
 
+
 // !=
 inline bool Vec2::operator!=(const Vec2& b) const
 {
-	return !(isZero(x() - b.x()) && isZero(y() - b.y()));
+	return !(Math::isZero(x() - b.x()) &&
+		Math::isZero(y() - b.y()));
 }
 
 
@@ -188,11 +209,6 @@ inline Vec2 Vec2::operator+(float f) const
 	return (*this) + Vec2(f);
 }
 
-// float + vec2
-inline Vec2 operator+(float f, const Vec2& v2)
-{
-	return v2 + f;
-}
 
 // vec2 += float
 inline Vec2& Vec2::operator+=(float f)
@@ -201,17 +217,13 @@ inline Vec2& Vec2::operator+=(float f)
 	return (*this);
 }
 
+
 // vec2 - float
 inline Vec2 Vec2::operator-(float f) const
 {
 	return (*this) - Vec2(f);
 }
 
-// float - vec2
-inline Vec2 operator-(float f, const Vec2& v2)
-{
-	return Vec2(f - v2.x(), f - v2.y());
-}
 
 // vec2 -= float
 inline Vec2& Vec2::operator-=(float f)
@@ -220,17 +232,13 @@ inline Vec2& Vec2::operator-=(float f)
 	return (*this);
 }
 
+
 // vec2 * float
 inline Vec2 Vec2::operator*(float f) const
 {
 	return (*this) * Vec2(f);
 }
 
-// float * vec2
-inline Vec2 operator*(float f, const Vec2& v2)
-{
-	return v2 * f;
-}
 
 // vec2 *= float
 inline Vec2& Vec2::operator*=(float f)
@@ -239,17 +247,13 @@ inline Vec2& Vec2::operator*=(float f)
 	return (*this);
 }
 
+
 // vec2 / float
 inline Vec2 Vec2::operator/(float f) const
 {
 	return (*this) / Vec2(f);
 }
 
-// float / vec2
-inline Vec2 operator/(float f, const Vec2& v2)
-{
-	return Vec2(f / v2.x(), f / v2.y());
-}
 
 // vec2 /= float
 inline Vec2& Vec2::operator/=(float f)
@@ -258,6 +262,7 @@ inline Vec2& Vec2::operator/=(float f)
 	return (*this);
 }
 
+
 //==============================================================================
 // Misc methods                                                                =
 //==============================================================================
@@ -265,21 +270,24 @@ inline Vec2& Vec2::operator/=(float f)
 // getLength
 inline float Vec2::getLength() const
 {
-	return m::sqrt(x() * x() + y() * y());
+	return Math::sqrt(x() * x() + y() * y());
 }
 
+
 // normalize
 inline void Vec2::normalize()
 {
 	(*this) /= getLength();
 }
 
+
 // Normalized (return the normalized)
 inline Vec2 Vec2::getNormalized() const
 {
 	return (*this) / getLength();
 }
 
+
 // dot
 inline float Vec2::dot(const Vec2& b) const
 {
@@ -288,13 +296,40 @@ inline float Vec2::dot(const Vec2& b) const
 
 
 //==============================================================================
-// Print                                                                       =
+// Friends                                                                     =
 //==============================================================================
+
+// float + vec2
+inline Vec2 operator+(float f, const Vec2& v2)
+{
+	return v2 + f;
+}
+
+
+// float - vec2
+inline Vec2 operator-(float f, const Vec2& v2)
+{
+	return Vec2(f - v2.x(), f - v2.y());
+}
+
+
+// float * vec2
+inline Vec2 operator*(float f, const Vec2& v2)
+{
+	return v2 * f;
+}
+
+
+// float / vec2
+inline Vec2 operator/(float f, const Vec2& v2)
+{
+	return Vec2(f / v2.x(), f / v2.y());
+}
+
+
+// Print
 inline std::ostream& operator<<(std::ostream& s, const Vec2& v)
 {
 	s << v.x() << ' ' << v.y();
 	return s;
 }
-
-
-} // end namespace

+ 30 - 34
src/m/Vec3.h

@@ -1,23 +1,22 @@
-#ifndef M_VEC3_H
-#define M_VEC3_H
+#ifndef VEC3_H
+#define VEC3_H
 
-#include "Common.h"
-
-
-namespace m {
+#include "MathCommonIncludes.h"
 
+/// @addtogroup Math
+/// @{
 
 /// 3D vector. One of the most used classes
 class Vec3
 {
 	public:
-		/// @name Constructors & distructors
+		/// @name Constructors
 		/// @{
 		explicit Vec3();
-		explicit Vec3(float x, float y, float z);
-		explicit Vec3(float f);
-		explicit Vec3(float arr[]);
-		explicit Vec3(const Vec2& v2, float z);
+		explicit Vec3(const float x, const float y, const float z);
+		explicit Vec3(const float f);
+		explicit Vec3(const float arr[]);
+		explicit Vec3(const Vec2& v2, const float z);
 		         Vec3(const Vec3& b);
 		explicit Vec3(const Vec4& v4);
 		explicit Vec3(const Quat& q);
@@ -31,8 +30,8 @@ class Vec3
 		float y() const;
 		float& z();
 		float z() const;
-		float& operator[](uint i);
-		float operator[](uint i) const;
+		float& operator[](const size_t i);
+		float operator[](const size_t i) const;
 		/// @}
 
 		/// @name Operators with same type
@@ -53,14 +52,14 @@ class Vec3
 
 		/// @name Operators with float
 		/// @{
-		Vec3 operator+(float f) const;
-		Vec3& operator+=(float f);
-		Vec3 operator-(float f) const;
-		Vec3& operator-=(float f);
-		Vec3 operator*(float f) const;
-		Vec3& operator*=(float f);
-		Vec3 operator/(float f) const;
-		Vec3& operator/=(float f);
+		Vec3 operator+(const float f) const;
+		Vec3& operator+=(const float f);
+		Vec3 operator-(const float f) const;
+		Vec3& operator-=(const float f);
+		Vec3 operator*(const float f) const;
+		Vec3& operator*=(const float f);
+		Vec3 operator/(const float f) const;
+		Vec3& operator/=(const float f);
 		/// @}
 
 		/// @name Operators with other types
@@ -68,7 +67,7 @@ class Vec3
 		Vec3 operator*(const Mat3& m3) const;
 		/// @}
 
-		/// @name Misc methods
+		/// @name Other
 		/// @{
 		float dot(const Vec3& b) const;
 		Vec3 cross(const Vec3& b) const;
@@ -105,6 +104,15 @@ class Vec3
 		void transform(const Transform& transform);
 		/// @}
 
+		/// @name Friends
+		/// @{
+		friend Vec3 operator+(const float f, const Vec3& v);
+		friend Vec3 operator-(const float f, const Vec3& v);
+		friend Vec3 operator*(const float f, const Vec3& v);
+		friend Vec3 operator/(const float f, const Vec3& v);
+		friend std::ostream& operator<<(std::ostream& s, const Vec3& v);
+		/// @}
+
 	private:
 		/// @name Data
 		/// @{
@@ -119,21 +127,9 @@ class Vec3
 		};
 		/// @}
 };
-
-
-/// @name Other operators
-/// @{
-extern Vec3 operator+(float f, const Vec3& v);
-extern Vec3 operator-(float f, const Vec3& v);
-extern Vec3 operator*(float f, const Vec3& v);
-extern Vec3 operator/(float f, const Vec3& v);
-extern std::ostream& operator<<(std::ostream& s, const Vec3& v);
 /// @}
 
 
-} // end namespace
-
-
 #include "Vec3.inl.h"
 
 

+ 75 - 39
src/m/Vec3.inl.h

@@ -1,7 +1,4 @@
-#include "Common.inl.h"
-
-
-namespace m {
+#include "MathCommonSrc.h"
 
 
 //==============================================================================
@@ -14,28 +11,32 @@ inline Vec3::Vec3()
 	arr[0] = arr[1] = arr[2] = 0.0;
 }
 
+
 // float, float, float
-inline Vec3::Vec3(float x_, float y_, float z_)
+inline Vec3::Vec3(const float x_, const float y_, const float z_)
 {
 	x() = x_;
 	y() = y_;
 	z() = z_;
 }
 
+
 // float
-inline Vec3::Vec3(float f)
+inline Vec3::Vec3(const float f)
 {
 	arr[0] = arr[1] = arr[2] = f;
 }
 
+
 // float[]
-inline Vec3::Vec3(float arr_[])
+inline Vec3::Vec3(const float arr_[])
 {
 	arr[0] = arr_[0];
 	arr[1] = arr_[1];
 	arr[2] = arr_[2];
 }
 
+
 // Copy
 inline Vec3::Vec3(const Vec3& b)
 {
@@ -44,14 +45,16 @@ inline Vec3::Vec3(const Vec3& b)
 	arr[2] = b.arr[2];
 }
 
+
 // Vec2, float
-inline Vec3::Vec3(const Vec2& v2, float z_)
+inline Vec3::Vec3(const Vec2& v2, const float z_)
 {
 	x() = v2.x();
 	y() = v2.y();
 	z() = z_;
 }
 
+
 // Vec4
 inline Vec3::Vec3(const Vec4& v4)
 {
@@ -60,6 +63,7 @@ inline Vec3::Vec3(const Vec4& v4)
 	arr[2] = v4[2];
 }
 
+
 // Quat
 inline Vec3::Vec3(const Quat& q)
 {
@@ -77,37 +81,44 @@ inline float& Vec3::x()
 	return vec.x;
 }
 
+
 inline float Vec3::x() const
 {
 	return vec.x;
 }
 
+
 inline float& Vec3::y()
 {
 	return vec.y;
 }
 
+
 inline float Vec3::y() const
 {
 	return vec.y;
 }
 
+
 inline float& Vec3::z()
 {
 	return vec.z;
 }
 
+
 inline float Vec3::z() const
 {
 	return vec.z;
 }
 
-inline float& Vec3::operator[](uint i)
+
+inline float& Vec3::operator[](const size_t i)
 {
 	return arr[i];
 }
 
-inline float Vec3::operator[](uint i) const
+
+inline float Vec3::operator[](const size_t i) const
 {
 	return arr[i];
 }
@@ -126,12 +137,14 @@ inline Vec3& Vec3::operator=(const Vec3& b)
 	return (*this);
 }
 
+
 // +
 inline Vec3 Vec3::operator+(const Vec3& b) const
 {
 	return Vec3(x() + b.x(), y() + b.y(), z() + b.z());
 }
 
+
 // +=
 inline Vec3& Vec3::operator+=(const Vec3& b)
 {
@@ -141,12 +154,14 @@ inline Vec3& Vec3::operator+=(const Vec3& b)
 	return (*this);
 }
 
+
 // -
 inline Vec3 Vec3::operator-(const Vec3& b) const
 {
 	return Vec3(x() - b.x(), y() - b.y(), z() - b.z());
 }
 
+
 // -=
 inline Vec3& Vec3::operator-=(const Vec3& b)
 {
@@ -156,12 +171,14 @@ inline Vec3& Vec3::operator-=(const Vec3& b)
 	return (*this);
 }
 
+
 // *
 inline Vec3 Vec3::operator*(const Vec3& b) const
 {
 	return Vec3(x() * b.x(), y() * b.y(), z() * b.z());
 }
 
+
 // *=
 inline Vec3& Vec3::operator*=(const Vec3& b)
 {
@@ -171,12 +188,14 @@ inline Vec3& Vec3::operator*=(const Vec3& b)
 	return (*this);
 }
 
+
 // /
 inline Vec3 Vec3::operator/(const Vec3& b) const
 {
 	return Vec3(x() / b.x(), y() / b.y(), z() / b.z());
 }
 
+
 // /=
 inline Vec3& Vec3::operator/=(const Vec3& b)
 {
@@ -186,22 +205,29 @@ inline Vec3& Vec3::operator/=(const Vec3& b)
 	return (*this);
 }
 
+
 // negative
 inline Vec3 Vec3::operator-() const
 {
 	return Vec3(-x(), -y(), -z());
 }
 
+
 // ==
 inline bool Vec3::operator==(const Vec3& b) const
 {
-	return isZero(x() - b.x()) && isZero(y() - b.y()) && isZero(z() - b.z());
+	return Math::isZero(x() - b.x()) &&
+		Math::isZero(y() - b.y()) &&
+		Math::isZero(z() - b.z());
 }
 
+
 // !=
 inline bool Vec3::operator!=(const Vec3& b) const
 {
-	return !(isZero(x() - b.x()) && isZero(y() - b.y()) && isZero(z() - b.z()));
+	return !(Math::isZero(x() - b.x()) &&
+		Math::isZero(y() - b.y()) &&
+		Math::isZero(z() - b.z()));
 }
 
 
@@ -215,11 +241,6 @@ inline Vec3 Vec3::operator+(float f) const
 	return (*this) + Vec3(f);
 }
 
-// float + Vec3
-inline Vec3 operator+(float f, const Vec3& v)
-{
-	return v + f;
-}
 
 // Vec3 += float
 inline Vec3& Vec3::operator+=(float f)
@@ -228,17 +249,13 @@ inline Vec3& Vec3::operator+=(float f)
 	return (*this);
 }
 
+
 // Vec3 - float
 inline Vec3 Vec3::operator-(float f) const
 {
 	return (*this) - Vec3(f);
 }
 
-// float - Vec3
-inline Vec3 operator-(float f, const Vec3& v)
-{
-	return Vec3(f - v.x(), f - v.y(), f - v.z());
-}
 
 // Vec3 -= float
 inline Vec3& Vec3::operator-=(float f)
@@ -247,17 +264,13 @@ inline Vec3& Vec3::operator-=(float f)
 	return (*this);
 }
 
+
 // Vec3 * float
 inline Vec3 Vec3::operator*(float f) const
 {
 	return (*this) * Vec3(f);
 }
 
-// float * Vec3
-inline Vec3 operator*(float f, const Vec3& v)
-{
-	return v * f;
-}
 
 // Vec3 *= float
 inline Vec3& Vec3::operator*=(float f)
@@ -266,17 +279,13 @@ inline Vec3& Vec3::operator*=(float f)
 	return (*this);
 }
 
+
 // Vec3 / float
 inline Vec3 Vec3::operator/(float f) const
 {
 	return (*this) / Vec3(f);
 }
 
-// float / Vec3
-inline Vec3 operator/(float f, const Vec3& v)
-{
-	return Vec3(f / v.x(), f / v.y(), f / v.z());
-}
 
 // Vec3 /= float
 inline Vec3& Vec3::operator/=(float f)
@@ -287,7 +296,7 @@ inline Vec3& Vec3::operator/=(float f)
 
 
 //==============================================================================
-// Misc methods                                                                =
+// Other                                                                       =
 //==============================================================================
 
 // dot
@@ -307,7 +316,7 @@ inline Vec3 Vec3::cross(const Vec3& b) const
 // getLength
 inline float Vec3::getLength() const
 {
-	return m::sqrt(getLengthSquared());
+	return Math::sqrt(getLengthSquared());
 }
 
 // getLengthSquared
@@ -343,7 +352,7 @@ inline Vec3 Vec3::getProjection(const Vec3& toThis) const
 // getRotated
 inline Vec3 Vec3::getRotated(const Quat& q) const
 {
-	ASSERT(isZero(1.0 - q.getLength())); // Not normalized quat
+	ASSERT(Math::isZero(1.0 - q.getLength())); // Not normalized quat
 
 	/*float vmult = 2.0f*(q.x*x + q.y*y + q.z*z);
 	float crossmult = 2.0*q.w;
@@ -456,13 +465,40 @@ inline void Vec3::transform(const Transform& transform)
 }
 
 //==============================================================================
-// Print                                                                       =
+// Globals                                                                     =
 //==============================================================================
+
+// float + Vec3
+inline Vec3 operator+(const float f, const Vec3& v)
+{
+	return v + f;
+}
+
+
+// float - Vec3
+inline Vec3 operator-(const float f, const Vec3& v)
+{
+	return Vec3(f - v.x(), f - v.y(), f - v.z());
+}
+
+
+// float * Vec3
+inline Vec3 operator*(const float f, const Vec3& v)
+{
+	return v * f;
+}
+
+
+// float / Vec3
+inline Vec3 operator/(const float f, const Vec3& v)
+{
+	return Vec3(f / v.x(), f / v.y(), f / v.z());
+}
+
+
+// Print
 inline std::ostream& operator<<(std::ostream& s, const Vec3& v)
 {
 	s << v.x() << ' ' << v.y() << ' ' << v.z();
 	return s;
 }
-
-
-} // end namespace

+ 30 - 34
src/m/Vec4.h

@@ -1,11 +1,11 @@
-#ifndef M_VEC4_H
-#define M_VEC4_H
+#ifndef VEC4_H
+#define VEC4_H
 
-#include "Common.h"
+#include "MathCommonIncludes.h"
 
 
-namespace m {
-
+/// @addtogroup Math
+/// @{
 
 /// 4D vector
 class Vec4
@@ -14,11 +14,12 @@ class Vec4
 		/// @name Constructors
 		/// @{
 		explicit Vec4();
-		explicit Vec4(float x, float y, float z, float w);
-		explicit Vec4(float f);
-		explicit Vec4(float arr[]);
-		explicit Vec4(const Vec2& v2, float z, float w);
-		explicit Vec4(const Vec3& v3, float w);
+		explicit Vec4(const float x, const float y, const float z,
+			const float w);
+		explicit Vec4(const float f);
+		explicit Vec4(const float arr[]);
+		explicit Vec4(const Vec2& v2, const float z, const float w);
+		explicit Vec4(const Vec3& v3, const float w);
 		         Vec4(const Vec4& b);
 		explicit Vec4(const Quat& q);
 #if defined(MATH_INTEL_SIMD)
@@ -36,8 +37,8 @@ class Vec4
 		float z() const;
 		float& w();
 		float w() const;
-		float& operator[](uint i);
-		float operator[](uint i) const;
+		float& operator[](const size_t i);
+		float operator[](const size_t i) const;
 #if defined(MATH_INTEL_SIMD)
 		__m128& getMm();
 		const __m128& getMm() const;
@@ -62,14 +63,14 @@ class Vec4
 
 		/// @name Operators with float
 		/// @{
-		Vec4 operator+(float f) const;
-		Vec4& operator+=(float f);
-		Vec4 operator-(float f) const;
-		Vec4& operator-=(float f);
-		Vec4 operator*(float f) const;
-		Vec4& operator*=(float f);
-		Vec4 operator/(float f) const;
-		Vec4& operator/=(float f);
+		Vec4 operator+(const float f) const;
+		Vec4& operator+=(const float f);
+		Vec4 operator-(const float f) const;
+		Vec4& operator-=(const float f);
+		Vec4 operator*(const float f) const;
+		Vec4& operator*=(const float f);
+		Vec4 operator/(const float f) const;
+		Vec4& operator/=(const float f);
 		/// @}
 
 		/// @name Operators with other
@@ -85,6 +86,15 @@ class Vec4
 		float dot(const Vec4& b) const;
 		/// @}
 
+		/// @name Friends
+		/// @{
+		friend Vec4 operator+(const float f, const Vec4& v4);
+		friend Vec4 operator-(const float f, const Vec4& v4);
+		friend Vec4 operator*(const float f, const Vec4& v4);
+		friend Vec4 operator/(const float f, const Vec4& v4);
+		friend std::ostream& operator<<(std::ostream& s, const Vec4& v);
+		/// @}
+
 	private:
 		/// @name Data
 		/// @{
@@ -103,23 +113,9 @@ class Vec4
 		};
 		/// @}
 };
-
-
-/// @name Global operators with Vec4 and float
-/// @{
-extern Vec4 operator+(float f, const Vec4& v4);
-extern Vec4 operator-(float f, const Vec4& v4);
-extern Vec4 operator*(float f, const Vec4& v4);
-extern Vec4 operator/(float f, const Vec4& v4);
 /// @}
 
 
-extern std::ostream& operator<<(std::ostream& s, const Vec4& v);
-
-
-} // end namespace
-
-
 #include "Vec4.inl.h"
 
 

+ 92 - 47
src/m/Vec4.inl.h

@@ -1,7 +1,4 @@
-#include "Common.inl.h"
-
-
-namespace m {
+#include "MathCommonSrc.h"
 
 
 //==============================================================================
@@ -18,6 +15,7 @@ inline Vec4::Vec4()
 #endif
 }
 
+
 // float
 inline Vec4::Vec4(float f)
 {
@@ -28,8 +26,9 @@ inline Vec4::Vec4(float f)
 #endif
 }
 
+
 // float[]
-inline Vec4::Vec4(float arr_[])
+inline Vec4::Vec4(const float arr_[])
 {
 #if defined(MATH_INTEL_SIMD)
 	mm = _mm_load_ps(arr_);
@@ -41,8 +40,10 @@ inline Vec4::Vec4(float arr_[])
 #endif
 }
 
+
 // float, float, float, float
-inline Vec4::Vec4(float x_, float y_, float z_, float w_)
+inline Vec4::Vec4(const float x_, const float y_, const float z_,
+	const float w_)
 {
 #if defined(MATH_INTEL_SIMD)
 	mm = _mm_set_ps(w_, z_, y_, x_);
@@ -54,8 +55,9 @@ inline Vec4::Vec4(float x_, float y_, float z_, float w_)
 #endif
 }
 
+
 // vec2, float, float
-inline Vec4::Vec4(const Vec2& v2, float z_, float w_)
+inline Vec4::Vec4(const Vec2& v2, const float z_, const float w_)
 {
 	x() = v2.x();
 	y() = v2.y();
@@ -63,8 +65,9 @@ inline Vec4::Vec4(const Vec2& v2, float z_, float w_)
 	w() = w_;
 }
 
+
 // vec3, float
-inline Vec4::Vec4(const Vec3& v3, float w_)
+inline Vec4::Vec4(const Vec3& v3, const float w_)
 {
 	x() = v3.x();
 	y() = v3.y();
@@ -72,6 +75,7 @@ inline Vec4::Vec4(const Vec3& v3, float w_)
 	w() = w_;
 }
 
+
 // Copy
 inline Vec4::Vec4(const Vec4& b)
 {
@@ -85,6 +89,7 @@ inline Vec4::Vec4(const Vec4& b)
 #endif
 }
 
+
 // quat
 inline Vec4::Vec4(const Quat& q)
 {
@@ -94,6 +99,7 @@ inline Vec4::Vec4(const Quat& q)
 	w() = q.w();
 }
 
+
 // __m128
 #if defined(MATH_INTEL_SIMD)
 inline Vec4::Vec4(const __m128& mm_)
@@ -107,62 +113,73 @@ inline Vec4::Vec4(const __m128& mm_)
 // Accessors                                                                   =
 //==============================================================================
 
-inline float& Vec4::operator[](uint i)
+inline float& Vec4::operator[](const size_t i)
 {
 	return arr[i];
 }
 
-inline float Vec4::operator[](uint i) const
+
+inline float Vec4::operator[](const size_t i) const
 {
 	return arr[i];
 }
 
+
 inline float& Vec4::x()
 {
 	return vec.x;
 }
 
+
 inline float Vec4::x() const
 {
 	return vec.x;
 }
 
+
 inline float& Vec4::y()
 {
 	return vec.y;
 }
 
+
 inline float Vec4::y() const
 {
 	return vec.y;
 }
 
+
 inline float& Vec4::z()
 {
 	return vec.z;
 }
 
+
 inline float Vec4::z() const
 {
 	return vec.z;
 }
 
+
 inline float& Vec4::w()
 {
 	return vec.w;
 }
 
+
 inline float Vec4::w() const
 {
 	return vec.w;
 }
 
+
 #if defined(MATH_INTEL_SIMD)
 inline __m128& Vec4::getMm()
 {
 	return mm;
 }
 
+
 inline const __m128& Vec4::getMm() const
 {
 	return mm;
@@ -188,6 +205,7 @@ inline Vec4& Vec4::operator=(const Vec4& b)
 	return (*this);
 }
 
+
 // +
 inline Vec4 Vec4::operator+(const Vec4& b) const
 {
@@ -198,6 +216,7 @@ inline Vec4 Vec4::operator+(const Vec4& b) const
 #endif
 }
 
+
 // +=
 inline Vec4& Vec4::operator+=(const Vec4& b)
 {
@@ -212,6 +231,7 @@ inline Vec4& Vec4::operator+=(const Vec4& b)
 	return (*this);
 }
 
+
 // -
 inline Vec4 Vec4::operator-(const Vec4& b) const
 {
@@ -222,6 +242,7 @@ inline Vec4 Vec4::operator-(const Vec4& b) const
 #endif
 }
 
+
 // -=
 inline Vec4& Vec4::operator-=(const Vec4& b)
 {
@@ -236,6 +257,7 @@ inline Vec4& Vec4::operator-=(const Vec4& b)
 	return (*this);
 }
 
+
 // *
 inline Vec4 Vec4::operator*(const Vec4& b) const
 {
@@ -246,6 +268,7 @@ inline Vec4 Vec4::operator*(const Vec4& b) const
 #endif
 }
 
+
 // *=
 inline Vec4& Vec4::operator*=(const Vec4& b)
 {
@@ -260,6 +283,7 @@ inline Vec4& Vec4::operator*=(const Vec4& b)
 	return (*this);
 }
 
+
 // /
 inline Vec4 Vec4::operator/(const Vec4& b) const
 {
@@ -270,6 +294,7 @@ inline Vec4 Vec4::operator/(const Vec4& b) const
 #endif
 }
 
+
 // /=
 inline Vec4& Vec4::operator/=(const Vec4& b)
 {
@@ -284,26 +309,33 @@ inline Vec4& Vec4::operator/=(const Vec4& b)
 	return (*this);
 }
 
+
 // negative
 inline Vec4 Vec4::operator-() const
 {
 	return Vec4(-x(), -y(), -z(), -w());
 }
 
+
 // ==
 inline bool Vec4::operator==(const Vec4& b) const
 {
 	Vec4 sub = (*this) - b;
-	return isZero(sub.x()) && isZero(sub.y()) && isZero(sub.z()) &&
-		isZero(sub.w());
+	return Math::isZero(sub.x()) &&
+		Math::isZero(sub.y()) &&
+		Math::isZero(sub.z()) &&
+		Math::isZero(sub.w());
 }
 
+
 // !=
 inline bool Vec4::operator!=(const Vec4& b) const
 {
 	Vec4 sub = (*this) - b;
-	return !(isZero(sub.x()) && isZero(sub.y()) && isZero(sub.z()) &&
-		isZero(sub.w()));
+	return !(Math::isZero(sub.x()) &&
+		Math::isZero(sub.y()) &&
+		Math::isZero(sub.z()) &&
+		Math::isZero(sub.w()));
 }
 
 
@@ -312,76 +344,59 @@ inline bool Vec4::operator!=(const Vec4& b) const
 //==============================================================================
 
 // Vec4 + float
-inline Vec4 Vec4::operator+(float f) const
+inline Vec4 Vec4::operator+(const float f) const
 {
 	return (*this) + Vec4(f);
 }
 
-// float + Vec4
-inline Vec4 operator+(float f, const Vec4& v4)
-{
-	return v4 + f;
-}
 
 // Vec4 += float
-inline Vec4& Vec4::operator+=(float f)
+inline Vec4& Vec4::operator+=(const float f)
 {
 	(*this) += Vec4(f);
 	return (*this);
 }
 
+
 // Vec4 - float
-inline Vec4 Vec4::operator-(float f) const
+inline Vec4 Vec4::operator-(const float f) const
 {
 	return (*this) - Vec4(f);
 }
 
-// float - Vec4
-inline Vec4 operator-(float f, const Vec4& v4)
-{
-	return Vec4(f) - v4;
-}
 
 // Vec4 -= float
-inline Vec4& Vec4::operator-=(float f)
+inline Vec4& Vec4::operator-=(const float f)
 {
 	(*this) -= Vec4(f);
 	return (*this);
 }
 
+
 // Vec4 * float
-inline Vec4 Vec4::operator*(float f) const
+inline Vec4 Vec4::operator*(const float f) const
 {
 	return (*this) * Vec4(f);
 }
 
-// float * Vec4
-inline Vec4 operator*(float f, const Vec4& v4)
-{
-	return v4 * f;
-}
 
 // Vec4 *= float
-inline Vec4& Vec4::operator*=(float f)
+inline Vec4& Vec4::operator*=(const float f)
 {
 	(*this) *= Vec4(f);
 	return (*this);
 }
 
+
 // Vec4 / float
-inline Vec4 Vec4::operator/(float f) const
+inline Vec4 Vec4::operator/(const float f) const
 {
 	return (*this) / Vec4(f);
 }
 
-// float / Vec4
-inline Vec4 operator/(float f, const Vec4& v4)
-{
-	return Vec4(f) / v4;
-}
 
 // Vec4 /= float
-inline Vec4& Vec4::operator/=(float f)
+inline Vec4& Vec4::operator/=(const float f)
 {
 	(*this) /= Vec4(f);
 	return (*this);
@@ -420,18 +435,21 @@ inline float Vec4::dot(const Vec4& b) const
 #endif
 }
 
+
 // getLength
 inline float Vec4::getLength() const
 {
-	return m::sqrt(dot((*this)));
+	return Math::sqrt(dot((*this)));
 }
 
+
 // getNormalized
 inline Vec4 Vec4::getNormalized() const
 {
 	return (*this) / getLength();
 }
 
+
 // normalize
 inline void Vec4::normalize()
 {
@@ -440,13 +458,40 @@ inline void Vec4::normalize()
 
 
 //==============================================================================
-// Print                                                                       =
+// Friends                                                                     =
 //==============================================================================
+
+// float + Vec4
+inline Vec4 operator+(const float f, const Vec4& v4)
+{
+	return v4 + f;
+}
+
+
+// float - Vec4
+inline Vec4 operator-(const float f, const Vec4& v4)
+{
+	return Vec4(f) - v4;
+}
+
+
+// float * Vec4
+inline Vec4 operator*(const float f, const Vec4& v4)
+{
+	return v4 * f;
+}
+
+
+// float / Vec4
+inline Vec4 operator/(const float f, const Vec4& v4)
+{
+	return Vec4(f) / v4;
+}
+
+
+// Print
 inline std::ostream& operator<<(std::ostream& s, const Vec4& v)
 {
 	s << v.x() << ' ' << v.y() << ' ' << v.z() << ' ' << v.w();
 	return s;
 }
-
-
-} // end namespace

+ 1 - 1
src/misc/TestHeader.cpp

@@ -1,4 +1,4 @@
-#include "m/Math.h"
+#include "m/Vec2.h"
 
 
 

+ 3 - 9
src/phys/Character.cpp

@@ -4,13 +4,10 @@
 #include <BulletCollision/CollisionDispatch/btGhostObject.h>
 #include <BulletDynamics/Character/btKinematicCharacterController.h>
 #include "Character.h"
-#include "MasterContainer.h"
+#include "PhysWorld.h"
 #include "MotionState.h"
 #include "RigidBody.h"
-#include "MasterContainer.h"
-
-
-namespace phys {
+#include "PhysWorld.h"
 
 
 //==============================================================================
@@ -30,7 +27,7 @@ inline Character::Initializer::Initializer():
 //==============================================================================
 // Contructor                                                                  =
 //==============================================================================
-Character::Character(MasterContainer& masterContainer_,
+Character::Character(PhysWorld& masterContainer_,
 	const Initializer& init)
 :	masterContainer(masterContainer_)
 {
@@ -118,6 +115,3 @@ void Character::jump()
 {
 	character->jump();
 }
-
-
-} // end namespace

+ 6 - 14
src/phys/Character.h

@@ -1,5 +1,5 @@
-#ifndef PHYS_CHARACTER_H
-#define PHYS_CHARACTER_H
+#ifndef CHARACTER_H
+#define CHARACTER_H
 
 #include "m/Math.h"
 #include "core/Object.h"
@@ -10,19 +10,14 @@ class btConvexShape;
 class btKinematicCharacterController;
 class btGhostPairCallback;
 class SceneNode;
-
-
-namespace phys {
-
-
-class MasterContainer;
+class PhysWorld;
 class MotionState;
 
 
 /// Its basically a wrapper around bullet character
 class Character
 {
-	friend class MasterContainer;
+	friend class PhysWorld;
 
 	public:
 		/// Initializer class
@@ -39,14 +34,14 @@ class Character
 			Initializer();
 		};
 
-		Character(MasterContainer& masterContainer, const Initializer& init);
+		Character(PhysWorld& masterContainer, const Initializer& init);
 		~Character();
 		void rotate(float angle);
 		void moveForward(float distance);
 		void jump();
 
 	private:
-		MasterContainer& masterContainer; ///< Know your father
+		PhysWorld& masterContainer; ///< Know your father
 		btPairCachingGhostObject* ghostObject;
 		btConvexShape* convexShape;
 		btKinematicCharacterController* character;
@@ -55,7 +50,4 @@ class Character
 };
 
 
-} // end namespace
-
-
 #endif

+ 2 - 2
src/phys/Convertors.h

@@ -1,5 +1,5 @@
-#ifndef PHYS_CONVERTORS_H
-#define PHYS_CONVERTORS_H
+#ifndef CONVERTORS_H
+#define CONVERTORS_H
 
 #include <btBulletCollisionCommon.h>
 #include <btBulletDynamicsCommon.h>

+ 2 - 8
src/phys/MotionState.h

@@ -1,13 +1,10 @@
-#ifndef PHYS_MOTION_STATE_H
-#define PHYS_MOTION_STATE_H
+#ifndef MOTION_STATE_H
+#define MOTION_STATE_H
 
 #include <LinearMath/btMotionState.h>
 #include "scene/SceneNode.h"
 
 
-namespace phys {
-
-
 /// A custom motion state
 class MotionState: public btMotionState
 {
@@ -61,7 +58,4 @@ inline void MotionState::setWorldTransform(const btTransform& worldTrans)
 }
 
 
-} // end namespace
-
-
 #endif

+ 5 - 11
src/phys/MasterContainer.cpp → src/phys/PhysWorld.cpp

@@ -1,16 +1,13 @@
 #include <BulletCollision/CollisionDispatch/btGhostObject.h>
-#include "MasterContainer.h"
+#include "PhysWorld.h"
 #include "Character.h"
 #include "MotionState.h"
 
 
-namespace phys {
-
-
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
-MasterContainer::MasterContainer():
+PhysWorld::PhysWorld():
 	defaultContactProcessingThreshold(BT_LARGE_FLOAT)
 {
 	collisionConfiguration = new btDefaultCollisionConfiguration();
@@ -27,7 +24,7 @@ MasterContainer::MasterContainer():
 //==============================================================================
 // Destructor                                                                  =
 //==============================================================================
-MasterContainer::~MasterContainer()
+PhysWorld::~PhysWorld()
 {
 	/// @todo
 }
@@ -36,7 +33,7 @@ MasterContainer::~MasterContainer()
 //==============================================================================
 // setDebugDrawer                                                              =
 //==============================================================================
-void MasterContainer::setDebugDrawer(btIDebugDraw* newDebugDrawer)
+void PhysWorld::setDebugDrawer(btIDebugDraw* newDebugDrawer)
 {
 	debugDrawer.reset(newDebugDrawer);
 	dynamicsWorld->setDebugDrawer(debugDrawer.get());
@@ -47,7 +44,7 @@ void MasterContainer::setDebugDrawer(btIDebugDraw* newDebugDrawer)
 //==============================================================================
 // update                                                                      =
 //==============================================================================
-void MasterContainer::update(float prevUpdateTime, float crntTime)
+void PhysWorld::update(float prevUpdateTime, float crntTime)
 {
 	dynamicsWorld->stepSimulation(crntTime - prevUpdateTime);
 
@@ -58,6 +55,3 @@ void MasterContainer::update(float prevUpdateTime, float crntTime)
 			characters[i]->ghostObject->getWorldTransform());
 	}
 }
-
-
-} // end namespace

+ 5 - 12
src/phys/MasterContainer.h → src/phys/PhysWorld.h

@@ -1,5 +1,5 @@
-#ifndef PHYS_MASTER_CONTAINER_H
-#define PHYS_MASTER_CONTAINER_H
+#ifndef PHYS_WORLD_H
+#define PHYS_WORLD_H
 
 #include "Convertors.h"
 #include "util/Vec.h"
@@ -9,17 +9,12 @@
 
 
 class btIDebugDraw;
-namespace phys {
 class Character;
 class RigidBody;
-}
-
-
-namespace phys {
 
 
 /// The master container for all physics related stuff.
-class MasterContainer
+class PhysWorld
 {
 	friend class Character; ///< For registering and unregistering
 	friend class RigidBody;  ///< For registering and unregistering
@@ -35,8 +30,8 @@ class MasterContainer
 		};
 
 	public:
-		MasterContainer();
-		~MasterContainer();
+		PhysWorld();
+		~PhysWorld();
 
 		/// @name Accessors
 		/// @{
@@ -62,6 +57,4 @@ class MasterContainer
 };
 
 
-} // end namespace
-
 #endif

+ 2 - 8
src/phys/RigidBody.cpp

@@ -1,12 +1,9 @@
 #include "RigidBody.h"
-#include "MasterContainer.h"
+#include "PhysWorld.h"
 #include "scene/Scene.h"
 #include "MotionState.h"
 
 
-namespace phys {
-
-
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
@@ -23,7 +20,7 @@ RigidBody::Initializer::Initializer():
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
-RigidBody::RigidBody(MasterContainer& masterContainer_,
+RigidBody::RigidBody(PhysWorld& masterContainer_,
 	const Initializer& init)
 :	btRigidBody(btRigidBody::btRigidBodyConstructionInfo(0.0, NULL, NULL,
 		btVector3(0.0, 0.0, 0.0))), // dummy init
@@ -76,6 +73,3 @@ RigidBody::~RigidBody()
 {
 	masterContainer.dynamicsWorld->removeRigidBody(this);
 }
-
-
-} // end namespace

+ 5 - 13
src/phys/RigidBody.h

@@ -1,5 +1,5 @@
-#ifndef PHYS_RIGID_BODY_H
-#define PHYS_RIGID_BODY_H
+#ifndef RIGID_BODY_H
+#define RIGID_BODY_H
 
 #include <boost/scoped_ptr.hpp>
 #include <btBulletDynamicsCommon.h>
@@ -8,13 +8,8 @@
 
 
 class SceneNode;
-namespace phys {
 class MotionState;
-class MasterContainer;
-}
-
-
-namespace phys {
+class PhysWorld;
 
 
 /// Wrapper for rigid body
@@ -35,19 +30,16 @@ class RigidBody: public btRigidBody
 		};
 
 		/// Init and register
-		RigidBody(MasterContainer& masterContainer, const Initializer& init);
+		RigidBody(PhysWorld& masterContainer, const Initializer& init);
 
 		/// Unregister
 		~RigidBody();
 
 	private:
-		MasterContainer& masterContainer; ///< Know your father
+		PhysWorld& masterContainer; ///< Know your father
 		/// Keep it here for garbage collection
 		boost::scoped_ptr<MotionState> motionState;
 };
 
 
-} // end namespace
-
-
 #endif

+ 1 - 1
src/r/CollisionDbgDrawer.cpp

@@ -54,7 +54,7 @@ void CollisionDbgDrawer::draw(const Plane& plane)
 	Quat q;
 	q.setFrom2Vec3(Vec3(0.0, 0.0, 1.0), n);
 	Mat3 rot(q);
-	rot.rotateXAxis(m::PI / 2);
+	rot.rotateXAxis(Math::PI / 2);
 	Mat4 trf(n * o, rot);
 
 	dbg.setModelMat(trf);

+ 5 - 5
src/r/Dbg.cpp

@@ -110,14 +110,14 @@ void Dbg::drawSphere(float radius, int complexity)
 		complexityToPreCalculatedSphere[complexity] = Vec<Vec3>();
 		sphereLines = &complexityToPreCalculatedSphere[complexity];
 
-		float fi = m::PI / complexity;
+		float fi = Math::PI / complexity;
 
 		Vec3 prev(1.0, 0.0, 0.0);
-		for(float th = fi; th < m::PI * 2.0 + fi; th += fi)
+		for(float th = fi; th < Math::PI * 2.0 + fi; th += fi)
 		{
 			Vec3 p = Mat3(Euler(0.0, th, 0.0)) * Vec3(1.0, 0.0, 0.0);
 
-			for(float th2 = 0.0; th2 < m::PI; th2 += fi)
+			for(float th2 = 0.0; th2 < Math::PI; th2 += fi)
 			{
 				Mat3 rot(Euler(th2, 0.0, 0.0));
 
@@ -127,7 +127,7 @@ void Dbg::drawSphere(float radius, int complexity)
 				sphereLines->push_back(rotPrev);
 				sphereLines->push_back(rotP);
 
-				Mat3 rot2(Euler(0.0, 0.0, m::PI / 2));
+				Mat3 rot2(Euler(0.0, 0.0, Math::PI / 2));
 
 				sphereLines->push_back(rot2 * rotPrev);
 				sphereLines->push_back(rot2 * rotP);
@@ -359,7 +359,7 @@ void Dbg::run()
 	///////////////
 
 
-	SceneSingleton::get().getPhysMasterContainer().getWorld().
+	SceneSingleton::get().getPhysPhysWorld().getWorld().
 		debugDrawWorld();
 	// Physics
 	/*glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

+ 1 - 1
src/r/SceneDbgDrawer.cpp

@@ -47,7 +47,7 @@ void SceneDbgDrawer::drawPerspectiveCamera(const PerspectiveCamera& cam) const
 	dbg.setModelMat(Mat4(cam.getWorldTransform()));
 
 	const float camLen = 1.0;
-	float tmp0 = camLen / tan((m::PI - cam.getFovX()) * 0.5) + 0.001;
+	float tmp0 = camLen / tan((Math::PI - cam.getFovX()) * 0.5) + 0.001;
 	float tmp1 = camLen * tan(cam.getFovY() * 0.5) + 0.001;
 
 	Vec3 points[] = {

+ 1 - 1
src/rsrc/LightRsrc.cpp

@@ -19,7 +19,7 @@ LightRsrc::LightRsrc()
 	castsShadowFlag = false;
 	radius = 1.0;
 	distance = 3.0;
-	fovX = fovY = m::PI / 4.0;
+	fovX = fovY = Math::PI / 4.0;
 	width = height = 1.0;
 	spotLightCameraType = SLCT_PERSPECTIVE;
 }

+ 1 - 1
src/rsrc/MeshData.cpp

@@ -248,7 +248,7 @@ void MeshData::createVertTangents()
 
 		float det = (uvedge01.y() * uvedge02.x()) -
 			(uvedge01.x() * uvedge02.y());
-		if(isZero(det))
+		if(Math::isZero(det))
 		{
 			//WARNING(getRsrcName() << ": det == " << fixed << det);
 			det = 0.0001;

+ 1 - 0
src/rsrc/MeshData.h

@@ -5,6 +5,7 @@
 #include <boost/array.hpp>
 #include "m/Math.h"
 #include "util/StdTypes.h"
+#include "util/Accessors.h"
 #include "util/Vec.h"
 
 

+ 3 - 3
src/rsrc/ParticleEmitterRsrc.cpp

@@ -71,8 +71,8 @@ ParticleEmitterRsrc& ParticleEmitterRsrc::operator=(
 //==============================================================================
 bool ParticleEmitterRsrc::hasForce() const
 {
-	return (!m::isZero(forceDirection.getLengthSquared()) ||
-		!m::isZero(forceDirectionDeviation.getLengthSquared())) &&
+	return (!Math::isZero(forceDirection.getLengthSquared()) ||
+		!Math::isZero(forceDirectionDeviation.getLengthSquared())) &&
 			(forceMagnitude != 0.0 || forceMagnitudeDeviation != 0.0);
 }
 
@@ -82,7 +82,7 @@ bool ParticleEmitterRsrc::hasForce() const
 //==============================================================================
 bool ParticleEmitterRsrc::usingWorldGrav() const
 {
-	return m::isZero(gravity.getLengthSquared());
+	return Math::isZero(gravity.getLengthSquared());
 }
 
 

+ 2 - 2
src/rsrc/ShaderProgramPrePreprocessor.h

@@ -44,8 +44,8 @@ class ShaderProgramPrePreprocessor
 		/// @name Accessors
 		/// @{
 		GETTER_R(Vec<std::string>, trffbVaryings, getTranformFeedbackVaryings)
-		const std::string& getShaderSource(ShaderType type) {
-			return output.shaderSources[type];}
+		const std::string& getShaderSource(ShaderType type)
+			{return output.shaderSources[type];}
 		/// @}
 
 	protected:

+ 1 - 1
src/scene/Particle.cpp

@@ -21,7 +21,7 @@ Particle::~Particle()
 //==============================================================================
 // setNewRigidBody                                                             =
 //==============================================================================
-void Particle::setNewRigidBody(phys::RigidBody* body_)
+void Particle::setNewRigidBody(RigidBody* body_)
 {
 	body.reset(body_);
 }

+ 4 - 6
src/scene/Particle.h

@@ -5,9 +5,7 @@
 #include "ModelNode.h"
 
 
-namespace phys {
 class RigidBody;
-}
 
 
 /// The scene node particle class
@@ -19,13 +17,13 @@ class Particle: public ModelNode
 
 		GETTER_SETTER(float, timeOfDeath, getTimeOfDeath, setTimeOfDeath)
 		bool isDead() const {return timeOfDeath < 0.0;}
-		void setNewRigidBody(phys::RigidBody* body_);
-		phys::RigidBody& getRigidBody() {return *body;}
-		const phys::RigidBody& getRigidBody() const {return *body;}
+		void setNewRigidBody(RigidBody* body_);
+		RigidBody& getRigidBody() {return *body;}
+		const RigidBody& getRigidBody() const {return *body;}
 
 	private:
 		float timeOfDeath; ///< Life of death. If < 0.0 then dead. In seconds
-		boost::scoped_ptr<phys::RigidBody> body; ///< For garbage collection
+		boost::scoped_ptr<RigidBody> body; ///< For garbage collection
 };
 
 

+ 7 - 7
src/scene/ParticleEmitterNode.cpp

@@ -80,17 +80,17 @@ void ParticleEmitterNode::init(const char* filename)
 			util::randFloat(particleMassDeviation) * 2.0 -
 			particleMassDeviation;
 
-		phys::RigidBody::Initializer init;
+		RigidBody::Initializer init;
 		init.mass = mass;
 		init.startTrf = toAnki(startingTrf);
 		init.shape = collShape.get();
 		init.sceneNode = particle;
-		init.group = phys::MasterContainer::CG_PARTICLE;
-		init.mask = phys::MasterContainer::CG_ALL ^
-			phys::MasterContainer::CG_PARTICLE;
+		init.group = PhysWorld::CG_PARTICLE;
+		init.mask = PhysWorld::CG_ALL ^
+			PhysWorld::CG_PARTICLE;
 
-		phys::RigidBody* body = new phys::RigidBody(
-			SceneSingleton::get().getPhysMasterContainer(), init);
+		RigidBody* body = new RigidBody(
+			SceneSingleton::get().getPhysPhysWorld(), init);
 
 		body->forceActivationState(DISABLE_SIMULATION);
 
@@ -144,7 +144,7 @@ void ParticleEmitterNode::frameUpdate(float prevUpdateTime, float crntTime)
 				continue;
 			}
 
-			phys::RigidBody& body = p.getRigidBody();
+			RigidBody& body = p.getRigidBody();
 
 			p.enableFlag(SceneNode::SNF_ACTIVE);
 

+ 3 - 3
src/scene/PerspectiveCamera.cpp

@@ -51,13 +51,13 @@ void PerspectiveCamera::calcLSpaceFrustumPlanes()
 {
 	float c, s; // cos & sine
 
-	sinCos(PI + fovX / 2, s, c);
+	Math::sinCos(Math::PI + fovX / 2, s, c);
 	// right
 	lspaceFrustumPlanes[FP_RIGHT] = Plane(Vec3(c, 0.0, s), 0.0);
 	// left
 	lspaceFrustumPlanes[FP_LEFT] = Plane(Vec3(-c, 0.0, s), 0.0);
 
-	sinCos((3 * PI - fovY) * 0.5, s, c);
+	Math::sinCos((3 * Math::PI - fovY) * 0.5, s, c);
 	// top
 	lspaceFrustumPlanes[FP_TOP] = Plane(Vec3(0.0, s, c), 0.0);
 	// bottom
@@ -75,7 +75,7 @@ void PerspectiveCamera::calcLSpaceFrustumPlanes()
 //==============================================================================
 void PerspectiveCamera::getExtremePoints(Vec3* points, uint& pointsNum) const
 {
-	float x = getZFar() / tan((PI - getFovX()) / 2.0);
+	float x = getZFar() / tan((Math::PI - getFovX()) / 2.0);
 	float y = tan(getFovY() / 2.0) * getZFar();
 	float z = -getZFar();
 

+ 1 - 1
src/scene/Scene.cpp

@@ -22,7 +22,7 @@ Scene::Scene()
 	ambientCol = Vec3(0.1, 0.05, 0.05) * 4;
 	//sunPos = Vec3(0.0, 1.0, -1.0) * 50.0;
 
-	physMasterContainer.reset(new phys::MasterContainer);
+	physPhysWorld.reset(new PhysWorld);
 	visibilityTester.reset(new VisibilityTester(*this));
 }
 

+ 8 - 8
src/scene/Scene.h

@@ -2,7 +2,7 @@
 #define SCENE_H
 
 #include <boost/scoped_ptr.hpp>
-#include "phys/MasterContainer.h"
+#include "phys/PhysWorld.h"
 #include "util/Assert.h"
 #include "util/Accessors.h"
 #include "VisibilityTester.h"
@@ -52,8 +52,8 @@ class Scene
 		/// @name Accessors
 		/// @{
 		GETTER_SETTER(Vec3, ambientCol, getAmbientColor, setAmbientColor)
-		phys::MasterContainer& getPhysMasterContainer();
-		const phys::MasterContainer& getPhysMasterContainer() const;
+		PhysWorld& getPhysPhysWorld();
+		const PhysWorld& getPhysPhysWorld() const;
 		const VisibilityTester& getVisibilityTester() const;
 
 		GETTER_RW(Types<SceneNode>::Container, nodes, getAllNodes)
@@ -80,7 +80,7 @@ class Scene
 
 		Vec3 ambientCol; ///< The global ambient color
 		/// Connection with Bullet wrapper
-		boost::scoped_ptr<phys::MasterContainer> physMasterContainer;
+		boost::scoped_ptr<PhysWorld> physPhysWorld;
 		boost::scoped_ptr<VisibilityTester> visibilityTester;
 
 		/// Adds a node in a container
@@ -111,15 +111,15 @@ inline void Scene::eraseNode(ContainerType& container, Type* x)
 }
 
 
-inline phys::MasterContainer& Scene::getPhysMasterContainer()
+inline PhysWorld& Scene::getPhysPhysWorld()
 {
-	return *physMasterContainer;
+	return *physPhysWorld;
 }
 
 
-inline const phys::MasterContainer& Scene::getPhysMasterContainer() const
+inline const PhysWorld& Scene::getPhysPhysWorld() const
 {
-	return *physMasterContainer;
+	return *physPhysWorld;
 }
 
 

+ 5 - 3
src/scene/SkinNode.cpp

@@ -176,11 +176,13 @@ void SkinNode::updateBoneTransforms(const Skeleton& skeleton,
 		// bone.final_transform = MA * ANIM * MAi
 		// where MA is bone matrix at armature space and ANIM the interpolated
 		// transformation.
-		combineTransformations(boneTranslations[boneId], boneRotations[boneId],
+		Math::combineTransformations(
+			boneTranslations[boneId], boneRotations[boneId],
 			boned.getTslSkelSpaceInv(), boned.getRotSkelSpaceInv(),
 			boneTranslations[boneId], boneRotations[boneId]);
 
-		combineTransformations(boned.getTslSkelSpace(), boned.getRotSkelSpace(),
+		Math::combineTransformations(
+			boned.getTslSkelSpace(), boned.getRotSkelSpace(),
 			boneTranslations[boneId], boneRotations[boneId],
 			boneTranslations[boneId], boneRotations[boneId]);
 
@@ -188,7 +190,7 @@ void SkinNode::updateBoneTransforms(const Skeleton& skeleton,
 		if(boned.getParent())
 		{
 			// bone.final_final_transform = parent.transf * bone.final_transform
-			combineTransformations(
+			Math::combineTransformations(
 				boneTranslations[boned.getParent()->getPos()],
 				boneRotations[boned.getParent()->getPos()],
 				boneTranslations[boneId],

+ 13 - 19
src/ui/Font.cpp → src/ui/UiFont.cpp

@@ -1,23 +1,20 @@
-#include "Font.h"
+#include "UiFont.h"
 #include "rsrc/Texture.h"
 #include "util/Exception.h"
 #include "util/Assert.h"
-#include "FtFontLoader.h"
+#include "UiFtFontLoader.h"
 #include <GL/glew.h>
 #include <boost/foreach.hpp>
 
 
-namespace ui {
-
-
 //==============================================================================
 // create                                                                      =
 //==============================================================================
-void Font::create(const char* fontFilename, uint nominalWidth,
+void UiFont::create(const char* fontFilename, uint nominalWidth,
 	uint NominalHeight)
 {
 	FT_Vector ftSize = {nominalWidth, NominalHeight};
-	FtFontLoader ft(fontFilename, ftSize);
+	UiFtFontLoader ft(fontFilename, ftSize);
 
 	lineHeight = ft.getLineHeight();
 
@@ -25,20 +22,20 @@ void Font::create(const char* fontFilename, uint nominalWidth,
 
 	// - Create glyphs
 	// - Get metrics
-	BOOST_FOREACH(const FtFontLoader::Glyph& ftGlyph, ft.getGlyphs())
+	BOOST_FOREACH(const UiFtFontLoader::Glyph& ftGlyph, ft.getGlyphs())
 	{
 		// Create
 		glyphs.push_back(new Glyph);
 		Glyph& glyph = glyphs.back();
 
 		// Metrics
-		glyph.width = FtFontLoader::toPixels(ftGlyph.getMetrics().width);
-		glyph.height = FtFontLoader::toPixels(ftGlyph.getMetrics().height);
-		glyph.horizBearingX = FtFontLoader::toPixels(
+		glyph.width = UiFtFontLoader::toPixels(ftGlyph.getMetrics().width);
+		glyph.height = UiFtFontLoader::toPixels(ftGlyph.getMetrics().height);
+		glyph.horizBearingX = UiFtFontLoader::toPixels(
 			ftGlyph.getMetrics().horiBearingX);
-		glyph.horizBearingY = FtFontLoader::toPixels(
+		glyph.horizBearingY = UiFtFontLoader::toPixels(
 			ftGlyph.getMetrics().horiBearingY);
-		glyph.horizAdvance = FtFontLoader::toPixels(
+		glyph.horizAdvance = UiFtFontLoader::toPixels(
 			ftGlyph.getMetrics().horiAdvance);
 	}
 
@@ -49,12 +46,12 @@ void Font::create(const char* fontFilename, uint nominalWidth,
 	int posY = 0;
 
 	// For all rows
-	for(uint i = 0; i < FtFontLoader::GLYPH_ROWS; i++)
+	for(uint i = 0; i < UiFtFontLoader::GLYPH_ROWS; i++)
 	{
 		// For all columns
-		for(uint j = 0; j < FtFontLoader::GLYPH_COLUMNS; j++)
+		for(uint j = 0; j < UiFtFontLoader::GLYPH_COLUMNS; j++)
 		{
-			Glyph& glyph = glyphs[i * FtFontLoader::GLYPH_COLUMNS + j];
+			Glyph& glyph = glyphs[i * UiFtFontLoader::GLYPH_COLUMNS + j];
 
 			// Set texture matrix
 			// glyph width
@@ -99,6 +96,3 @@ void Font::create(const char* fontFilename, uint nominalWidth,
 	map->create(tinit);
 	map->setRepeat(false);
 }
-
-
-} // end namespace

+ 12 - 17
src/ui/Font.h → src/ui/UiFont.h

@@ -1,24 +1,22 @@
 #ifndef UI_FONT_H
 #define UI_FONT_H
 
-#include "util/StdTypes.h"
-#include "m/Math.h"
 #include <boost/scoped_ptr.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
+#include "util/StdTypes.h"
+#include "util/Accessors.h"
+#include "m/Math.h"
 
 
 class Texture;
 
 
-namespace ui {
-
-
 /// The font is device agnostic, all sizes are in actual pixels
-class Font
+class UiFont
 {
 	public:
 		/// Constructor @see create
-		Font(const char* fontFilename, uint nominalWidth, uint nominalHeight);
+		UiFont(const char* fontFilename, uint nominalWidth, uint nominalHeight);
 
 		/// @name Accessors
 		/// @{
@@ -59,50 +57,47 @@ class Font
 };
 
 
-inline Font::Font(const char* fontFilename, uint nominalWidth,
+inline UiFont::UiFont(const char* fontFilename, uint nominalWidth,
 	uint nominalHeight)
 {
 	create(fontFilename, nominalWidth, nominalHeight);
 }
 
 
-inline const Mat3& Font::getGlyphTextureMatrix(char c) const
+inline const Mat3& UiFont::getGlyphTextureMatrix(char c) const
 {
 	return glyphs[c - ' '].textureMat;
 }
 
 
-inline uint Font::getGlyphWidth(char c) const
+inline uint UiFont::getGlyphWidth(char c) const
 {
 	return glyphs[c - ' '].width;
 }
 
 
-inline uint Font::getGlyphHeight(char c) const
+inline uint UiFont::getGlyphHeight(char c) const
 {
 	return glyphs[c - ' '].height;
 }
 
 
-inline int Font::getGlyphAdvance(char c) const
+inline int UiFont::getGlyphAdvance(char c) const
 {
 	return glyphs[c - ' '].horizAdvance;
 }
 
 
-inline int Font::getGlyphBearingX(char c) const
+inline int UiFont::getGlyphBearingX(char c) const
 {
 	return glyphs[c - ' '].horizBearingX;
 }
 
 
-inline int Font::getGlyphBearingY(char c) const
+inline int UiFont::getGlyphBearingY(char c) const
 {
 	return glyphs[c - ' '].horizBearingY;
 }
 
 
-} // end namespace
-
-
 #endif

+ 6 - 12
src/ui/FtFontLoader.cpp → src/ui/UiFtFontLoader.cpp

@@ -1,17 +1,14 @@
-#include "FtFontLoader.h"
+#include "UiFtFontLoader.h"
 #include "util/Exception.h"
 #include "core/Logger.h"
 #include "core/Globals.h"
 #include <boost/foreach.hpp>
 
 
-namespace ui {
-
-
 //==============================================================================
 // getAllGlyphs                                                                =
 //==============================================================================
-void FtFontLoader::getAllGlyphs()
+void UiFtFontLoader::getAllGlyphs()
 {
 	glyphs.resize(GLYPHS_NUM);
 
@@ -43,7 +40,7 @@ void FtFontLoader::getAllGlyphs()
 //==============================================================================
 // copyBitmap                                                                  =
 //==============================================================================
-void FtFontLoader::copyBitmap(const uchar* srcImg, const FT_Vector& srcSize,
+void UiFtFontLoader::copyBitmap(const uchar* srcImg, const FT_Vector& srcSize,
 	const FT_Vector& pos)
 {
 	for(int i = 0; i < srcSize.y; i++)
@@ -61,7 +58,7 @@ void FtFontLoader::copyBitmap(const uchar* srcImg, const FT_Vector& srcSize,
 //==============================================================================
 // computeImageSize                                                            =
 //==============================================================================
-void FtFontLoader::computeImageSize()
+void UiFtFontLoader::computeImageSize()
 {
 	imgSize.x = 0;
 	imgSize.y = 0;
@@ -112,7 +109,7 @@ void FtFontLoader::computeImageSize()
 //==============================================================================
 // createImage                                                                 =
 //==============================================================================
-void FtFontLoader::createImage(const char* filename, const FT_Vector& fontSize)
+void UiFtFontLoader::createImage(const char* filename, const FT_Vector& fontSize)
 {
 	FT_Error error;
 
@@ -200,7 +197,7 @@ void FtFontLoader::createImage(const char* filename, const FT_Vector& fontSize)
 //==============================================================================
 // saveImage                                                                   =
 //==============================================================================
-void FtFontLoader::saveImage(const char* filename) const
+void UiFtFontLoader::saveImage(const char* filename) const
 {
 	char tgaHeader[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
@@ -231,6 +228,3 @@ void FtFontLoader::saveImage(const char* filename) const
 
 	fclose(fp);
 }
-
-
-} // end namespace

+ 4 - 10
src/ui/FtFontLoader.h → src/ui/UiFtFontLoader.h

@@ -10,18 +10,15 @@
 #include FT_GLYPH_H
 
 
-namespace ui {
-
-
 /// A helper class that uses libfreetype to load glyphs from a font file and
 /// gather the metrics for each glyph
-class FtFontLoader
+class UiFtFontLoader
 {
 	public:
 		/// Contains info about the glyphs
 		class Glyph
 		{
-			friend class FtFontLoader;
+			friend class UiFtFontLoader;
 
 			public:
 				GETTER_R(FT_Glyph_Metrics, metrics, getMetrics)
@@ -39,7 +36,7 @@ class FtFontLoader
 		};
 
 		/// One and only constructor
-		FtFontLoader(const char* filename, const FT_Vector& fontSize);
+		UiFtFontLoader(const char* filename, const FT_Vector& fontSize);
 
 		/// @name Accessors
 		/// @{
@@ -80,14 +77,11 @@ class FtFontLoader
 };
 
 
-inline FtFontLoader::FtFontLoader(const char* filename,
+inline UiFtFontLoader::UiFtFontLoader(const char* filename,
 	const FT_Vector& fontSize)
 {
 	createImage(filename, fontSize);
 }
 
 
-} // end namespace
-
-
 #endif

+ 9 - 15
src/ui/Painter.cpp → src/ui/UiPainter.cpp

@@ -1,19 +1,16 @@
-#include "Painter.h"
+#include "UiPainter.h"
 #include "gl/GlStateMachine.h"
 #include "rsrc/Texture.h"
 #include "rsrc/ShaderProgram.h"
 #include "core/Logger.h"
-#include "Font.h"
+#include "UiFont.h"
 #include <cstdarg>
 
 
-namespace ui {
-
-
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
-Painter::Painter(const Vec2& deviceSize_)
+UiPainter::UiPainter(const Vec2& deviceSize_)
 :	deviceSize(deviceSize_)
 {
 	init();
@@ -23,21 +20,21 @@ Painter::Painter(const Vec2& deviceSize_)
 //==============================================================================
 // setFont                                                                     =
 //==============================================================================
-void Painter::setFont(const char* fontFilename, uint nominalWidth,
+void UiPainter::setFont(const char* fontFilename, uint nominalWidth,
 	uint nominalHeight)
 {
-	font.reset(new Font(fontFilename, nominalWidth, nominalHeight));
+	font.reset(new UiFont(fontFilename, nominalWidth, nominalHeight));
 }
 
 
 //==============================================================================
 // init                                                                        =
 //==============================================================================
-void Painter::init()
+void UiPainter::init()
 {
 	// Default font
 	float dfltFontWidth = 0.2 * deviceSize.x();
-	font.reset(new Font("engine-rsrc/ConsolaMono.ttf", dfltFontWidth,
+	font.reset(new UiFont("engine-rsrc/ConsolaMono.ttf", dfltFontWidth,
 	                    deviceSize.x() / deviceSize.y() * dfltFontWidth));
 
 	// Misc
@@ -65,7 +62,7 @@ void Painter::init()
 //==============================================================================
 // drawText                                                                    =
 //==============================================================================
-void Painter::drawText(const char* text)
+void UiPainter::drawText(const char* text)
 {
 	// Set GL
 	GlStateMachineSingleton::get().enable(GL_BLEND);
@@ -136,7 +133,7 @@ void Painter::drawText(const char* text)
 //==============================================================================
 // drawFormatedText                                                            =
 //==============================================================================
-void Painter::drawFormatedText(const char* format, ...)
+void UiPainter::drawFormatedText(const char* format, ...)
 {
 	va_list ap;
 	char text[512];
@@ -149,6 +146,3 @@ void Painter::drawFormatedText(const char* format, ...)
 
 	drawText(text);
 }
-
-
-} // end namespace

+ 5 - 11
src/ui/Painter.h → src/ui/UiPainter.h

@@ -9,17 +9,14 @@
 #include <boost/scoped_ptr.hpp>
 
 
-namespace ui {
-
-
-class Font;
+class UiFont;
 
 
 /// @todo
-class Painter
+class UiPainter
 {
 	public:
-		Painter(const Vec2& deviceSize);
+		UiPainter(const Vec2& deviceSize);
 
 		/// @name Accessors
 		/// @{
@@ -27,7 +24,7 @@ class Painter
 		GETTER_SETTER(Vec4, col, getColor, setColor)
 		void setFont(const char* fontFilename, uint nominalWidth,
 			uint nominalHeight);
-		const Font& getFont() const {return *font;}
+		const UiFont& getFont() const {return *font;}
 		/// @}
 
 		void drawText(const char* text);
@@ -37,7 +34,7 @@ class Painter
 	private:
 		/// @name Data
 		/// @{
-		boost::scoped_ptr<Font> font;
+		boost::scoped_ptr<UiFont> font;
 		RsrcPtr<ShaderProgram> sProg;
 
 		Vec2 pos;
@@ -55,7 +52,4 @@ class Painter
 };
 
 
-}
-
-
 #endif

+ 4 - 10
src/ui/PainterDevice.cpp → src/ui/UiPainterDevice.cpp

@@ -1,14 +1,11 @@
-#include "PainterDevice.h"
+#include "UiPainterDevice.h"
 #include "rsrc/Texture.h"
 
 
-namespace ui {
-
-
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
-PainterDevice::PainterDevice(Texture& colorFai_)
+UiPainterDevice::UiPainterDevice(Texture& colorFai_)
 :	colorFai(colorFai_)
 {}
 
@@ -16,7 +13,7 @@ PainterDevice::PainterDevice(Texture& colorFai_)
 //==============================================================================
 // getSize                                                                     =
 //==============================================================================
-Vec2 PainterDevice::getSize() const
+Vec2 UiPainterDevice::getSize() const
 {
 	return Vec2(colorFai.getWidth(), colorFai.getHeight());
 }
@@ -25,7 +22,7 @@ Vec2 PainterDevice::getSize() const
 //==============================================================================
 // create                                                                      =
 //==============================================================================
-void PainterDevice::create()
+void UiPainterDevice::create()
 {
 	Fbo::create();
 	bind();
@@ -36,6 +33,3 @@ void PainterDevice::create()
 
 	unbind();
 }
-
-
-} // end namespace

+ 4 - 10
src/ui/PainterDevice.h → src/ui/UiPainterDevice.h

@@ -1,5 +1,5 @@
-#ifndef UI_PAINDER_DEVICE_H
-#define UI_PAINDER_DEVICE_H
+#ifndef UI_PAINTER_DEVICE_H
+#define UI_PAINTER_DEVICE_H
 
 #include "gl/Fbo.h"
 #include "m/Math.h"
@@ -9,15 +9,12 @@
 class Texture;
 
 
-namespace ui {
-
-
 /// This actually and FBO but with size info
-class PainterDevice: public Fbo
+class UiPainterDevice: public Fbo
 {
 	public:
 		/// Constructor
-		PainterDevice(Texture& colorFai);
+		UiPainterDevice(Texture& colorFai);
 
 		/// @name Accessors
 		/// @{
@@ -31,7 +28,4 @@ class PainterDevice: public Fbo
 };
 
 
-} // end namespace
-
-
 #endif

+ 1 - 1
src/util/Accessors.h

@@ -31,7 +31,7 @@
 
 /// Setter, cause we are to bored to write
 #define SETTER_BY_VAL(type__, var__, setter__) \
-	void setter__(type__ x__) {var__ = x__;}
+	void setter__(const type__ x__) {var__ = x__;}
 
 
 /// The macro implies read write var