Răsfoiți Sursa

Updated Vector2/Vector3/Vector4 native classes
Added managed vector classes and managed math class

Marko Pintera 12 ani în urmă
părinte
comite
def3e8c935

+ 4 - 4
BansheeEngine/Source/BsCamera.cpp

@@ -510,16 +510,16 @@ namespace BansheeEngine
 			// Some custom projection matrices can have unusual inverted settings
 			// So make sure the AABB is the right way around to start with
 			Vector3 tmp = min;
-			min.makeFloor(max);
-			max.makeCeil(tmp);
+			min.floor(max);
+			max.ceil(tmp);
 		}
 
 		if (mProjType == PT_PERSPECTIVE)
 		{
 			// Merge with far plane bounds
 			float radio = farDist / mNearDist;
-			min.makeFloor(Vector3(left * radio, bottom * radio, -farDist));
-			max.makeCeil(Vector3(right * radio, top * radio, 0));
+			min.floor(Vector3(left * radio, bottom * radio, -farDist));
+			max.ceil(Vector3(right * radio, top * radio, 0));
 		}
 		mBoundingBox.setExtents(min, max);
 

+ 0 - 15
CSharpWrap.txt

@@ -54,20 +54,6 @@ to call a Main function in the assembly
 
  -----------------
 
- Implement ScriptField, EngineAssembly classes
-Implement ScriptClass::getField method
-
- -----------------
-
- add BansheeEditor class
- Add C++ EditorApplication and have it start up Application and create a main window
-Then in C# class just call EditorApplication to create a main window
-
-Create another .exe class called BansheeEd, which loads up MBansheeEditor assembly and calls EditorApplication to start everything up.
- - I might need to add Mono loading code to BansheeEngine first?
- - ScriptManager
-  - InvokeMethod
-
 For EditorWindow, add a new class in BansheeEditor, which pretty much does the job of  EditorWidget::open
  - Except it creates an empty widget. (It will also create a window, but in C++ code)
  - All the window docking/undocking moving/resizing is done in C++
@@ -77,7 +63,6 @@ For EditorWindow, add a new class in BansheeEditor, which pretty much does the j
 
  Implementation steps:
  - Get EditorApplication finished and make the main window open from C#
-   - (Will possibly need to make new CamelotClient.cpp? since that one is full of junk)
  - Add support for Resources
    - Importer - Likely invisible for outside world
    - Resources.Save/Load - Will likely need some kind of an AssetManager for all imported assets

+ 1 - 1
CamelotClient/Source/CmDebugCamera.cpp

@@ -84,7 +84,7 @@ namespace CamelotFramework
 			mPitch += Degree(gInput().getVerticalAxis() * ROTATION_SPEED);
 
 			Quaternion yRot;
-			yRot.FromAngleAxis(Radian(mYaw), Vector3::UP);
+			yRot.FromAngleAxis(Radian(mYaw), Vector3::UNIT_Y);
 
 			Quaternion xRot;
 			xRot.FromAngleAxis(Radian(mPitch), yRot.xAxis());

+ 1 - 1
CamelotCore/Include/CmSceneObject.h

@@ -62,7 +62,7 @@ namespace CamelotFramework
 		 *
 		 * @return	Forward axis of the object.
 		 */
-		Vector3 getForward() const { return getWorldRotation() * Vector3::NEGATIVE_UNIT_Z; }
+		Vector3 getForward() const { return getWorldRotation() * -Vector3::UNIT_Z; }
 
 		/**
 		 * @brief	Gets the Y (up) axis of the object, in world space.

+ 3 - 3
CamelotCore/Source/CmSceneObject.cpp

@@ -8,8 +8,8 @@
 namespace CamelotFramework
 {
 	SceneObject::SceneObject(const String& name)
-		:mName(name), mPosition(Vector3::ZERO), mRotation(Quaternion::IDENTITY), mScale(Vector3::UNIT_SCALE),
-		mWorldPosition(Vector3::ZERO), mWorldRotation(Quaternion::IDENTITY), mWorldScale(Vector3::UNIT_SCALE),
+		:mName(name), mPosition(Vector3::ZERO), mRotation(Quaternion::IDENTITY), mScale(Vector3::ONE),
+		mWorldPosition(Vector3::ZERO), mWorldRotation(Quaternion::IDENTITY), mWorldScale(Vector3::ONE),
 		mCachedLocalTfrm(Matrix4::IDENTITY), mIsCachedLocalTfrmUpToDate(false),
 		mCachedWorldTfrm(Matrix4::IDENTITY), mIsCachedWorldTfrmUpToDate(false),
 		mCustomWorldTfrm(Matrix4::IDENTITY), mIsCustomTfrmModeActive(false)
@@ -203,7 +203,7 @@ namespace CamelotFramework
 		if (forwardDir == Vector3::ZERO) 
 			return;
 
-		Vector3 nrmForwardDir = forwardDir.normalizedCopy();
+		Vector3 nrmForwardDir = Vector3::normalize(forwardDir);
 		Vector3 currentForwardDir = getForward();
 		
 		const Quaternion& currentRotation = getWorldRotation();

+ 9 - 9
CamelotUtility/Include/CmAABox.cpp

@@ -5,7 +5,7 @@ namespace CamelotFramework
 	const AABox AABox::BOX_EMPTY;
 
 	AABox::AABox() 
-		:mMinimum(Vector3::ZERO), mMaximum(Vector3::UNIT_SCALE)
+		:mMinimum(Vector3::ZERO), mMaximum(Vector3::ONE)
 	{
 		// Default to a null box 
 		setMin(Vector3(-0.5f, -0.5f, -0.5f));
@@ -13,13 +13,13 @@ namespace CamelotFramework
 	}
 
 	AABox::AABox(const AABox & rkBox)
-		:mMinimum(Vector3::ZERO), mMaximum(Vector3::UNIT_SCALE)
+		:mMinimum(Vector3::ZERO), mMaximum(Vector3::ONE)
 	{
 		setExtents( rkBox.mMinimum, rkBox.mMaximum );
 	}
 
 	AABox::AABox(const Vector3& min, const Vector3& max)
-		:mMinimum(Vector3::ZERO), mMaximum(Vector3::UNIT_SCALE)
+		:mMinimum(Vector3::ZERO), mMaximum(Vector3::ONE)
 	{
 		setExtents( min, max );
 	}
@@ -69,16 +69,16 @@ namespace CamelotFramework
 	{
 		Vector3 min = mMinimum;
 		Vector3 max = mMaximum;
-		max.makeCeil(rhs.mMaximum);
-		min.makeFloor(rhs.mMinimum);
+		max.ceil(rhs.mMaximum);
+		min.floor(rhs.mMinimum);
 
 		setExtents(min, max);
 	}
 
 	void AABox::merge( const Vector3& point )
 	{
-		mMaximum.makeCeil(point);
-		mMinimum.makeFloor(point);
+		mMaximum.ceil(point);
+		mMinimum.floor(point);
 	}
 
 	void AABox::transform( const Matrix4& matrix )
@@ -172,8 +172,8 @@ namespace CamelotFramework
 		Vector3 intMin = mMinimum;
         Vector3 intMax = mMaximum;
 
-        intMin.makeCeil(b2.getMin());
-        intMax.makeFloor(b2.getMax());
+        intMin.ceil(b2.getMin());
+        intMax.floor(b2.getMax());
 
         // Check intersection isn't null
         if (intMin.x < intMax.x &&

+ 0 - 2
CamelotUtility/Include/CmPlane.h

@@ -153,8 +153,6 @@ namespace CamelotFramework {
         {
             return (rhs.d != d || rhs.normal != normal);
         }
-
-        CM_UTILITY_EXPORT friend std::ostream& operator<< (std::ostream& o, const Plane& p);
     };
 
     typedef Vector<Plane>::type PlaneList;

+ 4 - 32
CamelotUtility/Include/CmQuaternion.h

@@ -33,22 +33,13 @@ THE SOFTWARE.
 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
 
 
-#ifndef __Quaternion_H__
-#define __Quaternion_H__
+#pragma once
 
 #include "CmPrerequisitesUtil.h"
 #include "CmMath.h"
 
-namespace CamelotFramework {
-
-	/** \addtogroup Core
-	*  @{
-	*/
-	/** \addtogroup Math
-	*  @{
-	*/
-	/** Implementation of a Quaternion, i.e. a rotation around an axis.
-    */
+namespace CamelotFramework 
+{
     class CM_UTILITY_EXPORT Quaternion
     {
     public:
@@ -248,24 +239,5 @@ namespace CamelotFramework {
 		{
 			return Math::isNaN(x) || Math::isNaN(y) || Math::isNaN(z) || Math::isNaN(w);
 		}
-
-        /** Function for writing to a stream. Outputs "Quaternion(w, x, y, z)" with w,x,y,z
-            being the member values of the quaternion.
-        */
-        inline CM_UTILITY_EXPORT friend std::ostream& operator <<
-            ( std::ostream& o, const Quaternion& q )
-        {
-            o << "Quaternion(" << q.w << ", " << q.x << ", " << q.y << ", " << q.z << ")";
-            return o;
-        }
-
     };
-	/** @} */
-	/** @} */
-
-}
-
-
-
-
-#endif 
+}

+ 169 - 353
CamelotUtility/Include/CmVector2.h

@@ -25,524 +25,356 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
-#ifndef __Vector2_H__
-#define __Vector2_H__
-
+#pragma once
 
 #include "CmPrerequisitesUtil.h"
 #include "CmMath.h"
 
 namespace CamelotFramework
 {
-	/** \addtogroup Core
-	*  @{
-	*/
-	/** \addtogroup Math
-	*  @{
-	*/
-	/** Standard 2-dimensional vector.
-        @remarks
-            A direction in 2D space represented as distances along the 2
-            orthogonal axes (x, y). Note that positions, directions and
-            scaling factors can be represented by a vector, depending on how
-            you interpret the values.
-    */
     class CM_UTILITY_EXPORT Vector2
     {
     public:
         float x, y;
 
     public:
-        inline Vector2()
-        {
-        }
-
-        inline Vector2(const float fX, const float fY )
-            : x( fX ), y( fY )
-        {
-        }
-
-        inline explicit Vector2( const float scaler )
-            : x( scaler), y( scaler )
-        {
-        }
-
-        inline explicit Vector2( const float afCoordinate[2] )
-            : x( afCoordinate[0] ),
-              y( afCoordinate[1] )
-        {
-        }
-
-        inline explicit Vector2( const int afCoordinate[2] )
-        {
-            x = (float)afCoordinate[0];
-            y = (float)afCoordinate[1];
-        }
+        Vector2()
+        { }
 
-        inline explicit Vector2( float* const r )
-            : x( r[0] ), y( r[1] )
-        {
-        }
+        Vector2(float x, float y)
+            : x(x), y(y)
+        { }
 
-		/** Exchange the contents of this vector with another. 
-		*/
-		inline void swap(Vector2& other)
+		/**
+		 * @brief	Exchange the contents of this vector with another.
+		 */
+		void swap(Vector2& other)
 		{
 			std::swap(x, other.x);
 			std::swap(y, other.y);
 		}
 
-		inline float operator [] ( const size_t i ) const
+		float operator[] (size_t i) const
         {
-            assert( i < 2 );
+            assert(i < 2);
 
             return *(&x+i);
         }
 
-		inline float& operator [] ( const size_t i )
+		float& operator[] (size_t i)
         {
-            assert( i < 2 );
+            assert(i < 2);
 
             return *(&x+i);
         }
 
-		/// Pointer accessor for direct copying
-		inline float* ptr()
+		float* ptr()
 		{
 			return &x;
 		}
-		/// Pointer accessor for direct copying
-		inline const float* ptr() const
+
+		const float* ptr() const
 		{
 			return &x;
 		}
 
-        /** Assigns the value of the other vector.
-            @param
-                rkVector The other vector
-        */
-        inline Vector2& operator = ( const Vector2& rkVector )
+        Vector2& operator= (const Vector2& rhs)
         {
-            x = rkVector.x;
-            y = rkVector.y;
+            x = rhs.x;
+            y = rhs.y;
 
             return *this;
         }
 
-		inline Vector2& operator = ( const float fScalar)
+		Vector2& operator= (float rhs)
 		{
-			x = fScalar;
-			y = fScalar;
+			x = rhs;
+			y = rhs;
 
 			return *this;
 		}
 
-        inline bool operator == ( const Vector2& rkVector ) const
+        bool operator== (const Vector2& rhs) const
         {
-            return ( x == rkVector.x && y == rkVector.y );
+            return (x == rhs.x && y == rhs.y);
         }
 
-        inline bool operator != ( const Vector2& rkVector ) const
+        bool operator!= (const Vector2& rhs) const
         {
-            return ( x != rkVector.x || y != rkVector.y  );
+            return (x != rhs.x || y != rhs.y);
         }
 
-        // arithmetic operations
-        inline Vector2 operator + ( const Vector2& rkVector ) const
+        Vector2 operator+ (const Vector2& rhs) const
         {
-            return Vector2(
-                x + rkVector.x,
-                y + rkVector.y);
+            return Vector2(x + rhs.x, y + rhs.y);
         }
 
-        inline Vector2 operator - ( const Vector2& rkVector ) const
+        Vector2 operator- (const Vector2& rhs) const
         {
-            return Vector2(
-                x - rkVector.x,
-                y - rkVector.y);
+            return Vector2(x - rhs.x, y - rhs.y);
         }
 
-        inline Vector2 operator * ( const float fScalar ) const
+        Vector2 operator* (const float rhs) const
         {
-            return Vector2(
-                x * fScalar,
-                y * fScalar);
+            return Vector2(x * rhs, y * rhs);
         }
 
-        inline Vector2 operator * ( const Vector2& rhs) const
+        Vector2 operator* (const Vector2& rhs) const
         {
-            return Vector2(
-                x * rhs.x,
-                y * rhs.y);
+            return Vector2(x * rhs.x, y * rhs.y);
         }
 
-        inline Vector2 operator / ( const float fScalar ) const
+        Vector2 operator/ (const float rhs) const
         {
-            assert( fScalar != 0.0 );
+            assert(rhs != 0.0);
 
-            float fInv = 1.0f / fScalar;
+            float fInv = 1.0f / rhs;
 
-            return Vector2(
-                x * fInv,
-                y * fInv);
+            return Vector2(x * fInv, y * fInv);
         }
 
-        inline Vector2 operator / ( const Vector2& rhs) const
+        Vector2 operator/ (const Vector2& rhs) const
         {
-            return Vector2(
-                x / rhs.x,
-                y / rhs.y);
+            return Vector2(x / rhs.x, y / rhs.y);
         }
 
-        inline const Vector2& operator + () const
+        const Vector2& operator+ () const
         {
             return *this;
         }
 
-        inline Vector2 operator - () const
+        Vector2 operator- () const
         {
             return Vector2(-x, -y);
         }
 
-        // overloaded operators to help Vector2
-        inline friend Vector2 operator * ( const float fScalar, const Vector2& rkVector )
+        friend Vector2 operator* (float lhs, const Vector2& rhs)
         {
-            return Vector2(
-                fScalar * rkVector.x,
-                fScalar * rkVector.y);
+            return Vector2(lhs * rhs.x, lhs * rhs.y);
         }
 
-        inline friend Vector2 operator / ( const float fScalar, const Vector2& rkVector )
+        friend Vector2 operator/ (float lhs, const Vector2& rhs)
         {
-            return Vector2(
-                fScalar / rkVector.x,
-                fScalar / rkVector.y);
+            return Vector2(lhs / rhs.x, lhs / rhs.y);
         }
 
-        inline friend Vector2 operator + (const Vector2& lhs, const float rhs)
+        friend Vector2 operator+ (Vector2& lhs, float rhs)
         {
-            return Vector2(
-                lhs.x + rhs,
-                lhs.y + rhs);
+            return Vector2(lhs.x + rhs, lhs.y + rhs);
         }
 
-        inline friend Vector2 operator + (const float lhs, const Vector2& rhs)
+        friend Vector2 operator+ (float lhs, const Vector2& rhs)
         {
-            return Vector2(
-                lhs + rhs.x,
-                lhs + rhs.y);
+            return Vector2(lhs + rhs.x, lhs + rhs.y);
         }
 
-        inline friend Vector2 operator - (const Vector2& lhs, const float rhs)
+        friend Vector2 operator- (const Vector2& lhs, float rhs)
         {
-            return Vector2(
-                lhs.x - rhs,
-                lhs.y - rhs);
+            return Vector2(lhs.x - rhs, lhs.y - rhs);
         }
 
-        inline friend Vector2 operator - (const float lhs, const Vector2& rhs)
+        friend Vector2 operator- (const float lhs, const Vector2& rhs)
         {
-            return Vector2(
-                lhs - rhs.x,
-                lhs - rhs.y);
+            return Vector2(lhs - rhs.x, lhs - rhs.y);
         }
-        // arithmetic updates
-        inline Vector2& operator += ( const Vector2& rkVector )
+
+        Vector2& operator+= (const Vector2& rhs)
         {
-            x += rkVector.x;
-            y += rkVector.y;
+            x += rhs.x;
+            y += rhs.y;
 
             return *this;
         }
 
-        inline Vector2& operator += ( const float fScaler )
+        Vector2& operator+= (float rhs)
         {
-            x += fScaler;
-            y += fScaler;
+            x += rhs;
+            y += rhs;
 
             return *this;
         }
 
-        inline Vector2& operator -= ( const Vector2& rkVector )
+        Vector2& operator-= (const Vector2& rhs)
         {
-            x -= rkVector.x;
-            y -= rkVector.y;
+            x -= rhs.x;
+            y -= rhs.y;
 
             return *this;
         }
 
-        inline Vector2& operator -= ( const float fScaler )
+        Vector2& operator-= (float rhs)
         {
-            x -= fScaler;
-            y -= fScaler;
+            x -= rhs;
+            y -= rhs;
 
             return *this;
         }
 
-        inline Vector2& operator *= ( const float fScalar )
+        Vector2& operator*= (float rhs)
         {
-            x *= fScalar;
-            y *= fScalar;
+            x *= rhs;
+            y *= rhs;
 
             return *this;
         }
 
-        inline Vector2& operator *= ( const Vector2& rkVector )
+        Vector2& operator*= (const Vector2& rhs)
         {
-            x *= rkVector.x;
-            y *= rkVector.y;
+            x *= rhs.x;
+            y *= rhs.y;
 
             return *this;
         }
 
-        inline Vector2& operator /= ( const float fScalar )
+        Vector2& operator/= (float rhs)
         {
-            assert( fScalar != 0.0 );
+            assert(rhs != 0.0f);
 
-            float fInv = 1.0f / fScalar;
+            float inv = 1.0f / rhs;
 
-            x *= fInv;
-            y *= fInv;
+            x *= inv;
+            y *= inv;
 
             return *this;
         }
 
-        inline Vector2& operator /= ( const Vector2& rkVector )
+        Vector2& operator/= (const Vector2& rhs)
         {
-            x /= rkVector.x;
-            y /= rkVector.y;
+            x /= rhs.x;
+            y /= rhs.y;
 
             return *this;
         }
 
-        /** Returns the length (magnitude) of the vector.
-            @warning
-                This operation requires a square root and is expensive in
-                terms of CPU operations. If you don't need to know the exact
-                length (e.g. for just comparing lengths) use squaredLength()
-                instead.
-        */
-        inline float length () const
+        /**
+         * @brief	Returns the length (magnitude) of the vector.
+         */
+        float length() const
         {
-            return Math::Sqrt( x * x + y * y );
+            return Math::Sqrt(x * x + y * y);
         }
 
-        /** Returns the square of the length(magnitude) of the vector.
-            @remarks
-                This  method is for efficiency - calculating the actual
-                length of a vector requires a square root, which is expensive
-                in terms of the operations required. This method returns the
-                square of the length of the vector, i.e. the same as the
-                length but before the square root is taken. Use this if you
-                want to find the longest / shortest vector without incurring
-                the square root.
-        */
-        inline float squaredLength () const
+        /**
+         * @brief	Returns the square of the length(magnitude) of the vector.
+         */
+        float squaredLength() const
         {
             return x * x + y * y;
         }
-        /** Returns the distance to another vector.
-            @warning
-                This operation requires a square root and is expensive in
-                terms of CPU operations. If you don't need to know the exact
-                distance (e.g. for just comparing distances) use squaredDistance()
-                instead.
-        */
-        inline float distance(const Vector2& rhs) const
+
+        /**
+         * @brief	Returns the distance to another vector.
+         */
+        float distance(const Vector2& rhs) const
         {
             return (*this - rhs).length();
         }
 
-        /** Returns the square of the distance to another vector.
-            @remarks
-                This method is for efficiency - calculating the actual
-                distance to another vector requires a square root, which is
-                expensive in terms of the operations required. This method
-                returns the square of the distance to another vector, i.e.
-                the same as the distance but before the square root is taken.
-                Use this if you want to find the longest / shortest distance
-                without incurring the square root.
-        */
-        inline float squaredDistance(const Vector2& rhs) const
+        /**
+         * @brief	Returns the square of the distance to another vector.
+         */
+        float sqrdDistance(const Vector2& rhs) const
         {
             return (*this - rhs).squaredLength();
         }
 
-        /** Calculates the dot (scalar) product of this vector with another.
-            @remarks
-                The dot product can be used to calculate the angle between 2
-                vectors. If both are unit vectors, the dot product is the
-                cosine of the angle; otherwise the dot product must be
-                divided by the product of the lengths of both vectors to get
-                the cosine of the angle. This result can further be used to
-                calculate the distance of a point from a plane.
-            @param
-                vec Vector with which to calculate the dot product (together
-                with this one).
-            @returns
-                A float representing the dot product value.
-        */
-        inline float dotProduct(const Vector2& vec) const
+        /**
+         * @brief	Calculates the dot (scalar) product of this vector with another.
+         */
+        float dot(const Vector2& vec) const
         {
             return x * vec.x + y * vec.y;
         }
 
-        /** Normalises the vector.
-            @remarks
-                This method normalises the vector such that it's
-                length / magnitude is 1. The result is called a unit vector.
-            @note
-                This function will not crash for zero-sized vectors, but there
-                will be no changes made to their components.
-            @returns The previous length of the vector.
-        */
-        inline float normalize()
+        /**
+         * @brief	Normalizes the vector.
+         */
+        float normalize()
         {
-            float fLength = Math::Sqrt( x * x + y * y);
+            float len = Math::Sqrt(x * x + y * y);
 
             // Will also work for zero-sized vectors, but will change nothing
-            if ( fLength > 1e-08 )
+            if (len > 1e-08)
             {
-                float fInvLength = 1.0f / fLength;
-                x *= fInvLength;
-                y *= fInvLength;
+                float invLen = 1.0f / len;
+                x *= invLen;
+                y *= invLen;
             }
 
-            return fLength;
+            return len;
         }
 
-
-
-        /** Returns a vector at a point half way between this and the passed
-            in vector.
-        */
-        inline Vector2 midPoint( const Vector2& vec ) const
-        {
-            return Vector2(
-                ( x + vec.x ) * 0.5f,
-                ( y + vec.y ) * 0.5f );
-        }
-
-        /** Returns true if the vector's scalar components are all greater
-            that the ones of the vector it is compared against.
-        */
-        inline bool operator < ( const Vector2& rhs ) const
+        /**
+         * @brief	Generates a vector perpendicular to this vector.
+         */
+        Vector2 perpendicular() const
         {
-            if( x < rhs.x && y < rhs.y )
-                return true;
-            return false;
+            return Vector2 (-y, x);
         }
 
-        /** Returns true if the vector's scalar components are all smaller
-            that the ones of the vector it is compared against.
-        */
-        inline bool operator > ( const Vector2& rhs ) const
+        /**
+		 * @brief	Calculates the 2 dimensional cross-product of 2 vectors, which results
+		 *		in a single floating point value which is 2 times the area of the triangle.
+         */
+        float cross(const Vector2& other) const
         {
-            if( x > rhs.x && y > rhs.y )
-                return true;
-            return false;
+            return x * other.y - y * other.x;
         }
 
-        /** Sets this vector's components to the minimum of its own and the
-            ones of the passed in vector.
-            @remarks
-                'Minimum' in this case means the combination of the lowest
-                value of x, y and z from both vectors. Lowest is taken just
-                numerically, not magnitude, so -1 < 0.
-        */
-        inline void makeFloor( const Vector2& cmp )
+        /**
+		 * @brief	Sets this vector's components to the minimum of its own and the
+		 *		ones of the passed in vector.
+         */
+        void floor(const Vector2& cmp)
         {
-            if( cmp.x < x ) x = cmp.x;
-            if( cmp.y < y ) y = cmp.y;
+            if(cmp.x < x) x = cmp.x;
+            if(cmp.y < y) y = cmp.y;
         }
 
-        /** Sets this vector's components to the maximum of its own and the
-            ones of the passed in vector.
-            @remarks
-                'Maximum' in this case means the combination of the highest
-                value of x, y and z from both vectors. Highest is taken just
-                numerically, not magnitude, so 1 > -3.
-        */
-        inline void makeCeil( const Vector2& cmp )
+        /**
+		 * @brief	Sets this vector's components to the maximum of its own and the
+		 *		ones of the passed in vector.
+         */
+        void ceil(const Vector2& cmp)
         {
-            if( cmp.x > x ) x = cmp.x;
-            if( cmp.y > y ) y = cmp.y;
+            if(cmp.x > x) x = cmp.x;
+            if(cmp.y > y) y = cmp.y;
         }
 
-        /** Generates a vector perpendicular to this vector (eg an 'up' vector).
-            @remarks
-                This method will return a vector which is perpendicular to this
-                vector. There are an infinite number of possibilities but this
-                method will guarantee to generate one of them. If you need more
-                control you should use the Quaternion class.
-        */
-        inline Vector2 perpendicular(void) const
-        {
-            return Vector2 (-y, x);
-        }
-        /** Calculates the 2 dimensional cross-product of 2 vectors, which results
-			in a single floating point value which is 2 times the area of the triangle.
-        */
-        inline float crossProduct( const Vector2& rkVector ) const
-        {
-            return x * rkVector.y - y * rkVector.x;
-        }
-        /** Generates a new random vector which deviates from this vector by a
-            given angle in a random direction.
-            @remarks
-                This method assumes that the random number generator has already
-                been seeded appropriately.
-            @param
-                angle The angle at which to deviate in radians
-            @param
-                up Any vector perpendicular to this one (which could generated
-                by cross-product of this vector and any other non-colinear
-                vector). If you choose not to provide this the function will
-                derive one on it's own, however if you provide one yourself the
-                function will be faster (this allows you to reuse up vectors if
-                you call this method more than once)
-            @returns
-                A random vector which deviates from this vector by angle. This
-                vector will not be normalised, normalise it if you wish
-                afterwards.
-        */
-        inline Vector2 randomDeviant(
-            float angle) const
-        {
-
-            angle *=  Math::UnitRandom() * Math::TWO_PI;
-            float cosa = cos(angle);
-            float sina = sin(angle);
-            return  Vector2(cosa * x - sina * y,
-                            sina * x + cosa * y);
-        }
-
-        /** Returns true if this vector is zero length. */
-        inline bool isZeroLength(void) const
+        /**
+         * @brief	Returns true if this vector is zero length.
+         */
+        bool isZeroLength() const
         {
             float sqlen = (x * x) + (y * y);
             return (sqlen < (1e-06 * 1e-06));
-
         }
 
-        /** As normalise, except that this vector is unaffected and the
-            normalised vector is returned as a copy. */
-        inline Vector2 normalizedCopy(void) const
+        /**
+		 * @brief	Calculates a reflection vector to the plane with the given normal.
+         */
+        Vector2 reflect(const Vector2& normal) const
         {
-            Vector2 ret = *this;
-            ret.normalize();
-            return ret;
+            return Vector2(*this - (2 * this->dot(normal) * normal));
         }
 
-        /** Calculates a reflection vector to the plane with the given normal .
-        @remarks NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.
-        */
-        inline Vector2 reflect(const Vector2& normal) const
-        {
-            return Vector2( *this - ( 2 * this->dotProduct(normal) * normal ) );
-        }
-		/// Check whether this vector contains valid values
-		inline bool isNaN() const
+		static Vector2 normalize(const Vector2& val)
+		{
+			float len = Math::Sqrt(val.x * val.x + val.y * val.y);
+
+			// Will also work for zero-sized vectors, but will change nothing
+			Vector2 normalizedVec;
+			if (len > 1e-08)
+			{
+				float invLen = 1.0f / len;
+				normalizedVec.x *= invLen;
+				normalizedVec.y *= invLen;
+			}
+
+			return normalizedVec;
+		}
+
+		bool isNaN() const
 		{
 			return Math::isNaN(x) || Math::isNaN(y);
 		}
@@ -557,27 +389,11 @@ namespace CamelotFramework
 			return Vector2(std::max(a.x, b.x), std::max(a.y, b.y));
 		}
 
-        // special points
         static const Vector2 ZERO;
-        static const Vector2 UNIT_X;
-        static const Vector2 UNIT_Y;
-        static const Vector2 NEGATIVE_UNIT_X;
-        static const Vector2 NEGATIVE_UNIT_Y;
-        static const Vector2 UNIT_SCALE;
-
-        /** Function for writing to a stream.
-        */
-        inline CM_UTILITY_EXPORT friend std::ostream& operator <<
-            ( std::ostream& o, const Vector2& v )
-        {
-            o << "Vector2(" << v.x << ", " << v.y <<  ")";
-            return o;
-        }
-
+		static const Vector2 ONE;
+		static const Vector2 UNIT_X;
+		static const Vector2 UNIT_Y;
     };
-	/** @} */
-	/** @} */
 
 	CM_ALLOW_MEMCPY_SERIALIZATION(Vector2);
-}
-#endif
+}

+ 205 - 513
CamelotUtility/Include/CmVector3.h

@@ -25,8 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
-#ifndef __Vector3_H__
-#define __Vector3_H__
+#pragma once
 
 #include "CmPrerequisitesUtil.h"
 #include "CmMath.h"
@@ -34,596 +33,343 @@ THE SOFTWARE.
 
 namespace CamelotFramework
 {
-	/** \addtogroup Core
-	*  @{
-	*/
-	/** \addtogroup Math
-	*  @{
-	*/
-	/** Standard 3-dimensional vector.
-        @remarks
-            A direction in 3D space represented as distances along the 3
-            orthogonal axes (x, y, z). Note that positions, directions and
-            scaling factors can be represented by a vector, depending on how
-            you interpret the values.
-    */
     class CM_UTILITY_EXPORT Vector3
     {
     public:
 		float x, y, z;
 
     public:
-        inline Vector3()
-        {
-        }
+        Vector3()
+        { }
 
-        inline Vector3( const float fX, const float fY, const float fZ )
-            : x( fX ), y( fY ), z( fZ )
-        {
-        }
-
-        inline explicit Vector3( const float afCoordinate[3] )
-            : x( afCoordinate[0] ),
-              y( afCoordinate[1] ),
-              z( afCoordinate[2] )
-        {
-        }
-
-        inline explicit Vector3( const int afCoordinate[3] )
-        {
-            x = (float)afCoordinate[0];
-            y = (float)afCoordinate[1];
-            z = (float)afCoordinate[2];
-        }
-
-        inline explicit Vector3( float* const r )
-            : x( r[0] ), y( r[1] ), z( r[2] )
-        {
-        }
+        Vector3(float x, float y, float z)
+            : x(x), y(y), z(z)
+        { }
 
-        inline explicit Vector3( const float scaler )
-            : x( scaler )
-            , y( scaler )
-            , z( scaler )
-        {
-        }
-
-
-		/** Exchange the contents of this vector with another. 
-		*/
-		inline void swap(Vector3& other)
+		/**
+		 * @brief	Exchange the contents of this vector with another.
+		 */
+		void swap(Vector3& other)
 		{
 			std::swap(x, other.x);
 			std::swap(y, other.y);
 			std::swap(z, other.z);
 		}
 
-		inline float operator [] ( const size_t i ) const
+		float operator[] (size_t i) const
         {
-            assert( i < 3 );
+            assert(i < 3);
 
             return *(&x+i);
         }
 
-		inline float& operator [] ( const size_t i )
+		float& operator[] (size_t i)
         {
-            assert( i < 3 );
+            assert(i < 3);
 
             return *(&x+i);
         }
-		/// Pointer accessor for direct copying
-		inline float* ptr()
+
+		float* ptr()
 		{
 			return &x;
 		}
-		/// Pointer accessor for direct copying
-		inline const float* ptr() const
+
+		const float* ptr() const
 		{
 			return &x;
 		}
 
-        /** Assigns the value of the other vector.
-            @param
-                rkVector The other vector
-        */
-        inline Vector3& operator = ( const Vector3& rkVector )
+        Vector3& operator= (const Vector3& rhs)
         {
-            x = rkVector.x;
-            y = rkVector.y;
-            z = rkVector.z;
+            x = rhs.x;
+            y = rhs.y;
+            z = rhs.z;
 
             return *this;
         }
 
-        inline Vector3& operator = ( const float fScaler )
+        Vector3& operator= (float rhs)
         {
-            x = fScaler;
-            y = fScaler;
-            z = fScaler;
+            x = rhs;
+            y = rhs;
+            z = rhs;
 
             return *this;
         }
 
-        inline bool operator == ( const Vector3& rkVector ) const
+        bool operator== (const Vector3& rhs) const
         {
-            return ( x == rkVector.x && y == rkVector.y && z == rkVector.z );
+            return (x == rhs.x && y == rhs.y && z == rhs.z);
         }
 
-        inline bool operator != ( const Vector3& rkVector ) const
+        bool operator!= (const Vector3& rhs) const
         {
-            return ( x != rkVector.x || y != rkVector.y || z != rkVector.z );
+            return (x != rhs.x || y != rhs.y || z != rhs.z);
         }
 
-        // arithmetic operations
-        inline Vector3 operator + ( const Vector3& rkVector ) const
+        Vector3 operator+ (const Vector3& rhs) const
         {
-            return Vector3(
-                x + rkVector.x,
-                y + rkVector.y,
-                z + rkVector.z);
+            return Vector3(x + rhs.x, y + rhs.y, z + rhs.z);
         }
 
-        inline Vector3 operator - ( const Vector3& rkVector ) const
+        Vector3 operator- (const Vector3& rhs) const
         {
-            return Vector3(
-                x - rkVector.x,
-                y - rkVector.y,
-                z - rkVector.z);
+            return Vector3(x - rhs.x, y - rhs.y, z - rhs.z);
         }
 
-        inline Vector3 operator * ( const float fScalar ) const
+        Vector3 operator* (float rhs) const
         {
-            return Vector3(
-                x * fScalar,
-                y * fScalar,
-                z * fScalar);
+            return Vector3(x * rhs, y * rhs, z * rhs);
         }
 
-        inline Vector3 operator * ( const Vector3& rhs) const
+        Vector3 operator* (const Vector3& rhs) const
         {
-            return Vector3(
-                x * rhs.x,
-                y * rhs.y,
-                z * rhs.z);
+            return Vector3(x * rhs.x, y * rhs.y, z * rhs.z);
         }
 
-        inline Vector3 operator / ( const float fScalar ) const
+        Vector3 operator/ (float val) const
         {
-            assert( fScalar != 0.0 );
-
-            float fInv = 1.0f / fScalar;
+            assert(val != 0.0);
 
-            return Vector3(
-                x * fInv,
-                y * fInv,
-                z * fInv);
+            float fInv = 1.0f / val;
+            return Vector3(x * fInv, y * fInv, z * fInv);
         }
 
-        inline Vector3 operator / ( const Vector3& rhs) const
+        Vector3 operator/ (const Vector3& rhs) const
         {
-            return Vector3(
-                x / rhs.x,
-                y / rhs.y,
-                z / rhs.z);
+            return Vector3(x / rhs.x, y / rhs.y, z / rhs.z);
         }
 
-        inline const Vector3& operator + () const
+        const Vector3& operator+ () const
         {
             return *this;
         }
 
-        inline Vector3 operator - () const
+        Vector3 operator- () const
         {
             return Vector3(-x, -y, -z);
         }
 
-        // overloaded operators to help Vector3
-        inline friend Vector3 operator * ( const float fScalar, const Vector3& rkVector )
+        friend Vector3 operator* (float lhs, const Vector3& rhs)
         {
-            return Vector3(
-                fScalar * rkVector.x,
-                fScalar * rkVector.y,
-                fScalar * rkVector.z);
+            return Vector3(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z);
         }
 
-        inline friend Vector3 operator / ( const float fScalar, const Vector3& rkVector )
+        friend Vector3 operator/ (float lhs, const Vector3& rhs)
         {
-            return Vector3(
-                fScalar / rkVector.x,
-                fScalar / rkVector.y,
-                fScalar / rkVector.z);
+            return Vector3(lhs / rhs.x, lhs / rhs.y, lhs / rhs.z);
         }
 
-        inline friend Vector3 operator + (const Vector3& lhs, const float rhs)
+        friend Vector3 operator+ (const Vector3& lhs, float rhs)
         {
-            return Vector3(
-                lhs.x + rhs,
-                lhs.y + rhs,
-                lhs.z + rhs);
+            return Vector3(lhs.x + rhs, lhs.y + rhs, lhs.z + rhs);
         }
 
-        inline friend Vector3 operator + (const float lhs, const Vector3& rhs)
+        friend Vector3 operator+ (float lhs, const Vector3& rhs)
         {
-            return Vector3(
-                lhs + rhs.x,
-                lhs + rhs.y,
-                lhs + rhs.z);
+            return Vector3(lhs + rhs.x, lhs + rhs.y, lhs + rhs.z);
         }
 
-        inline friend Vector3 operator - (const Vector3& lhs, const float rhs)
+        friend Vector3 operator- (const Vector3& lhs, float rhs)
         {
-            return Vector3(
-                lhs.x - rhs,
-                lhs.y - rhs,
-                lhs.z - rhs);
+            return Vector3(lhs.x - rhs, lhs.y - rhs, lhs.z - rhs);
         }
 
-        inline friend Vector3 operator - (const float lhs, const Vector3& rhs)
+        friend Vector3 operator- (float lhs, const Vector3& rhs)
         {
-            return Vector3(
-                lhs - rhs.x,
-                lhs - rhs.y,
-                lhs - rhs.z);
+            return Vector3(lhs - rhs.x, lhs - rhs.y, lhs - rhs.z);
         }
 
-        // arithmetic updates
-        inline Vector3& operator += ( const Vector3& rkVector )
+        Vector3& operator+= (const Vector3& rhs)
         {
-            x += rkVector.x;
-            y += rkVector.y;
-            z += rkVector.z;
+            x += rhs.x;
+            y += rhs.y;
+            z += rhs.z;
 
             return *this;
         }
 
-        inline Vector3& operator += ( const float fScalar )
+        Vector3& operator+= (float rhs)
         {
-            x += fScalar;
-            y += fScalar;
-            z += fScalar;
+            x += rhs;
+            y += rhs;
+            z += rhs;
+
             return *this;
         }
 
-        inline Vector3& operator -= ( const Vector3& rkVector )
+        Vector3& operator-= (const Vector3& rhs)
         {
-            x -= rkVector.x;
-            y -= rkVector.y;
-            z -= rkVector.z;
+            x -= rhs.x;
+            y -= rhs.y;
+            z -= rhs.z;
 
             return *this;
         }
 
-        inline Vector3& operator -= ( const float fScalar )
+        Vector3& operator-= (float rhs)
         {
-            x -= fScalar;
-            y -= fScalar;
-            z -= fScalar;
+            x -= rhs;
+            y -= rhs;
+            z -= rhs;
+
             return *this;
         }
 
-        inline Vector3& operator *= ( const float fScalar )
+        Vector3& operator*= (float rhs)
         {
-            x *= fScalar;
-            y *= fScalar;
-            z *= fScalar;
+            x *= rhs;
+            y *= rhs;
+            z *= rhs;
+
             return *this;
         }
 
-        inline Vector3& operator *= ( const Vector3& rkVector )
+        Vector3& operator*= (const Vector3& rhs)
         {
-            x *= rkVector.x;
-            y *= rkVector.y;
-            z *= rkVector.z;
+            x *= rhs.x;
+            y *= rhs.y;
+            z *= rhs.z;
 
             return *this;
         }
 
-        inline Vector3& operator /= ( const float fScalar )
+        Vector3& operator/= (float rhs)
         {
-            assert( fScalar != 0.0 );
+            assert(rhs != 0.0f);
 
-            float fInv = 1.0f / fScalar;
+            float inv = 1.0f / rhs;
 
-            x *= fInv;
-            y *= fInv;
-            z *= fInv;
+            x *= inv;
+            y *= inv;
+            z *= inv;
 
             return *this;
         }
 
-        inline Vector3& operator /= ( const Vector3& rkVector )
+        Vector3& operator/= (const Vector3& rhs)
         {
-            x /= rkVector.x;
-            y /= rkVector.y;
-            z /= rkVector.z;
+            x /= rhs.x;
+            y /= rhs.y;
+            z /= rhs.z;
 
             return *this;
         }
 
-
-        /** Returns the length (magnitude) of the vector.
-            @warning
-                This operation requires a square root and is expensive in
-                terms of CPU operations. If you don't need to know the exact
-                length (e.g. for just comparing lengths) use squaredLength()
-                instead.
-        */
-        inline float length () const
+        /**
+         * @brief	Returns the length (magnitude) of the vector.
+         */
+        float length() const
         {
-            return Math::Sqrt( x * x + y * y + z * z );
+            return Math::Sqrt(x * x + y * y + z * z);
         }
 
-        /** Returns the square of the length(magnitude) of the vector.
-            @remarks
-                This  method is for efficiency - calculating the actual
-                length of a vector requires a square root, which is expensive
-                in terms of the operations required. This method returns the
-                square of the length of the vector, i.e. the same as the
-                length but before the square root is taken. Use this if you
-                want to find the longest / shortest vector without incurring
-                the square root.
-        */
-        inline float squaredLength () const
+        /**
+         * @brief	Returns the square of the length(magnitude) of the vector.
+         */
+        float squaredLength() const
         {
             return x * x + y * y + z * z;
         }
 
-        /** Returns the distance to another vector.
-            @warning
-                This operation requires a square root and is expensive in
-                terms of CPU operations. If you don't need to know the exact
-                distance (e.g. for just comparing distances) use squaredDistance()
-                instead.
-        */
-        inline float distance(const Vector3& rhs) const
+        /**
+         * @brief	Returns the distance to another vector.
+         */
+        float distance(const Vector3& rhs) const
         {
             return (*this - rhs).length();
         }
 
-        /** Returns the square of the distance to another vector.
-            @remarks
-                This method is for efficiency - calculating the actual
-                distance to another vector requires a square root, which is
-                expensive in terms of the operations required. This method
-                returns the square of the distance to another vector, i.e.
-                the same as the distance but before the square root is taken.
-                Use this if you want to find the longest / shortest distance
-                without incurring the square root.
-        */
-        inline float squaredDistance(const Vector3& rhs) const
+        /**
+         * @brief	Returns the square of the distance to another vector.
+         */
+        float squaredDistance(const Vector3& rhs) const
         {
             return (*this - rhs).squaredLength();
         }
 
-        /** Calculates the dot (scalar) product of this vector with another.
-            @remarks
-                The dot product can be used to calculate the angle between 2
-                vectors. If both are unit vectors, the dot product is the
-                cosine of the angle; otherwise the dot product must be
-                divided by the product of the lengths of both vectors to get
-                the cosine of the angle. This result can further be used to
-                calculate the distance of a point from a plane.
-            @param
-                vec Vector with which to calculate the dot product (together
-                with this one).
-            @returns
-                A float representing the dot product value.
-        */
-        inline float dotProduct(const Vector3& vec) const
+        /**
+         * @brief	Calculates the dot (scalar) product of this vector with another
+         */
+        float dot(const Vector3& vec) const
         {
             return x * vec.x + y * vec.y + z * vec.z;
         }
 
-        /** Calculates the absolute dot (scalar) product of this vector with another.
-            @remarks
-                This function work similar dotProduct, except it use absolute value
-                of each component of the vector to computing.
-            @param
-                vec Vector with which to calculate the absolute dot product (together
-                with this one).
-            @returns
-                A float representing the absolute dot product value.
-        */
-        inline float absDotProduct(const Vector3& vec) const
-        {
-            return Math::Abs(x * vec.x) + Math::Abs(y * vec.y) + Math::Abs(z * vec.z);
-        }
-
-        /** Normalises the vector.
-            @remarks
-                This method normalises the vector such that it's
-                length / magnitude is 1. The result is called a unit vector.
-            @note
-                This function will not crash for zero-sized vectors, but there
-                will be no changes made to their components.
-            @returns The previous length of the vector.
-        */
-        inline float normalize()
+        /**
+         * @brief	Normalizes the vector.
+         */
+        float normalize()
         {
-            float fLength = Math::Sqrt( x * x + y * y + z * z );
+            float len = Math::Sqrt(x * x + y * y + z * z);
 
             // Will also work for zero-sized vectors, but will change nothing
-            if ( fLength > 1e-08 )
+            if (len > 1e-08)
             {
-                float fInvLength = 1.0f / fLength;
-                x *= fInvLength;
-                y *= fInvLength;
-                z *= fInvLength;
+                float invLen = 1.0f / len;
+                x *= invLen;
+                y *= invLen;
+                z *= invLen;
             }
 
-            return fLength;
-        }
-
-        /** Calculates the cross-product of 2 vectors, i.e. the vector that
-            lies perpendicular to them both.
-            @remarks
-                The cross-product is normally used to calculate the normal
-                vector of a plane, by calculating the cross-product of 2
-                non-equivalent vectors which lie on the plane (e.g. 2 edges
-                of a triangle).
-            @param
-                vec Vector which, together with this one, will be used to
-                calculate the cross-product.
-            @returns
-                A vector which is the result of the cross-product. This
-                vector will <b>NOT</b> be normalised, to maximise efficiency
-                - call Vector3::normalise on the result if you wish this to
-                be done. As for which side the resultant vector will be on, the
-                returned vector will be on the side from which the arc from 'this'
-                to rkVector is anticlockwise, e.g. UNIT_Y.crossProduct(UNIT_Z)
-                = UNIT_X, whilst UNIT_Z.crossProduct(UNIT_Y) = -UNIT_X.
-				This is because engine uses a right-handed coordinate system.
-            @par
-                For a clearer explanation, look a the left and the bottom edges
-                of your monitor's screen. Assume that the first vector is the
-                left edge and the second vector is the bottom edge, both of
-                them starting from the lower-left corner of the screen. The
-                resulting vector is going to be perpendicular to both of them
-                and will go <i>inside</i> the screen, towards the cathode tube
-                (assuming you're using a CRT monitor, of course).
-        */
-        inline Vector3 crossProduct( const Vector3& rkVector ) const
-        {
-            return Vector3(
-                y * rkVector.z - z * rkVector.y,
-                z * rkVector.x - x * rkVector.z,
-                x * rkVector.y - y * rkVector.x);
+            return len;
         }
 
-        /** Returns a vector at a point half way between this and the passed
-            in vector.
-        */
-        inline Vector3 midPoint( const Vector3& vec ) const
+        /**
+		 * @brief	Calculates the cross-product of 2 vectors, i.e. the vector that
+		 *		lies perpendicular to them both.
+         */
+        Vector3 cross(const Vector3& other) const
         {
             return Vector3(
-                ( x + vec.x ) * 0.5f,
-                ( y + vec.y ) * 0.5f,
-                ( z + vec.z ) * 0.5f );
+                y * other.z - z * other.y,
+                z * other.x - x * other.z,
+                x * other.y - y * other.x);
         }
 
-        /** Returns true if the vector's scalar components are all greater
-            that the ones of the vector it is compared against.
-        */
-        inline bool operator < ( const Vector3& rhs ) const
+        /**
+		 * @brief	Sets this vector's components to the minimum of its own and the
+		 *		ones of the passed in vector.
+         */
+        void floor(const Vector3& cmp)
         {
-            if( x < rhs.x && y < rhs.y && z < rhs.z )
-                return true;
-            return false;
+            if(cmp.x < x) x = cmp.x;
+            if(cmp.y < y) y = cmp.y;
+            if(cmp.z < z) z = cmp.z;
         }
 
-        /** Returns true if the vector's scalar components are all smaller
-            that the ones of the vector it is compared against.
-        */
-        inline bool operator > ( const Vector3& rhs ) const
+        /**
+		 * @brief	Sets this vector's components to the maximum of its own and the
+		 *		ones of the passed in vector.
+         */
+        void ceil(const Vector3& cmp)
         {
-            if( x > rhs.x && y > rhs.y && z > rhs.z )
-                return true;
-            return false;
+            if(cmp.x > x) x = cmp.x;
+            if(cmp.y > y) y = cmp.y;
+            if(cmp.z > z) z = cmp.z;
         }
 
-        /** Sets this vector's components to the minimum of its own and the
-            ones of the passed in vector.
-            @remarks
-                'Minimum' in this case means the combination of the lowest
-                value of x, y and z from both vectors. Lowest is taken just
-                numerically, not magnitude, so -1 < 0.
+        /**   
+        *  @brief	Generates a vector perpendicular to this vector.
         */
-        inline void makeFloor( const Vector3& cmp )
+        Vector3 perpendicular() const
         {
-            if( cmp.x < x ) x = cmp.x;
-            if( cmp.y < y ) y = cmp.y;
-            if( cmp.z < z ) z = cmp.z;
-        }
+            static const float squareZero = (float)(1e-06 * 1e-06);
 
-        /** Sets this vector's components to the maximum of its own and the
-            ones of the passed in vector.
-            @remarks
-                'Maximum' in this case means the combination of the highest
-                value of x, y and z from both vectors. Highest is taken just
-                numerically, not magnitude, so 1 > -3.
-        */
-        inline void makeCeil( const Vector3& cmp )
-        {
-            if( cmp.x > x ) x = cmp.x;
-            if( cmp.y > y ) y = cmp.y;
-            if( cmp.z > z ) z = cmp.z;
-        }
+            Vector3 perp = this->cross(Vector3::UNIT_X);
 
-        /** Generates a vector perpendicular to this vector (eg an 'up' vector).
-            @remarks
-                This method will return a vector which is perpendicular to this
-                vector. There are an infinite number of possibilities but this
-                method will guarantee to generate one of them. If you need more
-                control you should use the Quaternion class.
-        */
-        inline Vector3 perpendicular(void) const
-        {
-            static const float fSquareZero = (float)(1e-06 * 1e-06);
-
-            Vector3 perp = this->crossProduct( Vector3::UNIT_X );
+            if(perp.squaredLength() < squareZero)
+                perp = this->cross(Vector3::UNIT_Y);
 
-            // Check length
-            if( perp.squaredLength() < fSquareZero )
-            {
-                /* This vector is the Y axis multiplied by a scalar, so we have
-                   to use another axis.
-                */
-                perp = this->crossProduct( Vector3::UNIT_Y );
-            }
 			perp.normalize();
-
             return perp;
         }
-        /** Generates a new random vector which deviates from this vector by a
-            given angle in a random direction.
-            @remarks
-                This method assumes that the random number generator has already
-                been seeded appropriately.
-            @param
-                angle The angle at which to deviate
-            @param
-                up Any vector perpendicular to this one (which could generated
-                by cross-product of this vector and any other non-colinear
-                vector). If you choose not to provide this the function will
-                derive one on it's own, however if you provide one yourself the
-                function will be faster (this allows you to reuse up vectors if
-                you call this method more than once)
-            @returns
-                A random vector which deviates from this vector by angle. This
-                vector will not be normalised, normalise it if you wish
-                afterwards.
-        */
-        inline Vector3 randomDeviant(
-            const Radian& angle,
-            const Vector3& up = Vector3::ZERO ) const
-        {
-            Vector3 newUp;
-
-            if (up == Vector3::ZERO)
-            {
-                // Generate an up vector
-                newUp = this->perpendicular();
-            }
-            else
-            {
-                newUp = up;
-            }
-
-            // Rotate up vector by random amount around this
-            Quaternion q;
-            q.FromAngleAxis( Radian(Math::UnitRandom() * Math::TWO_PI), *this );
-            newUp = q * newUp;
 
-            // Finally rotate this by given angle around randomised up
-            q.FromAngleAxis( angle, newUp );
-            return q * (*this);
-        }
-
-		/** Gets the angle between 2 vectors.
-		@remarks
-			Vectors do not have to be unit-length but must represent directions.
-		*/
-		inline Radian angleBetween(const Vector3& dest)
+		/**
+		 * @brief	Gets the angle between 2 vectors.
+		 */
+		Radian angleBetween(const Vector3& dest)
 		{
 			float lenProduct = length() * dest.length();
 
@@ -631,50 +377,46 @@ namespace CamelotFramework
 			if(lenProduct < 1e-6f)
 				lenProduct = 1e-6f;
 
-			float f = dotProduct(dest) / lenProduct;
+			float f = dot(dest) / lenProduct;
 
-			f = Math::Clamp(f, (float)-1.0, (float)1.0);
+			f = Math::Clamp(f, -1.0f, 1.0f);
 			return Math::ACos(f);
 
 		}
-        /** Gets the shortest arc quaternion to rotate this vector to the destination
-            vector.
-        @remarks
-            If you call this with a dest vector that is close to the inverse
-            of this vector, we will rotate 180 degrees around the 'fallbackAxis'
-			(if specified, or a generated axis if not) since in this case
-			ANY axis of rotation is valid.
-        */
-        Quaternion getRotationTo(const Vector3& dest,
-			const Vector3& fallbackAxis = Vector3::ZERO) const
+
+        /**
+		 * @brief	Gets the shortest arc quaternion to rotate this vector to the destination
+		 *		vector.
+         */
+        Quaternion getRotationTo(const Vector3& dest, const Vector3& fallbackAxis = Vector3::ZERO) const
         {
             // Based on Stan Melax's article in Game Programming Gems
             Quaternion q;
-            // Copy, since cannot modify local
+
             Vector3 v0 = *this;
             Vector3 v1 = dest;
             v0.normalize();
             v1.normalize();
 
-            float d = v0.dotProduct(v1);
+            float d = v0.dot(v1);
+
             // If dot == 1, vectors are the same
             if (d >= 1.0f)
-            {
                 return Quaternion::IDENTITY;
-            }
+
 			if (d < (1e-6f - 1.0f))
 			{
 				if (fallbackAxis != Vector3::ZERO)
 				{
-					// rotate 180 degrees about the fallback axis
+					// Rotate 180 degrees about the fallback axis
 					q.FromAngleAxis(Radian(Math::PI), fallbackAxis);
 				}
 				else
 				{
 					// Generate an axis
-					Vector3 axis = Vector3::UNIT_X.crossProduct(*this);
-					if (axis.isZeroLength()) // pick another if colinear
-						axis = Vector3::UNIT_Y.crossProduct(*this);
+					Vector3 axis = Vector3::UNIT_X.cross(*this);
+					if (axis.isZeroLength()) // Pick another if colinear
+						axis = Vector3::UNIT_Y.cross(*this);
 					axis.normalize();
 					q.FromAngleAxis(Radian(Math::PI), axis);
 				}
@@ -684,7 +426,7 @@ namespace CamelotFramework
                 float s = Math::Sqrt( (1+d)*2 );
 	            float invs = 1 / s;
 
-				Vector3 c = v0.crossProduct(v1);
+				Vector3 c = v0.cross(v1);
 
     	        q.x = c.x * invs;
         	    q.y = c.y * invs;
@@ -692,79 +434,48 @@ namespace CamelotFramework
             	q.w = s * 0.5f;
 				q.normalize();
 			}
+
             return q;
         }
 
-        /** Returns true if this vector is zero length. */
-        inline bool isZeroLength(void) const
+        /**
+         * @brief	Returns true if this vector is zero length.
+         */
+        bool isZeroLength() const
         {
             float sqlen = (x * x) + (y * y) + (z * z);
             return (sqlen < (1e-06 * 1e-06));
-
-        }
-
-        /** As normalise, except that this vector is unaffected and the
-            normalised vector is returned as a copy. */
-        inline Vector3 normalizedCopy(void) const
-        {
-            Vector3 ret = *this;
-            ret.normalize();
-            return ret;
         }
 
-        /** Calculates a reflection vector to the plane with the given normal .
-        @remarks NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.
-        */
-        inline Vector3 reflect(const Vector3& normal) const
+        /**
+		 * @brief	Calculates a reflection vector to the plane with the given normal.
+         */
+        Vector3 reflect(const Vector3& normal) const
         {
-            return Vector3( *this - ( 2 * this->dotProduct(normal) * normal ) );
+            return Vector3(*this - (2 * this->dot(normal) * normal));
         }
 
-		/** Returns whether this vector is within a positional tolerance
-			of another vector.
-		@param rhs The vector to compare with
-		@param tolerance The amount that each element of the vector may vary by
-			and still be considered equal
-		*/
-		inline bool positionEquals(const Vector3& rhs, float tolerance = 1e-03) const
+		static Vector3 normalize(const Vector3& val)
 		{
-			return Math::RealEqual(x, rhs.x, tolerance) &&
-				Math::RealEqual(y, rhs.y, tolerance) &&
-				Math::RealEqual(z, rhs.z, tolerance);
+			float len = Math::Sqrt(val.x * val.x + val.y * val.y + val.z * val.z);
 
-		}
-
-		/** Returns whether this vector is within a positional tolerance
-			of another vector, also take scale of the vectors into account.
-		@param rhs The vector to compare with
-		@param tolerance The amount (related to the scale of vectors) that distance
-            of the vector may vary by and still be considered close
-		*/
-		inline bool positionCloses(const Vector3& rhs, float tolerance = 1e-03f) const
-		{
-			return squaredDistance(rhs) <=
-                (squaredLength() + rhs.squaredLength()) * tolerance;
-		}
-
-		/** Returns whether this vector is within a directional tolerance
-			of another vector.
-		@param rhs The vector to compare with
-		@param tolerance The maximum angle by which the vectors may vary and
-			still be considered equal
-		@note Both vectors should be normalised.
-		*/
-		inline bool directionEquals(const Vector3& rhs,
-			const Radian& tolerance) const
-		{
-			float dot = dotProduct(rhs);
-			Radian angle = Math::ACos(dot);
+			// Will also work for zero-sized vectors, but will change nothing
+			if (len > 1e-08)
+			{
+				float invLen = 1.0f / len;
 
-			return Math::Abs(angle.valueRadians()) <= tolerance.valueRadians();
+				Vector3 normalizedVec;
+				normalizedVec.x = val.x * invLen;
+				normalizedVec.y = val.y * invLen;
+				normalizedVec.z = val.z * invLen;
 
+				return normalizedVec;
+			}
+			else
+				return val;
 		}
 
-		/// Check whether this vector contains valid values
-		inline bool isNaN() const
+		bool isNaN() const
 		{
 			return Math::isNaN(x) || Math::isNaN(y) || Math::isNaN(z);
 		}
@@ -779,31 +490,12 @@ namespace CamelotFramework
 			return Vector3(std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z));
 		}
 
-		// special points
         static const Vector3 ZERO;
+		static const Vector3 ONE;
         static const Vector3 UNIT_X;
         static const Vector3 UNIT_Y;
         static const Vector3 UNIT_Z;
-		static const Vector3 RIGHT;
-		static const Vector3 UP;
-		static const Vector3 FORWARD;
-        static const Vector3 NEGATIVE_UNIT_X;
-        static const Vector3 NEGATIVE_UNIT_Y;
-        static const Vector3 NEGATIVE_UNIT_Z;
-        static const Vector3 UNIT_SCALE;
-
-        /** Function for writing to a stream.
-        */
-        inline CM_UTILITY_EXPORT friend std::ostream& operator <<
-            ( std::ostream& o, const Vector3& v )
-        {
-            o << "Vector3(" << v.x << ", " << v.y << ", " << v.z << ")";
-            return o;
-        }
     };
-	/** @} */
-	/** @} */
 
 	CM_ALLOW_MEMCPY_SERIALIZATION(Vector3);
 }
-#endif

+ 114 - 230
CamelotUtility/Include/CmVector4.h

@@ -25,74 +25,30 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
-#ifndef __Vector4_H__
-#define __Vector4_H__
+#pragma once
 
 #include "CmPrerequisitesUtil.h"
 #include "CmVector3.h"
 
 namespace CamelotFramework
 {
-	/** \addtogroup Core
-	*  @{
-	*/
-	/** \addtogroup Math
-	*  @{
-	*/
-	/** 4-dimensional homogeneous vector.
-    */
     class CM_UTILITY_EXPORT Vector4
     {
     public:
         float x, y, z, w;
 
     public:
-        inline Vector4()
-        {
-        }
+        Vector4()
+        { }
 
-        inline Vector4( const float fX, const float fY, const float fZ, const float fW )
-            : x( fX ), y( fY ), z( fZ ), w( fW)
-        {
-        }
+        Vector4(float x, float y, float z, float w)
+            :x(x), y(y), z(z), w(w)
+        { }
 
-        inline explicit Vector4( const float afCoordinate[4] )
-            : x( afCoordinate[0] ),
-              y( afCoordinate[1] ),
-              z( afCoordinate[2] ),
-              w( afCoordinate[3] )
-        {
-        }
-
-        inline explicit Vector4( const int afCoordinate[4] )
-        {
-            x = (float)afCoordinate[0];
-            y = (float)afCoordinate[1];
-            z = (float)afCoordinate[2];
-            w = (float)afCoordinate[3];
-        }
-
-        inline explicit Vector4( float* const r )
-            : x( r[0] ), y( r[1] ), z( r[2] ), w( r[3] )
-        {
-        }
-
-        inline explicit Vector4( const float scaler )
-            : x( scaler )
-            , y( scaler )
-            , z( scaler )
-            , w( scaler )
-        {
-        }
-
-        inline explicit Vector4(const Vector3& rhs)
-            : x(rhs.x), y(rhs.y), z(rhs.z), w(1.0f)
-        {
-        }
-
-		/** Exchange the contents of this vector with another. 
-		*/
-		inline void swap(Vector4& other)
+		/**
+		 * @brief	Exchange the contents of this vector with another.
+		 */
+		void swap(Vector4& other)
 		{
 			std::swap(x, other.x);
 			std::swap(y, other.y);
@@ -100,315 +56,243 @@ namespace CamelotFramework
 			std::swap(w, other.w);
 		}
 	
-		inline float operator [] ( const size_t i ) const
+		float operator[] (size_t i) const
         {
-            assert( i < 4 );
+            assert (i < 4);
 
             return *(&x+i);
         }
 
-		inline float& operator [] ( const size_t i )
+		float& operator[] (size_t i)
         {
-            assert( i < 4 );
+            assert(i < 4);
 
             return *(&x+i);
         }
 
-		/// Pointer accessor for direct copying
-		inline float* ptr()
+		float* ptr()
 		{
 			return &x;
 		}
-		/// Pointer accessor for direct copying
-		inline const float* ptr() const
+
+		const float* ptr() const
 		{
 			return &x;
 		}
 
-        /** Assigns the value of the other vector.
-            @param
-                rkVector The other vector
-        */
-        inline Vector4& operator = ( const Vector4& rkVector )
+        Vector4& operator= (const Vector4& rhs)
         {
-            x = rkVector.x;
-            y = rkVector.y;
-            z = rkVector.z;
-            w = rkVector.w;
+            x = rhs.x;
+            y = rhs.y;
+            z = rhs.z;
+            w = rhs.w;
 
             return *this;
         }
 
-		inline Vector4& operator = ( const float fScalar)
+		Vector4& operator= (float rhs)
 		{
-			x = fScalar;
-			y = fScalar;
-			z = fScalar;
-			w = fScalar;
+			x = rhs;
+			y = rhs;
+			z = rhs;
+			w = rhs;
+
 			return *this;
 		}
 
-        inline bool operator == ( const Vector4& rkVector ) const
+        bool operator== (const Vector4& rhs) const
         {
-            return ( x == rkVector.x &&
-                y == rkVector.y &&
-                z == rkVector.z &&
-                w == rkVector.w );
+            return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
         }
 
-        inline bool operator != ( const Vector4& rkVector ) const
+        bool operator!= (const Vector4& rhs) const
         {
-            return ( x != rkVector.x ||
-                y != rkVector.y ||
-                z != rkVector.z ||
-                w != rkVector.w );
+            return (x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w);
         }
 
-        inline Vector4& operator = (const Vector3& rhs)
+        Vector4& operator= (const Vector3& rhs)
         {
             x = rhs.x;
             y = rhs.y;
             z = rhs.z;
             w = 1.0f;
+
             return *this;
         }
 
-        // arithmetic operations
-        inline Vector4 operator + ( const Vector4& rkVector ) const
+        Vector4 operator+ (const Vector4& rhs) const
         {
-            return Vector4(
-                x + rkVector.x,
-                y + rkVector.y,
-                z + rkVector.z,
-                w + rkVector.w);
+            return Vector4(x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w);
         }
 
-        inline Vector4 operator - ( const Vector4& rkVector ) const
+        Vector4 operator- (const Vector4& rhs) const
         {
-            return Vector4(
-                x - rkVector.x,
-                y - rkVector.y,
-                z - rkVector.z,
-                w - rkVector.w);
+            return Vector4(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w);
         }
 
-        inline Vector4 operator * ( const float fScalar ) const
+        Vector4 operator* (float rhs) const
         {
-            return Vector4(
-                x * fScalar,
-                y * fScalar,
-                z * fScalar,
-                w * fScalar);
+            return Vector4(x * rhs, y * rhs, z * rhs, w * rhs);
         }
 
-        inline Vector4 operator * ( const Vector4& rhs) const
+        Vector4 operator* (const Vector4& rhs) const
         {
-            return Vector4(
-                rhs.x * x,
-                rhs.y * y,
-                rhs.z * z,
-                rhs.w * w);
+            return Vector4(rhs.x * x, rhs.y * y, rhs.z * z, rhs.w * w);
         }
 
-        inline Vector4 operator / ( const float fScalar ) const
+        Vector4 operator/ (float rhs) const
         {
-            assert( fScalar != 0.0 );
+            assert(rhs != 0.0f);
 
-            float fInv = 1.0f / fScalar;
-
-            return Vector4(
-                x * fInv,
-                y * fInv,
-                z * fInv,
-                w * fInv);
+            float inv = 1.0f / rhs;
+            return Vector4(x * inv, y * inv, z * inv, w * inv);
         }
 
-        inline Vector4 operator / ( const Vector4& rhs) const
+        Vector4 operator/ (const Vector4& rhs) const
         {
-            return Vector4(
-                x / rhs.x,
-                y / rhs.y,
-                z / rhs.z,
-                w / rhs.w);
+            return Vector4(x / rhs.x, y / rhs.y, z / rhs.z, w / rhs.w);
         }
 
-        inline const Vector4& operator + () const
+        const Vector4& operator+ () const
         {
             return *this;
         }
 
-        inline Vector4 operator - () const
+        Vector4 operator- () const
         {
             return Vector4(-x, -y, -z, -w);
         }
 
-        inline friend Vector4 operator * ( const float fScalar, const Vector4& rkVector )
+        friend Vector4 operator* (float lhs, const Vector4& rhs)
         {
-            return Vector4(
-                fScalar * rkVector.x,
-                fScalar * rkVector.y,
-                fScalar * rkVector.z,
-                fScalar * rkVector.w);
+            return Vector4(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z, lhs * rhs.w);
         }
 
-        inline friend Vector4 operator / ( const float fScalar, const Vector4& rkVector )
+        friend Vector4 operator/ (float lhs, const Vector4& rhs)
         {
-            return Vector4(
-                fScalar / rkVector.x,
-                fScalar / rkVector.y,
-                fScalar / rkVector.z,
-                fScalar / rkVector.w);
+            return Vector4(lhs / rhs.x, lhs / rhs.y, lhs / rhs.z, lhs / rhs.w);
         }
 
-        inline friend Vector4 operator + (const Vector4& lhs, const float rhs)
+        friend Vector4 operator+ (const Vector4& lhs, float rhs)
         {
-            return Vector4(
-                lhs.x + rhs,
-                lhs.y + rhs,
-                lhs.z + rhs,
-                lhs.w + rhs);
+            return Vector4(lhs.x + rhs, lhs.y + rhs, lhs.z + rhs, lhs.w + rhs);
         }
 
-        inline friend Vector4 operator + (const float lhs, const Vector4& rhs)
+        friend Vector4 operator+ (float lhs, const Vector4& rhs)
         {
-            return Vector4(
-                lhs + rhs.x,
-                lhs + rhs.y,
-                lhs + rhs.z,
-                lhs + rhs.w);
+            return Vector4(lhs + rhs.x, lhs + rhs.y, lhs + rhs.z, lhs + rhs.w);
         }
 
-        inline friend Vector4 operator - (const Vector4& lhs, float rhs)
+        friend Vector4 operator- (const Vector4& lhs, float rhs)
         {
-            return Vector4(
-                lhs.x - rhs,
-                lhs.y - rhs,
-                lhs.z - rhs,
-                lhs.w - rhs);
+            return Vector4(lhs.x - rhs, lhs.y - rhs, lhs.z - rhs, lhs.w - rhs);
         }
 
-        inline friend Vector4 operator - (const float lhs, const Vector4& rhs)
+        friend Vector4 operator- (float lhs, Vector4& rhs)
         {
-            return Vector4(
-                lhs - rhs.x,
-                lhs - rhs.y,
-                lhs - rhs.z,
-                lhs - rhs.w);
+            return Vector4(lhs - rhs.x, lhs - rhs.y, lhs - rhs.z, lhs - rhs.w);
         }
 
-        // arithmetic updates
-        inline Vector4& operator += ( const Vector4& rkVector )
+        Vector4& operator+= (const Vector4& rhs)
         {
-            x += rkVector.x;
-            y += rkVector.y;
-            z += rkVector.z;
-            w += rkVector.w;
+            x += rhs.x;
+            y += rhs.y;
+            z += rhs.z;
+            w += rhs.w;
 
             return *this;
         }
 
-        inline Vector4& operator -= ( const Vector4& rkVector )
+        Vector4& operator-= (const Vector4& rhs)
         {
-            x -= rkVector.x;
-            y -= rkVector.y;
-            z -= rkVector.z;
-            w -= rkVector.w;
+            x -= rhs.x;
+            y -= rhs.y;
+            z -= rhs.z;
+            w -= rhs.w;
 
             return *this;
         }
 
-        inline Vector4& operator *= ( const float fScalar )
+        Vector4& operator*= (float rhs)
         {
-            x *= fScalar;
-            y *= fScalar;
-            z *= fScalar;
-            w *= fScalar;
+            x *= rhs;
+            y *= rhs;
+            z *= rhs;
+            w *= rhs;
+
             return *this;
         }
 
-        inline Vector4& operator += ( const float fScalar )
+        Vector4& operator+= (float rhs)
         {
-            x += fScalar;
-            y += fScalar;
-            z += fScalar;
-            w += fScalar;
+            x += rhs;
+            y += rhs;
+            z += rhs;
+            w += rhs;
+
             return *this;
         }
 
-        inline Vector4& operator -= ( const float fScalar )
+        Vector4& operator-= (float rhs)
         {
-            x -= fScalar;
-            y -= fScalar;
-            z -= fScalar;
-            w -= fScalar;
+            x -= rhs;
+            y -= rhs;
+            z -= rhs;
+            w -= rhs;
+
             return *this;
         }
 
-        inline Vector4& operator *= ( const Vector4& rkVector )
+        Vector4& operator*= (Vector4& rhs)
         {
-            x *= rkVector.x;
-            y *= rkVector.y;
-            z *= rkVector.z;
-            w *= rkVector.w;
+            x *= rhs.x;
+            y *= rhs.y;
+            z *= rhs.z;
+            w *= rhs.w;
 
             return *this;
         }
 
-        inline Vector4& operator /= ( const float fScalar )
+        Vector4& operator/= (float rhs)
         {
-            assert( fScalar != 0.0 );
+            assert(rhs != 0.0f);
 
-            float fInv = 1.0f / fScalar;
+            float inv = 1.0f / rhs;
 
-            x *= fInv;
-            y *= fInv;
-            z *= fInv;
-            w *= fInv;
+            x *= inv;
+            y *= inv;
+            z *= inv;
+            w *= inv;
 
             return *this;
         }
 
-        inline Vector4& operator /= ( const Vector4& rkVector )
+        Vector4& operator/= (const Vector4& rhs)
         {
-            x /= rkVector.x;
-            y /= rkVector.y;
-            z /= rkVector.z;
-            w /= rkVector.w;
+            x /= rhs.x;
+            y /= rhs.y;
+            z /= rhs.z;
+            w /= rhs.w;
 
             return *this;
         }
 
-        /** Calculates the dot (scalar) product of this vector with another.
-            @param
-                vec Vector with which to calculate the dot product (together
-                with this one).
-            @returns
-                A float representing the dot product value.
-        */
-        inline float dotProduct(const Vector4& vec) const
+        /**
+         * @brief	Calculates the dot (scalar) product of this vector with another.
+         */
+        float dot(const Vector4& vec) const
         {
             return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
         }
-		/// Check whether this vector contains valid values
-		inline bool isNaN() const
+
+		bool isNaN() const
 		{
 			return Math::isNaN(x) || Math::isNaN(y) || Math::isNaN(z) || Math::isNaN(w);
 		}
-        /** Function for writing to a stream.
-        */
-        inline CM_UTILITY_EXPORT friend std::ostream& operator <<
-            ( std::ostream& o, const Vector4& v )
-        {
-            o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
-            return o;
-        }
-        // special
+
         static const Vector4 ZERO;
     };
-	/** @} */
-	/** @} */
 
 	CM_ALLOW_MEMCPY_SERIALIZATION(Vector4);
 }
-#endif
 

+ 24 - 24
CamelotUtility/Source/CmMath.cpp

@@ -238,14 +238,14 @@ namespace CamelotFramework
 
 		// Note we don't care about normalisation here since sign is all we need
 		// It means we don't have to worry about magnitude of cross products either
-		dot[0] = v1.crossProduct(v2);
+		dot[0] = v1.cross(v2);
 		zeroDot[0] = Math::RealEqual(dot[0], 0.0f, 1e-3f);
 
 
 		v1 = c - b;
 		v2 = p - b;
 
-		dot[1] = v1.crossProduct(v2);
+		dot[1] = v1.cross(v2);
 		zeroDot[1] = Math::RealEqual(dot[1], 0.0f, 1e-3f);
 
 		// Compare signs (ignore colinear / coincident points)
@@ -258,7 +258,7 @@ namespace CamelotFramework
 		v1 = a - c;
 		v2 = p - c;
 
-		dot[2] = v1.crossProduct(v2);
+		dot[2] = v1.cross(v2);
 		zeroDot[2] = Math::RealEqual(dot[2], 0.0f, 1e-3f);
 		// Compare signs (ignore colinear / coincident points)
 		if((!zeroDot[0] && !zeroDot[2] 
@@ -286,14 +286,14 @@ namespace CamelotFramework
 
 		// Note we don't care about normalisation here since sign is all we need
 		// It means we don't have to worry about magnitude of cross products either
-        dot[0] = v1.crossProduct(v2).dotProduct(normal);
+        dot[0] = v1.cross(v2).dot(normal);
 		zeroDot[0] = Math::RealEqual(dot[0], 0.0f, 1e-3f);
 
 
         v1 = c - b;
         v2 = p - b;
 
-		dot[1] = v1.crossProduct(v2).dotProduct(normal);
+		dot[1] = v1.cross(v2).dot(normal);
 		zeroDot[1] = Math::RealEqual(dot[1], 0.0f, 1e-3f);
 
 		// Compare signs (ignore colinear / coincident points)
@@ -306,7 +306,7 @@ namespace CamelotFramework
         v1 = a - c;
         v2 = p - c;
 
-		dot[2] = v1.crossProduct(v2).dotProduct(normal);
+		dot[2] = v1.cross(v2).dot(normal);
 		zeroDot[2] = Math::RealEqual(dot[2], 0.0f, 1e-3f);
 		// Compare signs (ignore colinear / coincident points)
 		if((!zeroDot[0] && !zeroDot[2] 
@@ -333,7 +333,7 @@ namespace CamelotFramework
     std::pair<bool, float> Math::intersects(const Ray& ray, const Plane& plane)
     {
 
-        float denom = plane.normal.dotProduct(ray.getDirection());
+        float denom = plane.normal.dot(ray.getDirection());
         if (Math::Abs(denom) < std::numeric_limits<float>::epsilon())
         {
             // Parallel
@@ -341,7 +341,7 @@ namespace CamelotFramework
         }
         else
         {
-            float nom = plane.normal.dotProduct(ray.getOrigin()) + plane.d;
+            float nom = plane.normal.dot(ray.getOrigin()) + plane.d;
             float t = -(nom/denom);
             return std::pair<bool, float>(t >= 0, t);
         }
@@ -459,9 +459,9 @@ namespace CamelotFramework
         // Mmm, quadratics
         // Build coeffs which can be used with std quadratic solver
         // ie t = (-b +/- sqrt(b*b + 4ac)) / 2a
-        float a = raydir.dotProduct(raydir);
-        float b = 2 * rayorig.dotProduct(raydir);
-        float c = rayorig.dotProduct(rayorig) - radius*radius;
+        float a = raydir.dot(raydir);
+        float b = 2 * rayorig.dot(raydir);
+        float c = rayorig.dot(rayorig) - radius*radius;
 
         // Calc determinant
         float d = (b*b) - (4 * a * c);
@@ -496,7 +496,7 @@ namespace CamelotFramework
 		const Vector3& raydir = ray.getDirection();
 
 		// Check origin inside first
-		if ( rayorig > min && rayorig < max )
+		if ((rayorig.x > min.x && rayorig.y > min.y && rayorig.z > min.z) && (rayorig.x < max.x && rayorig.y < max.y && rayorig.z < max.z))
 		{
 			return std::pair<bool, float>(true, 0.0f);
 		}
@@ -696,7 +696,7 @@ namespace CamelotFramework
         //
         float t;
         {
-            float denom = normal.dotProduct(ray.getDirection());
+            float denom = normal.dot(ray.getDirection());
 
             // Check intersect side
             if (denom > + std::numeric_limits<float>::epsilon())
@@ -716,7 +716,7 @@ namespace CamelotFramework
                 return std::pair<bool, float>(false, 0.0f);
             }
 
-            t = normal.dotProduct(a - ray.getOrigin()) / denom;
+            t = normal.dot(a - ray.getOrigin()) / denom;
 
             if (t < 0)
             {
@@ -836,7 +836,7 @@ namespace CamelotFramework
 	    Vector3 side0 = position1 - position2;
 	    Vector3 side1 = position3 - position1;
 	    //Calculate face normal
-	    Vector3 normal = side1.crossProduct(side0);
+	    Vector3 normal = side1.cross(side0);
 	    normal.normalize();
 	    //Now we use a formula to calculate the tangent. 
 	    float deltaV0 = v1 - v2;
@@ -854,8 +854,8 @@ namespace CamelotFramework
 	    //then we need to reverse the s and t tangents. 
 	    //This is because the triangle has been mirrored when going from tangent space to object space.
 	    //reverse tangents if necessary
-	    Vector3 tangentCross = tangent.crossProduct(binormal);
-	    if (tangentCross.dotProduct(normal) < 0.0f)
+	    Vector3 tangentCross = tangent.cross(binormal);
+	    if (tangentCross.dot(normal) < 0.0f)
 	    {
 		    tangent = -tangent;
 		    binormal = -binormal;
@@ -878,12 +878,12 @@ namespace CamelotFramework
     {
         Vector3 normal = calculateBasicFaceNormal(v1, v2, v3);
         // Now set up the w (distance of tri from origin
-        return Vector4(normal.x, normal.y, normal.z, -(normal.dotProduct(v1)));
+        return Vector4(normal.x, normal.y, normal.z, -(normal.dot(v1)));
     }
     //-----------------------------------------------------------------------
     Vector3 Math::calculateBasicFaceNormal(const Vector3& v1, const Vector3& v2, const Vector3& v3)
     {
-        Vector3 normal = (v2 - v1).crossProduct(v3 - v1);
+        Vector3 normal = (v2 - v1).cross(v3 - v1);
         normal.normalize();
         return normal;
     }
@@ -892,12 +892,12 @@ namespace CamelotFramework
     {
         Vector3 normal = calculateBasicFaceNormalWithoutNormalize(v1, v2, v3);
         // Now set up the w (distance of tri from origin)
-        return Vector4(normal.x, normal.y, normal.z, -(normal.dotProduct(v1)));
+        return Vector4(normal.x, normal.y, normal.z, -(normal.dot(v1)));
     }
     //-----------------------------------------------------------------------
     Vector3 Math::calculateBasicFaceNormalWithoutNormalize(const Vector3& v1, const Vector3& v2, const Vector3& v3)
     {
-        Vector3 normal = (v2 - v1).crossProduct(v3 - v1);
+        Vector3 normal = (v2 - v1).cross(v3 - v1);
         return normal;
     }
 	//-----------------------------------------------------------------------
@@ -956,9 +956,9 @@ namespace CamelotFramework
 		Vector3 min = aabb.getMin();
 
 		Vector3 magnitude = max;
-		magnitude.makeCeil(-max);
-		magnitude.makeCeil(min);
-		magnitude.makeCeil(-min);
+		magnitude.ceil(-max);
+		magnitude.ceil(min);
+		magnitude.ceil(-min);
 
 		return magnitude.length();
 	}

+ 2 - 2
CamelotUtility/Source/CmMatrix3.cpp

@@ -1487,8 +1487,8 @@ namespace CamelotFramework
         }
 
         // make eigenvectors form a right--handed system
-        Vector3 kCross = akEigenvector[1].crossProduct(akEigenvector[2]);
-        float fDet = akEigenvector[0].dotProduct(kCross);
+        Vector3 kCross = akEigenvector[1].cross(akEigenvector[2]);
+        float fDet = akEigenvector[0].dot(kCross);
         if ( fDet < 0.0 )
         {
             akEigenvector[2][0] = - akEigenvector[2][0];

+ 6 - 12
CamelotUtility/Source/CmPlane.cpp

@@ -68,7 +68,7 @@ namespace CamelotFramework {
 	//-----------------------------------------------------------------------
 	float Plane::getDistance (const Vector3& rkPoint) const
 	{
-		return normal.dotProduct(rkPoint) + d;
+		return normal.dot(rkPoint) + d;
 	}
 	//-----------------------------------------------------------------------
 	Plane::Side Plane::getSide (const Vector3& rkPoint) const
@@ -98,7 +98,7 @@ namespace CamelotFramework {
 
         // Calculate the maximise allows absolute distance for
         // the distance between box centre and plane
-        float maxAbsDist = normal.absDotProduct(halfSize);
+        float maxAbsDist = Math::Abs(normal.x * halfSize.x) + Math::Abs(normal.y * halfSize.y) + Math::Abs(normal.z * halfSize.z);
 
         if (dist < -maxAbsDist)
             return Plane::NEGATIVE_SIDE;
@@ -114,15 +114,15 @@ namespace CamelotFramework {
 	{
 		Vector3 kEdge1 = rkPoint1 - rkPoint0;
 		Vector3 kEdge2 = rkPoint2 - rkPoint0;
-		normal = kEdge1.crossProduct(kEdge2);
+		normal = kEdge1.cross(kEdge2);
 		normal.normalize();
-		d = -normal.dotProduct(rkPoint0);
+		d = -normal.dot(rkPoint0);
 	}
 	//-----------------------------------------------------------------------
 	void Plane::redefine(const Vector3& rkNormal, const Vector3& rkPoint)
 	{
 		normal = rkNormal;
-		d = -rkNormal.dotProduct(rkPoint);
+		d = -rkNormal.dot(rkPoint);
 	}
 	//-----------------------------------------------------------------------
 	Vector3 Plane::projectVector(const Vector3& p) const
@@ -156,10 +156,4 @@ namespace CamelotFramework {
 
         return fLength;
     }
-	//-----------------------------------------------------------------------
-	std::ostream& operator<< (std::ostream& o, const Plane& p)
-	{
-		o << "Plane(normal=" << p.normal << ", d=" << p.d << ")";
-		return o;
-	}
-} // namespace CamelotFramework
+}

+ 2 - 2
CamelotUtility/Source/CmQuaternion.cpp

@@ -402,8 +402,8 @@ namespace CamelotFramework {
 		// nVidia SDK implementation
 		Vector3 uv, uuv;
 		Vector3 qvec(x, y, z);
-		uv = qvec.crossProduct(v);
-		uuv = qvec.crossProduct(uv);
+		uv = qvec.cross(v);
+		uuv = qvec.cross(uv);
 		uv *= (2.0f * w);
 		uuv *= 2.0f;
 

+ 4 - 8
CamelotUtility/Source/CmVector2.cpp

@@ -31,12 +31,8 @@ THE SOFTWARE.
 
 namespace CamelotFramework
 {
-    const Vector2 Vector2::ZERO( 0, 0);
-
-    const Vector2 Vector2::UNIT_X( 1, 0);
-    const Vector2 Vector2::UNIT_Y( 0, 1);
-    const Vector2 Vector2::NEGATIVE_UNIT_X( -1,  0);
-    const Vector2 Vector2::NEGATIVE_UNIT_Y(  0, -1);
-    const Vector2 Vector2::UNIT_SCALE(1, 1);
-
+    const Vector2 Vector2::ZERO(0, 0);
+	const Vector2 Vector2::ONE(1, 1);
+	const Vector2 Vector2::UNIT_X(1, 0);
+	const Vector2 Vector2::UNIT_Y(0, 1);
 }

+ 5 - 11
CamelotUtility/Source/CmVector3.cpp

@@ -30,16 +30,10 @@ THE SOFTWARE.
 
 namespace CamelotFramework
 {
-    const Vector3 Vector3::ZERO( 0, 0, 0 );
+    const Vector3 Vector3::ZERO(0, 0, 0);
+	const Vector3 Vector3::ONE(1, 1, 1);
 
-    const Vector3 Vector3::UNIT_X( 1, 0, 0 );
-    const Vector3 Vector3::UNIT_Y( 0, 1, 0 );
-    const Vector3 Vector3::UNIT_Z( 0, 0, 1 );
-	const Vector3 Vector3::RIGHT( 1, 0, 0 );
-	const Vector3 Vector3::UP( 0, 1, 0 );
-	const Vector3 Vector3::FORWARD( 0, 0, -1 );
-    const Vector3 Vector3::NEGATIVE_UNIT_X( -1,  0,  0 );
-    const Vector3 Vector3::NEGATIVE_UNIT_Y(  0, -1,  0 );
-    const Vector3 Vector3::NEGATIVE_UNIT_Z(  0,  0, -1 );
-    const Vector3 Vector3::UNIT_SCALE(1, 1, 1);
+    const Vector3 Vector3::UNIT_X(1, 0, 0);
+    const Vector3 Vector3::UNIT_Y(0, 1, 0);
+    const Vector3 Vector3::UNIT_Z(0, 0, 1);    
 }

+ 140 - 0
MBansheeEngine/Color.cs

@@ -0,0 +1,140 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace BansheeEngine
+{
+    [StructLayout(LayoutKind.Sequential)]
+    public struct Color
+    {
+        public float r;
+        public float g;
+        public float b;
+        public float a;
+
+        public static Color red
+        {
+            get
+            {
+                return new Color(1.0f, 0.0f, 0.0f, 1.0f);
+            }
+        }
+
+        public static Color green
+        {
+            get
+            {
+                return new Color(0.0f, 1.0f, 0.0f, 1.0f);
+            }
+        }
+
+        public static Color blue
+        {
+            get
+            {
+                return new Color(0.0f, 0.0f, 1.0f, 1.0f);
+            }
+        }
+
+        public static Color white
+        {
+            get
+            {
+                return new Color(1.0f, 1.0f, 1.0f, 1.0f);
+            }
+        }
+
+        public static Color black
+        {
+            get
+            {
+                return new Color(0.0f, 0.0f, 0.0f, 1.0f);
+            }
+        }
+
+        public float this[int index]
+        {
+            get
+            {
+                switch (index)
+                {
+                    case 0:
+                        return r;
+                    case 1:
+                        return g;
+                    case 2:
+                        return b;
+                    case 3:
+                        return a;
+                    default:
+                        throw new IndexOutOfRangeException("Invalid Color index.");
+                }
+            }
+            set
+            {
+                switch (index)
+                {
+                    case 0:
+                        r = value;
+                        break;
+                    case 1:
+                        g = value;
+                        break;
+                    case 2:
+                        b = value;
+                        break;
+                    case 3:
+                        a = value;
+                        break;
+                    default:
+                        throw new IndexOutOfRangeException("Invalid Color index.");
+                }
+            }
+        }
+
+        public Color(float r, float g, float b, float a)
+        {
+            this.r = r;
+            this.g = g;
+            this.b = b;
+            this.a = a;
+        }
+
+        public Color(float r, float g, float b)
+        {
+            this.r = r;
+            this.g = g;
+            this.b = b;
+            this.a = 1f;
+        }
+
+        public static Color operator+ (Color a, Color b)
+        {
+            return new Color(a.r + b.r, a.g + b.g, a.b + b.b, a.a + b.a);
+        }
+
+        public static Color operator- (Color a, Color b)
+        {
+            return new Color(a.r - b.r, a.g - b.g, a.b - b.b, a.a - b.a);
+        }
+
+        public static Color operator* (Color a, Color b)
+        {
+            return new Color(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);
+        }
+
+        public static Color operator* (Color a, float b)
+        {
+            return new Color(a.r * b, a.g * b, a.b * b, a.a * b);
+        }
+
+        public static Color operator* (float b, Color a)
+        {
+            return new Color(a.r * b, a.g * b, a.b * b, a.a * b);
+        }
+
+        public static Color operator/ (Color a, float b)
+        {
+            return new Color(a.r / b, a.g / b, a.b / b, a.a / b);
+        }
+    }
+}

+ 6 - 1
MBansheeEngine/MBansheeEngine.csproj

@@ -7,7 +7,7 @@
     <ProjectGuid>{876EB338-489E-4727-84DA-8CBBF0DA5B5E}</ProjectGuid>
     <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>MBansheeEngine</RootNamespace>
+    <RootNamespace>BansheeEngine</RootNamespace>
     <AssemblyName>MBansheeEngine</AssemblyName>
     <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
@@ -40,11 +40,16 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Color.cs" />
+    <Compile Include="MathEx.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="ScriptObject.cs" />
     <Compile Include="Texture2D.cs" />
     <Compile Include="TextureFormat.cs" />
+    <Compile Include="Vector2.cs" />
+    <Compile Include="Vector3.cs" />
+    <Compile Include="Vector4.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 244 - 0
MBansheeEngine/MathEx.cs

@@ -0,0 +1,244 @@
+using System;
+
+namespace BansheeEngine
+{
+    class MathEx
+    {
+        public static float Min(float a, float b)
+        {
+            if (a < b)
+                return a;
+            
+            return b;
+        }
+
+        public static float Min(params float[] values)
+        {
+            int length = values.Length;
+            if (length == 0)
+                return 0.0f;
+
+            float min = values[0];
+            for (int i = 1; i < length; i++)
+            {
+                if (values[i] < min)
+                    min = values[i];
+            }
+
+            return min;
+        }
+
+        public static int Min(int a, int b)
+        {
+            if (a < b)
+                return a;
+
+            return b;
+        }
+
+        public static int Min(params int[] values)
+        {
+            int length = values.Length;
+            if (length == 0)
+                return 0;
+
+            int min = values[0];
+            for (int i = 1; i < length; i++)
+            {
+                if (values[i] < min)
+                    min = values[i];
+            }
+
+            return min;
+        }
+
+        public static float Max(float a, float b)
+        {
+            if (a > b)
+                return a;
+
+            return b;
+        }
+
+        public static float Max(params float[] values)
+        {
+            int length = values.Length;
+            if (length == 0)
+                return 0.0f;
+
+            float max = values[0];
+            for (int i = 1; i < length; i++)
+            {
+                if (values[i] > max)
+                    max = values[i];
+            }
+
+            return max;
+        }
+
+        public static int Max(int a, int b)
+        {
+            if (a > b)
+                return a;
+            else
+                return b;
+        }
+
+        public static int Max(params int[] values)
+        {
+            int length = values.Length;
+            if (length == 0)
+                return 0;
+
+            int max = values[0];
+            for (int i = 1; i < length; ++i)
+            {
+                if (values[i] > max)
+                    max = values[i];
+            }
+
+            return max;
+        }
+
+        public static float Abs(float f)
+        {
+            return Math.Abs(f);
+        }
+
+        public static int Abs(int value)
+        {
+            return Math.Abs(value);
+        }
+
+        public static float Pow(float f, float p)
+        {
+            return (float)Math.Pow(f, p);
+        }
+
+        public static float Exp(float power)
+        {
+            return (float)Math.Exp(power);
+        }
+
+        public static float Log(float f, float p)
+        {
+            return (float)Math.Log(f, p);
+        }
+
+        public static float Log(float f)
+        {
+            return (float)Math.Log(f);
+        }
+
+        public static float Log10(float f)
+        {
+            return (float)Math.Log10(f);
+        }
+
+        public static float Ceil(float f)
+        {
+            return (float)Math.Ceiling(f);
+        }
+
+        public static float Floor(float f)
+        {
+            return (float)Math.Floor(f);
+        }
+
+        public static float Round(float f)
+        {
+            return (float)Math.Round(f);
+        }
+
+        public static int CeilToInt(float f)
+        {
+            return (int)Math.Ceiling(f);
+        }
+
+        public static int FloorToInt(float f)
+        {
+            return (int)Math.Floor(f);
+        }
+
+        public static int RoundToInt(float f)
+        {
+            return (int)Math.Round(f);
+        }
+
+        public static float Sign(float f)
+        {
+            return f >= 0.0f ? 1.0f : -1.0f;
+        }
+
+        public static float Sin(float f)
+        {
+            return (float)Math.Sin(f);
+        }
+
+        public static float Cos(float f)
+        {
+            return (float)Math.Cos(f);
+        }
+
+        public static float Tan(float f)
+        {
+            return (float)Math.Tan(f);
+        }
+
+        public static float Asin(float f)
+        {
+            return (float)Math.Asin(f);
+        }
+
+        public static float Acos(float f)
+        {
+            return (float)Math.Acos(f);
+        }
+
+        public static float Atan(float f)
+        {
+            return (float)Math.Atan(f);
+        }
+
+        public static float Atan2(float y, float x)
+        {
+            return (float)Math.Atan2(y, x);
+        }
+
+        public static float Sqrt(float f)
+        {
+            return (float)Math.Sqrt(f);
+        }
+
+        public static float Clamp(float value, float min, float max)
+        {
+            if (value < min)
+                value = min;
+            else if (value > max)
+                value = max;
+
+            return value;
+        }
+
+        public static int Clamp(int value, int min, int max)
+        {
+            if (value < min)
+                value = min;
+            else if (value > max)
+                value = max;
+
+            return value;
+        }
+
+        public static float Clamp01(float value)
+        {
+            if (value < 0.0)
+                return 0.0f;
+
+            if (value > 1.0)
+                return 1f;
+            
+            return value;
+        }
+    }
+}

+ 169 - 0
MBansheeEngine/Vector2.cs

@@ -0,0 +1,169 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace BansheeEngine
+{
+    [StructLayout(LayoutKind.Sequential)]
+    public struct Vector2
+    {
+        public float x;
+        public float y;
+
+        public static Vector2 zero
+        {
+            get
+            {
+                return new Vector2(0.0f, 0.0f);
+            }
+        }
+
+        public static Vector2 one
+        {
+            get
+            {
+                return new Vector2(1.0f, 1.0f);
+            }
+        }
+
+        public float this[int index]
+        {
+            get
+            {
+                switch (index)
+                {
+                    case 0:
+                        return x;
+                    case 1:
+                        return y;
+                    default:
+                        throw new IndexOutOfRangeException("Invalid Vector2 index.");
+                }
+            }
+
+            set
+            {
+                switch (index)
+                {
+                    case 0:
+                        x = value;
+                        break;
+                    case 1:
+                        y = value;
+                        break;
+                    default:
+                        throw new IndexOutOfRangeException("Invalid Vector2 index.");
+                }
+            }
+        }
+
+        public Vector2 normalized
+        {
+            get
+            {
+                return Normalize(this);
+            }
+        }
+
+        public float magnitude
+        {
+            get
+            {
+                return MathEx.Sqrt(x * x + y * y);
+            }
+        }
+
+        public float sqrdMagnitude
+        {
+            get
+            {
+                return (x * x + y * y);
+            }
+        }
+
+        public Vector2(float x, float y)
+        {
+            this.x = x;
+            this.y = y;
+        }
+
+        public static Vector2 operator+ (Vector2 a, Vector2 b)
+        {
+            return new Vector2(a.x + b.x, a.y + b.y);
+        }
+
+        public static Vector2 operator- (Vector2 a, Vector2 b)
+        {
+            return new Vector2(a.x - b.x, a.y - b.y);
+        }
+
+        public static Vector2 operator- (Vector2 v)
+        {
+            return new Vector2(-v.x, -v.y);
+        }
+
+        public static Vector2 operator* (Vector2 v, float d)
+        {
+            return new Vector2(v.x * d, v.y * d);
+        }
+
+        public static Vector2 operator* (float d, Vector2 v)
+        {
+            return new Vector2(v.x * d, v.y * d);
+        }
+
+        public static Vector2 operator/ (Vector2 v, float d)
+        {
+            return new Vector2(v.x / d, v.y / d);
+        }
+
+        public static Vector2 Scale(Vector2 a, Vector2 b)
+        {
+            return new Vector2(a.x * b.x, a.y * b.y);
+        }
+
+        public static Vector2 Normalize(Vector2 value)
+        {
+            float num = Magnitude(value);
+            if (num > 9.999999E-06f)
+                return value / num;
+
+            return zero;
+        }
+
+        public static float Dot(Vector2 lhs, Vector2 rhs)
+        {
+            return lhs.x * rhs.x + lhs.y * rhs.y;
+        }
+
+        public static float Distance(Vector2 a, Vector2 b)
+        {
+            Vector2 vector2 = new Vector2(a.x - b.x, a.y - b.y);
+            return MathEx.Sqrt(vector2.x * vector2.x + vector2.y * vector2.y);
+        }
+
+        public static float Magnitude(Vector2 v)
+        {
+            return MathEx.Sqrt(v.x * v.x + v.y * v.y);
+        }
+
+        public static float SqrMagnitude(Vector2 v)
+        {
+            return (v.x * v.x + v.y * v.y);
+        }
+
+        public void Scale(Vector2 scale)
+        {
+            x *= scale.x;
+            y *= scale.y;
+        }
+
+        public void Normalize()
+        {
+            float num = Magnitude(this);
+            if (num > 9.999999E-06f)
+                this /= num;
+            else
+                this = zero;
+        }
+    }
+}

+ 182 - 0
MBansheeEngine/Vector3.cs

@@ -0,0 +1,182 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace BansheeEngine
+{
+    [StructLayout(LayoutKind.Sequential)]
+    public struct Vector3
+    {
+        public float x;
+        public float y;
+        public float z;
+
+        public static Vector3 zero
+        {
+            get
+            {
+                return new Vector3(0.0f, 0.0f, 0.0f);
+            }
+        }
+
+        public static Vector3 one
+        {
+            get
+            {
+                return new Vector3(1.0f, 1.0f, 1.0f);
+            }
+        }
+
+        public float this[int index]
+        {
+            get
+            {
+                switch (index)
+                {
+                    case 0:
+                        return x;
+                    case 1:
+                        return y;
+                    case 2:
+                        return z;
+                    default:
+                        throw new IndexOutOfRangeException("Invalid Vector3 index.");
+                }
+            }
+
+            set
+            {
+                switch (index)
+                {
+                    case 0:
+                        x = value;
+                        break;
+                    case 1:
+                        y = value;
+                        break;
+                    case 2:
+                        z = value;
+                        break;
+                    default:
+                        throw new IndexOutOfRangeException("Invalid Vector3 index.");
+                }
+            }
+        }
+
+        public Vector3 normalized
+        {
+            get
+            {
+                return Normalize(this);
+            }
+        }
+
+        public float magnitude
+        {
+            get
+            {
+                return MathEx.Sqrt(x * x + y * y + z * z);
+            }
+        }
+
+        public float sqrdMagnitude
+        {
+            get
+            {
+                return (x * x + y * y + z * z);
+            }
+        }
+
+        public Vector3(float x, float y, float z)
+        {
+            this.x = x;
+            this.y = y;
+            this.z = z;
+        }
+
+        public static Vector3 operator+ (Vector3 a, Vector3 b)
+        {
+            return new Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
+        }
+
+        public static Vector3 operator- (Vector3 a, Vector3 b)
+        {
+            return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
+        }
+
+        public static Vector3 operator- (Vector3 v)
+        {
+            return new Vector3(-v.x, -v.y, -v.z);
+        }
+
+        public static Vector3 operator* (Vector3 v, float d)
+        {
+            return new Vector3(v.x * d, v.y * d, v.z * d);
+        }
+
+        public static Vector3 operator* (float d, Vector3 v)
+        {
+            return new Vector3(v.x * d, v.y * d, v.z * d);
+        }
+
+        public static Vector3 operator/ (Vector3 v, float d)
+        {
+            return new Vector3(v.x / d, v.y / d, v.z / d);
+        }
+
+        public static Vector3 Scale(Vector3 a, Vector3 b)
+        {
+            return new Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
+        }
+
+        public static Vector3 Cross(Vector3 lhs, Vector3 rhs)
+        {
+            return new Vector3(lhs.y * rhs.z - lhs.z * rhs.y, lhs.z * rhs.x - lhs.x * rhs.z, lhs.x * rhs.y - lhs.y * rhs.x);
+        }
+
+        public static Vector3 Normalize(Vector3 value)
+        {
+            float num = Magnitude(value);
+            if (num > 9.999999E-06)
+                return value / num;
+            
+            return zero;
+        }
+
+        public static float Dot(Vector3 lhs, Vector3 rhs)
+        {
+            return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
+        }
+
+        public static float Distance(Vector3 a, Vector3 b)
+        {
+            Vector3 vector3 = new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
+            return MathEx.Sqrt(vector3.x * vector3.x + vector3.y * vector3.y + vector3.z * vector3.z);
+        }
+
+        public static float Magnitude(Vector3 v)
+        {
+            return MathEx.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
+        }
+
+        public static float SqrMagnitude(Vector3 v)
+        {
+            return (v.x * v.x + v.y * v.y + v.z * v.z);
+        }
+
+        public void Scale(Vector3 scale)
+        {
+            x *= scale.x;
+            y *= scale.y;
+            z *= scale.z;
+        }
+
+        public void Normalize()
+        {
+            float num = Magnitude(this);
+            if (num > 9.999999E-06)
+                this /= num;
+            else
+                this = zero;
+        }
+    }
+}

+ 185 - 0
MBansheeEngine/Vector4.cs

@@ -0,0 +1,185 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace BansheeEngine
+{
+    [StructLayout(LayoutKind.Sequential)]
+    public struct Vector4
+    {
+        public float x;
+        public float y;
+        public float z;
+        public float w;
+
+        public static Vector4 zero
+        {
+            get
+            {
+                return new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
+            }
+        }
+
+        public static Vector4 one
+        {
+            get
+            {
+                return new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
+            }
+        }
+
+        public float this[int index]
+        {
+            get
+            {
+                switch (index)
+                {
+                    case 0:
+                        return x;
+                    case 1:
+                        return y;
+                    case 2:
+                        return z;
+                    case 3:
+                        return w;
+                    default:
+                        throw new IndexOutOfRangeException("Invalid Vector4 index.");
+                }
+            }
+
+            set
+            {
+                switch (index)
+                {
+                    case 0:
+                        x = value;
+                        break;
+                    case 1:
+                        y = value;
+                        break;
+                    case 2:
+                        z = value;
+                        break;
+                    case 3:
+                        w = value;
+                        break;
+                    default:
+                        throw new IndexOutOfRangeException("Invalid Vector4 index.");
+                }
+            }
+        }
+
+        public Vector4 normalized
+        {
+            get
+            {
+                return Normalize(this);
+            }
+        }
+
+        public float magnitude
+        {
+            get
+            {
+                return MathEx.Sqrt(x * x + y * y + z * z + w * w);
+            }
+        }
+
+        public float sqrdMagnitude
+        {
+            get
+            {
+                return (x * x + y * y + z * z + w * w);
+            }
+        }
+
+        public Vector4(float x, float y, float z, float w)
+        {
+            this.x = x;
+            this.y = y;
+            this.z = z;
+            this.w = w;
+        }
+
+        public static Vector4 operator+ (Vector4 a, Vector4 b)
+        {
+            return new Vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
+        }
+
+        public static Vector4 operator- (Vector4 a, Vector4 b)
+        {
+            return new Vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
+        }
+
+        public static Vector4 operator- (Vector4 v)
+        {
+            return new Vector4(-v.x, -v.y, -v.z, -v.w);
+        }
+
+        public static Vector4 operator* (Vector4 v, float d)
+        {
+            return new Vector4(v.x * d, v.y * d, v.z * d, v.w * d);
+        }
+
+        public static Vector4 operator* (float d, Vector4 v)
+        {
+            return new Vector4(v.x * d, v.y * d, v.z * d, v.w * d);
+        }
+
+        public static Vector4 operator /(Vector4 v, float d)
+        {
+            return new Vector4(v.x / d, v.y / d, v.z / d, v.w / d);
+        }
+
+        public static Vector4 Scale(Vector4 a, Vector4 b)
+        {
+            return new Vector4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
+        }
+
+        public static Vector4 Normalize(Vector4 value)
+        {
+            float num = Magnitude(value);
+            if (num > 9.999999E-06)
+                return value / num;
+
+            return zero;
+        }
+
+        public static float Dot(Vector4 lhs, Vector4 rhs)
+        {
+            return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z + lhs.w * rhs.w;
+        }
+
+        public static float Distance(Vector4 a, Vector4 b)
+        {
+            Vector4 vector4 = new Vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
+            return MathEx.Sqrt(vector4.x * vector4.x + vector4.y * vector4.y + vector4.z * vector4.z + vector4.w * vector4.w);
+        }
+
+        public static float Magnitude(Vector4 v)
+        {
+            return MathEx.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
+        }
+
+        public static float SqrMagnitude(Vector4 v)
+        {
+            return (v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
+        }
+
+        public void Scale(Vector4 scale)
+        {
+            x *= scale.x;
+            y *= scale.y;
+            z *= scale.z;
+            w *= scale.w;
+        }
+
+        public void Normalize()
+        {
+            float num = Magnitude(this);
+            if (num > 9.999999E-06)
+                this /= num;
+            else
+                this = zero;
+        }
+    }
+}