Browse Source

Documentation

BearishSun 10 years ago
parent
commit
3c0a5a5996

+ 27 - 2
BansheeUtility/Include/BsAABox.h

@@ -23,7 +23,7 @@ namespace BansheeEngine
 		|/    |/
 		|/    |/
 		6-----7
 		6-----7
 		*/
 		*/
-		typedef enum CornerEnum {
+		enum CornerEnum {
 			FAR_LEFT_BOTTOM = 0,
 			FAR_LEFT_BOTTOM = 0,
 			FAR_LEFT_TOP = 1,
 			FAR_LEFT_TOP = 1,
 			FAR_RIGHT_TOP = 2,
 			FAR_RIGHT_TOP = 2,
@@ -41,16 +41,41 @@ namespace BansheeEngine
 		AABox& operator=(const AABox& rhs);
 		AABox& operator=(const AABox& rhs);
 
 
 		~AABox() { }
 		~AABox() { }
-
+		
+		/**
+		 * @brief	Gets the corner of the box with minimum values (opposite to maximum corner).
+		 */
 		const Vector3& getMin() const { return mMinimum; }
 		const Vector3& getMin() const { return mMinimum; }
+
+		/**
+		 * @brief	Gets the corner of the box with maximum values (opposite to minimum corner).
+		 */
 		const Vector3& getMax() const { return mMaximum; }
 		const Vector3& getMax() const { return mMaximum; }
 
 
+		/**
+		 * @brief	Sets the corner of the box with minimum values (opposite to maximum corner).
+		 */
 		void setMin(const Vector3& vec) { mMinimum = vec; }
 		void setMin(const Vector3& vec) { mMinimum = vec; }
+
+		/**
+		 * @brief	Sets the corner of the box with maximum values (opposite to minimum corner).
+		 */
 		void setMax(const Vector3& vec) { mMaximum = vec; }
 		void setMax(const Vector3& vec) { mMaximum = vec; }
 
 
+		/**
+		 * @brief	Sets the minimum and maximum corners.
+		 */
 		void setExtents(const Vector3& min, const Vector3& max);
 		void setExtents(const Vector3& min, const Vector3& max);
+
+		/**
+		 * @brief	Scales the box around the center by multiplying
+		 * 			its extends with the provided scale.
+		 */
 		void scale(const Vector3& s);
 		void scale(const Vector3& s);
 
 
+		/**
+		 * @brief	Returns the coordinates of a specific corner.
+		 */
 		Vector3 getCorner(CornerEnum cornerToGet) const;
 		Vector3 getCorner(CornerEnum cornerToGet) const;
 
 
 		/**
 		/**

+ 1 - 1
BansheeUtility/Include/BsFwdDeclUtil.h

@@ -6,7 +6,7 @@ namespace BansheeEngine
 {
 {
 	/**
 	/**
 	 * @brief	Values that represent in which order are euler
 	 * @brief	Values that represent in which order are euler
-	 * 			angles applied when used in transformations
+	 * 			angles applied when used in transformations.
 	 */
 	 */
 	enum class EulerAngleOrder
 	enum class EulerAngleOrder
 	{
 	{

+ 8 - 7
BansheeUtility/Include/BsMatrix3.h

@@ -6,7 +6,8 @@
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
     /**
     /**
-     * @brief	Class representing a 3x3 matrix.
+     * @brief	A 3x3 matrix. Can be used for non-homogenous transformations
+     *          of three dimensional vectors and points.
      */
      */
     class BS_UTILITY_EXPORT Matrix3
     class BS_UTILITY_EXPORT Matrix3
     {
     {
@@ -203,12 +204,12 @@ namespace BansheeEngine
         void singularValueDecomposition(Matrix3& matL, Vector3& matS, Matrix3& matR) const;
         void singularValueDecomposition(Matrix3& matL, Vector3& matS, Matrix3& matR) const;
 
 
         /**
         /**
-         * @brief	Decomposes the matrix into various useful values.
+         * @brief	Decomposes the matrix into a set of values.
          *
          *
          * @param [out]	matQ	Columns form orthonormal bases. If your matrix is affine and
          * @param [out]	matQ	Columns form orthonormal bases. If your matrix is affine and
          * 						doesn't use non-uniform scaling this matrix will be the rotation part of the matrix.
          * 						doesn't use non-uniform scaling this matrix will be the rotation part of the matrix.
-         * @param [out]	vecD	If your matrix is affine these will be scaling factors of the matrix.
-		 * @param [out]	vecU	If your matrix is affine these will be shear factors of the matrix.
+         * @param [out]	vecD	If the matrix is affine these will be scaling factors of the matrix.
+		 * @param [out]	vecU	If the matrix is affine these will be shear factors of the matrix.
          */
          */
 		void QDUDecomposition(Matrix3& matQ, Vector3& vecD, Vector3& vecU) const;
 		void QDUDecomposition(Matrix3& matQ, Vector3& vecD, Vector3& vecU) const;
 
 
@@ -247,7 +248,7 @@ namespace BansheeEngine
 		void fromAxes(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
 		void fromAxes(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
 
 
         /**
         /**
-         * @brief	Extracts Pitch/Yaw/Roll rotations from this matrix.
+         * @brief	Converts an orthonormal matrix to euler angle (pitch/yaw/roll) representation.
          *
          *
          * @param [in,out]	xAngle	Rotation about x axis. (AKA Pitch)
          * @param [in,out]	xAngle	Rotation about x axis. (AKA Pitch)
          * @param [in,out]	yAngle  Rotation about y axis. (AKA Yaw)
          * @param [in,out]	yAngle  Rotation about y axis. (AKA Yaw)
@@ -278,8 +279,8 @@ namespace BansheeEngine
 		 * @param	xAngle	Rotation about x axis. (AKA Pitch)
 		 * @param	xAngle	Rotation about x axis. (AKA Pitch)
 		 * @param	yAngle	Rotation about y axis. (AKA Yaw)
 		 * @param	yAngle	Rotation about y axis. (AKA Yaw)
 		 * @param	zAngle	Rotation about z axis. (AKA Roll)
 		 * @param	zAngle	Rotation about z axis. (AKA Roll)
-		 * @param	order 	The order in which rotations will be extracted.
-		 * 					Different values can be retrieved depending on the order.
+		 * @param	order 	The order in which rotations will be applied.
+		 * 					Different rotations can be created depending on the order.
          *
          *
          * @note	Matrix must be orthonormal.
          * @note	Matrix must be orthonormal.
          */
          */

+ 6 - 4
BansheeUtility/Include/BsQuaternion.h

@@ -169,17 +169,17 @@ namespace BansheeEngine
         bool toEulerAngles(Radian& xAngle, Radian& yAngle, Radian& zAngle) const;
         bool toEulerAngles(Radian& xAngle, Radian& yAngle, Radian& zAngle) const;
 
 
         /**
         /**
-         * @brief	Get the local x-axis.
+         * @brief	Gets the positive x-axis of the coordinate system transformed by this quaternion.
          */
          */
         Vector3 xAxis() const;
         Vector3 xAxis() const;
 
 
         /**
         /**
-         * @brief	Get the local y-axis.
+         * @brief	Gets the positive y-axis of the coordinate system transformed by this quaternion.
          */
          */
         Vector3 yAxis() const;
         Vector3 yAxis() const;
 
 
 		/**
 		/**
-         * @brief	Get the local z-axis.
+         * @brief	Gets the positive z-axis of the coordinate system transformed by this quaternion.
          */
          */
         Vector3 zAxis() const;
         Vector3 zAxis() const;
 
 
@@ -242,7 +242,9 @@ namespace BansheeEngine
 		}
 		}
 
 
         /**
         /**
-         * @brief	Spherical linear interpolation
+         * @brief	Performs spherical interpolation between two quaternions. Spherical interpolation 
+         *          neatly interpolates between two rotations without modifying the size of the vector 
+         *          it is applied to (unlike linear interpolation).
          */
          */
         static Quaternion slerp(float t, const Quaternion& p,
         static Quaternion slerp(float t, const Quaternion& p,
             const Quaternion& q, bool shortestPath = false);
             const Quaternion& q, bool shortestPath = false);

+ 2 - 2
BansheeUtility/Include/BsRect3.h

@@ -49,12 +49,12 @@ namespace BansheeEngine
 		const Vector3& getCenter() const { return mCenter; }
 		const Vector3& getCenter() const { return mCenter; }
 
 
 		/**
 		/**
-		 * @brief	Returns the rectangles horizontal axis.
+		 * @brief	Returns the rectangle's horizontal axis.
 		 */
 		 */
 		const Vector3& getAxisHorz() const { return mAxisHorz; }
 		const Vector3& getAxisHorz() const { return mAxisHorz; }
 
 
 		/**
 		/**
-		 * @brief	Returns the rectangles vertical axis.
+		 * @brief	Returns the rectangle's vertical axis.
 		 */
 		 */
 		const Vector3& getAxisVert() const { return mAxisVert; }
 		const Vector3& getAxisVert() const { return mAxisVert; }
 
 

+ 2 - 2
MBansheeEditor/Scene/DefaultHandleManager.cs

@@ -73,7 +73,7 @@ namespace BansheeEditor
             {
             {
                 Quaternion rotation;
                 Quaternion rotation;
                 if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
                 if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
-                    rotation = Quaternion.identity;
+                    rotation = Quaternion.Identity;
                 else
                 else
                     rotation = selectedSceneObjects[0].Rotation; // We don't average rotation in case of multi-selection
                     rotation = selectedSceneObjects[0].Rotation; // We don't average rotation in case of multi-selection
 
 
@@ -87,7 +87,7 @@ namespace BansheeEditor
                         flatenedHierarchy.AddRange(EditorUtility.FlattenHierarchy(so));
                         flatenedHierarchy.AddRange(EditorUtility.FlattenHierarchy(so));
 
 
                     AABox selectionBounds = EditorUtility.CalculateBounds(flatenedHierarchy.ToArray());
                     AABox selectionBounds = EditorUtility.CalculateBounds(flatenedHierarchy.ToArray());
-                    position = selectionBounds.center;
+                    position = selectionBounds.Center;
                 }
                 }
 
 
                 activeHandle.Position = position;
                 activeHandle.Position = position;

+ 1 - 1
MBansheeEditor/Scene/HandleDrawing.cs

@@ -67,7 +67,7 @@ namespace BansheeEditor
 
 
         public static void DrawRect(Rect3 area, float size = 1.0f)
         public static void DrawRect(Rect3 area, float size = 1.0f)
         {
         {
-            Internal_DrawRect(area.center, area.axisHorz, area.axisVert, area.extentHorz, area.extentVert, size);
+            Internal_DrawRect(area.Center, area.AxisHorz, area.AxisVert, area.ExtentHorz, area.ExtentVert, size);
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]

+ 3 - 3
MBansheeEditor/Scene/RotateHandle.cs

@@ -67,7 +67,7 @@ namespace BansheeEditor
             else
             else
             {
             {
                 isDragged = false;
                 isDragged = false;
-                dragStartRotation = Quaternion.identity;
+                dragStartRotation = Quaternion.Identity;
             }
             }
 
 
             Degree xValue = 0.0f;
             Degree xValue = 0.0f;
@@ -132,7 +132,7 @@ namespace BansheeEditor
             // Draw "bounds" and free handle
             // Draw "bounds" and free handle
             Color gray = new Color(1.0f, 1.0f, 1.0f, 0.3f);
             Color gray = new Color(1.0f, 1.0f, 1.0f, 0.3f);
             Vector3 cameraNormal = EditorApplication.SceneViewCamera.SceneObject.Rotation.Rotate(Vector3.zAxis);
             Vector3 cameraNormal = EditorApplication.SceneViewCamera.SceneObject.Rotation.Rotate(Vector3.zAxis);
-            HandleDrawing.SetTransform(Matrix4.TRS(Position, Quaternion.identity, Vector3.one));
+            HandleDrawing.SetTransform(Matrix4.TRS(Position, Quaternion.Identity, Vector3.one));
             HandleDrawing.SetColor(gray);
             HandleDrawing.SetColor(gray);
 
 
             HandleDrawing.DrawWireDisc(cameraNormal * 0.1f, cameraNormal, 1.0f, handleSize);
             HandleDrawing.DrawWireDisc(cameraNormal * 0.1f, cameraNormal, 1.0f, handleSize);
@@ -192,7 +192,7 @@ namespace BansheeEditor
             Quaternion rot = Quaternion.FromToRotation(up, Vector3.yAxis);
             Quaternion rot = Quaternion.FromToRotation(up, Vector3.yAxis);
 
 
             Matrix4 worldToPlane = Matrix4.TRS(Vector3.zero, rot, Vector3.one);
             Matrix4 worldToPlane = Matrix4.TRS(Vector3.zero, rot, Vector3.one);
-            point = worldToPlane.MultiplyAffine(point);
+            point = worldToPlane.MultiplyDirection(point);
 
 
             return (MathEx.Atan2(-point.z, -point.x) + MathEx.Pi) * MathEx.Rad2Deg;
             return (MathEx.Atan2(-point.z, -point.x) + MathEx.Pi) * MathEx.Rad2Deg;
         }
         }

+ 1 - 1
MBansheeEngine/Light.cs

@@ -80,7 +80,7 @@ namespace BansheeEngine
         private void OnInitialize()
         private void OnInitialize()
         {
         {
             serializableData.position = Vector3.zero;
             serializableData.position = Vector3.zero;
-            serializableData.rotation = Quaternion.identity;
+            serializableData.rotation = Quaternion.Identity;
             serializableData.color = Color.White;
             serializableData.color = Color.White;
             serializableData.spotAngle = new Degree(45);
             serializableData.spotAngle = new Degree(45);
             serializableData.spotFalloffAngle = new Degree(40);
             serializableData.spotFalloffAngle = new Degree(40);

+ 25 - 5
MBansheeEngine/Math/AABox.cs

@@ -2,25 +2,37 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+    /// <summary>
+    /// Axis aligned box represented by minimum and maximum point.
+    /// </summary>
     [StructLayout(LayoutKind.Sequential), SerializeObject]
     [StructLayout(LayoutKind.Sequential), SerializeObject]
-	public struct AABox
+	public struct AABox // Note: Must match C++ class AABox
 	{
 	{
         private Vector3 _minimum;
         private Vector3 _minimum;
 		private Vector3 _maximum;
 		private Vector3 _maximum;
 
 
-        public Vector3 minimum
+        /// <summary>
+        /// Corner of the box with minimum values (opposite to maximum corner).
+        /// </summary>
+        public Vector3 Minimum
         {
         {
             get { return _minimum; }
             get { return _minimum; }
             set { _minimum = value; }
             set { _minimum = value; }
         }
         }
 
 
-        public Vector3 maximum
+        /// <summary>
+        /// Corner of the box with maximum values (opposite to minimum corner).
+        /// </summary>
+        public Vector3 Maximum
         {
         {
             get { return _maximum; }
             get { return _maximum; }
             set { _maximum = value; }
             set { _maximum = value; }
         }
         }
 
 
-        public Vector3 center
+        /// <summary>
+        /// Returns the center of the box.
+        /// </summary>
+        public Vector3 Center
         {
         {
             get 
             get 
             { 		
             { 		
@@ -30,7 +42,10 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
-	    public Vector3 size
+        /// <summary>
+        /// Returns the width, height and depth of the box.
+        /// </summary>
+	    public Vector3 Size
 	    {
 	    {
 	        get
 	        get
 	        {
 	        {
@@ -38,6 +53,11 @@ namespace BansheeEngine
 	        }
 	        }
 	    }
 	    }
 
 
+        /// <summary>
+        /// Creates a new axis aligned box.
+        /// </summary>
+        /// <param name="min">Corner of the box with minimum values.</param>
+        /// <param name="max">Corner of the box with maximum values.</param>
         public AABox(Vector3 min, Vector3 max)
         public AABox(Vector3 min, Vector3 max)
         {
         {
             _minimum = min;
             _minimum = min;

+ 39 - 6
MBansheeEngine/Math/BsRect3.cs

@@ -2,9 +2,25 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+    /// <summary>
+    /// Represents a rectangle in three dimensional space. It is represented by two axes that extend from the specified 
+    /// origin. Axes should be perpendicular to each other and they extend in both positive and negative directions from 
+    /// the origin by the amount specified by extents.
+    /// </summary>
     [StructLayout(LayoutKind.Sequential), SerializeObject]
     [StructLayout(LayoutKind.Sequential), SerializeObject]
-	public struct Rect3
+    public struct Rect3 // Note: Must match C++ class Rect3
 	{
 	{
+        /// <summary>
+        /// Creates a new rectangle.
+        /// </summary>
+        /// <param name="center">Origin of the rectangle. 
+        /// </param>
+        /// <param name="axes">Two axes that define orientation of the rectangle. Axes extend from the origin.
+        /// Axes should be normalized.
+        /// </param>
+        /// <param name="extents">Two extents that define the size of the rectangle. Extends should be
+        /// half the width/height as they are applied in both directions.
+        /// </param>
         public Rect3(Vector3 center, Vector3[] axes, float[] extents)
         public Rect3(Vector3 center, Vector3[] axes, float[] extents)
         {
         {
             this._center = center;
             this._center = center;
@@ -14,31 +30,48 @@ namespace BansheeEngine
             _extentVert = extents[1];
             _extentVert = extents[1];
         }
         }
 
 
-        public Vector3 center
+        /// <summary>
+        /// Origin of the rectangle.
+        /// </summary>
+        public Vector3 Center
         {
         {
             get { return _center; }
             get { return _center; }
             set { _center = value; }
             set { _center = value; }
         }
         }
 
 
-        public Vector3 axisHorz
+        /// <summary>
+        /// Returns the horizontal axis. Together with the vertical axis this defines rectangle orientation.
+        /// </summary>
+        public Vector3 AxisHorz
         {
         {
             get { return _axisHorz; }
             get { return _axisHorz; }
             set { _axisHorz = value; }
             set { _axisHorz = value; }
         }
         }
 
 
-        public Vector3 axisVert
+        /// <summary>
+        /// Returns the vertical axis. Together with the horizontal axis this defines rectangle orientation.
+        /// </summary>
+        public Vector3 AxisVert
         {
         {
             get { return _axisVert; }
             get { return _axisVert; }
             set { _axisVert = value; }
             set { _axisVert = value; }
         }
         }
 
 
-        public float extentHorz
+        /// <summary>
+        /// Returns the extents in the direction of the horizontal axis. This represents half the total
+        /// width of the rectangle.
+        /// </summary>
+        public float ExtentHorz
         {
         {
             get { return _extentHorz; }
             get { return _extentHorz; }
             set { _extentHorz = value; }
             set { _extentHorz = value; }
         }
         }
 
 
-        public float extentVert
+        /// <summary>
+        /// Returns the extents in the direction of the vertical axis. This represents half the total
+        /// height of the rectangle.
+        /// </summary>
+        public float ExtentVert
         {
         {
             get { return _extentVert; }
             get { return _extentVert; }
             set { _extentVert = value; }
             set { _extentVert = value; }

+ 37 - 1
MBansheeEngine/Math/Degree.cs

@@ -6,41 +6,74 @@ using System.Text;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+    /// <summary>
+    ///	Wrapper class which indicates a given angle value is in degrees. Degree values are interchangeable with radian 
+    /// values, and conversions will be done automatically between them.
+    /// </summary>
     [StructLayout(LayoutKind.Sequential), SerializeObject]
     [StructLayout(LayoutKind.Sequential), SerializeObject]
-	public struct Degree
+	public struct Degree // Note: Must match C++ class Degree
 	{
 	{
         readonly float value;
         readonly float value;
 
 
+        /// <summary>
+        /// Creates a new degree value.
+        /// </summary>
+        /// <param name="value">Value in degrees.</param>
 		public Degree(float value = 0.0f)
 		public Degree(float value = 0.0f)
 	    {
 	    {
 	        this.value = value;
 	        this.value = value;
 	    }
 	    }
 
 
+        /// <summary>
+        /// Creates a new degree value.
+        /// </summary>
+        /// <param name="r">Value in radians.</param>
         public Degree(Radian r)
         public Degree(Radian r)
         {
         {
             this.value = r.Degrees;
             this.value = r.Degrees;
         }
         }
 
 
+        /// <summary>
+        /// Converts a undefined angle value to a degree value.
+        /// </summary>
+        /// <param name="value">Value in degrees.</param>
+        /// <returns>Degree object wrapping the value.</returns>
         public static implicit operator Degree(float value)
         public static implicit operator Degree(float value)
         {
         {
             return new Degree(value);
             return new Degree(value);
         }
         }
 
 
+        /// <summary>
+        /// Converts a radian angle value to a degree value.
+        /// </summary>
+        /// <param name="r">Value in radians.</param>
+        /// <returns>Degree object wrapping the value.</returns>
         public static implicit operator Degree(Radian r)
         public static implicit operator Degree(Radian r)
         {
         {
             return new Degree(r.Degrees);
             return new Degree(r.Degrees);
         }
         }
 
 
+        /// <summary>
+        /// Converts a degree value to a regular floating point value.
+        /// </summary>
+        /// <param name="d">Degree value to convert.</param>
+        /// <returns>Value in degrees as floating point type.</returns>
 	    public static explicit operator float(Degree d)
 	    public static explicit operator float(Degree d)
 	    {
 	    {
             return d.value;
             return d.value;
 	    }
 	    }
 
 
+        /// <summary>
+        /// Returns the value in degrees as a floating point type.
+        /// </summary>
         public float Degrees
         public float Degrees
         {
         {
             get { return value; }
             get { return value; }
         }
         }
 
 
+        /// <summary>
+        /// Returns the value in radians as a floating point type.
+        /// </summary>
         public float Radians
         public float Radians
         {
         {
             get { return value*MathEx.Deg2Rad; }
             get { return value*MathEx.Deg2Rad; }
@@ -126,6 +159,7 @@ namespace BansheeEngine
             return a.value != b.value;
             return a.value != b.value;
         }
         }
 
 
+        /// <inheritdoc/>
         public override bool Equals(object other)
         public override bool Equals(object other)
         {
         {
             if (!(other is Degree))
             if (!(other is Degree))
@@ -138,11 +172,13 @@ namespace BansheeEngine
             return false;
             return false;
         }
         }
 
 
+        /// <inheritdoc/>
         public override int GetHashCode()
         public override int GetHashCode()
         {
         {
             return value.GetHashCode();
             return value.GetHashCode();
         }
         }
 
 
+        /// <inheritdoc/>
         public override string ToString()
         public override string ToString()
         {
         {
             return value.ToString();
             return value.ToString();

+ 256 - 0
MBansheeEngine/Math/MathEx.cs

@@ -2,6 +2,9 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+    /// <summary>
+    /// Values that represent in which order are euler angles applied when used in transformations.
+    /// </summary>
     public enum EulerAngleOrder
     public enum EulerAngleOrder
 	{
 	{
 		XYZ,
 		XYZ,
@@ -12,14 +15,42 @@ namespace BansheeEngine
 		ZYX
 		ZYX
 	};
 	};
 
 
+    /// <summary>
+    /// Utility class providing common scalar math operations.
+    /// </summary>
     class MathEx
     class MathEx
     {
     {
+        /// <summary>
+        /// Pi constant.
+        /// </summary>
         public const float Pi = 3.141593f;
         public const float Pi = 3.141593f;
+
+        /// <summary>
+        /// Two times pi constant.
+        /// </summary>
         public const float TwoPi = (2.0f * Pi);
         public const float TwoPi = (2.0f * Pi);
+
+        /// <summary>
+        /// Half of pi constant.
+        /// </summary>
         public const float HalfPi = (0.5f * Pi);
         public const float HalfPi = (0.5f * Pi);
+
+        /// <summary>
+        /// Constant that converts degrees to radians.
+        /// </summary>
         public const float Deg2Rad = Pi / 180.0f;
         public const float Deg2Rad = Pi / 180.0f;
+
+        /// <summary>
+        /// Constant that converts radians to degrees.
+        /// </summary>
         public const float Rad2Deg = 180.0f / Pi;
         public const float Rad2Deg = 180.0f / Pi;
 
 
+        /// <summary>
+        /// Returns the minimum value of the two provided.
+        /// </summary>
+        /// <param name="a">First value to compare.</param>
+        /// <param name="b">Second value to compare.</param>
+        /// <returns>Minimum of the two values.</returns>
         public static float Min(float a, float b)
         public static float Min(float a, float b)
         {
         {
             if (a < b)
             if (a < b)
@@ -28,6 +59,11 @@ namespace BansheeEngine
             return b;
             return b;
         }
         }
 
 
+        /// <summary>
+        /// Returns the minimum value of all the values provided.
+        /// </summary>
+        /// <param name="values">Values to compare.</param>
+        /// <returns>Minimum of all the values.</returns>
         public static float Min(params float[] values)
         public static float Min(params float[] values)
         {
         {
             int length = values.Length;
             int length = values.Length;
@@ -44,6 +80,12 @@ namespace BansheeEngine
             return min;
             return min;
         }
         }
 
 
+        /// <summary>
+        /// Returns the minimum value of the two provided.
+        /// </summary>
+        /// <param name="a">First value to compare.</param>
+        /// <param name="b">Second value to compare.</param>
+        /// <returns>Minimum of the two values.</returns>
         public static int Min(int a, int b)
         public static int Min(int a, int b)
         {
         {
             if (a < b)
             if (a < b)
@@ -52,6 +94,11 @@ namespace BansheeEngine
             return b;
             return b;
         }
         }
 
 
+        /// <summary>
+        /// Returns the minimum value of all the values provided.
+        /// </summary>
+        /// <param name="values">Values to compare.</param>
+        /// <returns>Minimum of all the values.</returns>
         public static int Min(params int[] values)
         public static int Min(params int[] values)
         {
         {
             int length = values.Length;
             int length = values.Length;
@@ -68,6 +115,12 @@ namespace BansheeEngine
             return min;
             return min;
         }
         }
 
 
+        /// <summary>
+        /// Returns the maximum value of the two provided.
+        /// </summary>
+        /// <param name="a">First value to compare.</param>
+        /// <param name="b">Second value to compare.</param>
+        /// <returns>Maximum of the two values.</returns>
         public static float Max(float a, float b)
         public static float Max(float a, float b)
         {
         {
             if (a > b)
             if (a > b)
@@ -76,6 +129,11 @@ namespace BansheeEngine
             return b;
             return b;
         }
         }
 
 
+        /// <summary>
+        /// Returns the maximum value of all the values provided.
+        /// </summary>
+        /// <param name="values">Values to compare.</param>
+        /// <returns>Maximum of all the values.</returns>
         public static float Max(params float[] values)
         public static float Max(params float[] values)
         {
         {
             int length = values.Length;
             int length = values.Length;
@@ -92,6 +150,12 @@ namespace BansheeEngine
             return max;
             return max;
         }
         }
 
 
+        /// <summary>
+        /// Returns the maximum value of the two provided.
+        /// </summary>
+        /// <param name="a">First value to compare.</param>
+        /// <param name="b">Second value to compare.</param>
+        /// <returns>Maximum of the two values.</returns>
         public static int Max(int a, int b)
         public static int Max(int a, int b)
         {
         {
             if (a > b)
             if (a > b)
@@ -100,6 +164,11 @@ namespace BansheeEngine
                 return b;
                 return b;
         }
         }
 
 
+        /// <summary>
+        /// Returns the maximum value of all the values provided.
+        /// </summary>
+        /// <param name="values">Values to compare.</param>
+        /// <returns>Maximum of all the values.</returns>
         public static int Max(params int[] values)
         public static int Max(params int[] values)
         {
         {
             int length = values.Length;
             int length = values.Length;
@@ -116,156 +185,320 @@ namespace BansheeEngine
             return max;
             return max;
         }
         }
 
 
+        /// <summary>
+        /// Returns the absolute value of the provided parameter.
+        /// </summary>
+        /// <param name="f">Parameter to take absolute value of.</param>
+        /// <returns>Absolute value of <paramref name="f"/>.</returns>
         public static float Abs(float f)
         public static float Abs(float f)
         {
         {
             return Math.Abs(f);
             return Math.Abs(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the absolute value of the provided parameter.
+        /// </summary>
+        /// <param name="value">Parameter to take absolute value of.</param>
+        /// <returns>Absolute value of <paramref name="value"/>.</returns>
         public static int Abs(int value)
         public static int Abs(int value)
         {
         {
             return Math.Abs(value);
             return Math.Abs(value);
         }
         }
 
 
+        /// <summary>
+        /// Raises <paramref name="f"/> to the power of <paramref name="p"/>.
+        /// </summary>
+        /// <param name="f">Value to raise to a power.</param>
+        /// <param name="p">Power to raise the value to.</param>
+        /// <returns><paramref name="f"/> raised to the power of <paramref name="p"/>.</returns>
         public static float Pow(float f, float p)
         public static float Pow(float f, float p)
         {
         {
             return (float)Math.Pow(f, p);
             return (float)Math.Pow(f, p);
         }
         }
 
 
+        /// <summary>
+        /// Raises e to the power of <paramref name="power"/>.
+        /// </summary>
+        /// <param name="power">Power to raise e to.</param>
+        /// <returns>e raised to the power of <paramref name="power"/>.</returns>
         public static float Exp(float power)
         public static float Exp(float power)
         {
         {
             return (float)Math.Exp(power);
             return (float)Math.Exp(power);
         }
         }
 
 
+        /// <summary>
+        /// Returns the logarithm of a number in a specified base.
+        /// </summary>
+        /// <param name="f">Value to get the logarithm of.</param>
+        /// <param name="p">Base of the logarithm</param>
+        /// <returns>Logarithm of a number in the specified base.</returns>
         public static float Log(float f, float p)
         public static float Log(float f, float p)
         {
         {
             return (float)Math.Log(f, p);
             return (float)Math.Log(f, p);
         }
         }
 
 
+        /// <summary>
+        /// Returns the natural logarithm (base e).
+        /// </summary>
+        /// <param name="f">Value to get the logarithm of.</param>
+        /// <returns>Natural logarithm of a number.</returns>
         public static float Log(float f)
         public static float Log(float f)
         {
         {
             return (float)Math.Log(f);
             return (float)Math.Log(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the logarithm of a number in base 10.
+        /// </summary>
+        /// <param name="f">Value to get the logarithm of.</param>
+        /// <returns>Logarithm of a number in base 10.</returns>
         public static float Log10(float f)
         public static float Log10(float f)
         {
         {
             return (float)Math.Log10(f);
             return (float)Math.Log10(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the smallest integral value that is greater than or equal to the provided value.
+        /// </summary>
+        /// <param name="f">Value to round.</param>
+        /// <returns>Smallest integral value that is greater than or equal to the provided value.</returns>
         public static float Ceil(float f)
         public static float Ceil(float f)
         {
         {
             return (float)Math.Ceiling(f);
             return (float)Math.Ceiling(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the largest integral value that is lesser than or equal to the provided value.
+        /// </summary>
+        /// <param name="f">Value to round.</param>
+        /// <returns>Largest integral value that is lessert than or equal to the provided value.</returns>
         public static float Floor(float f)
         public static float Floor(float f)
         {
         {
             return (float)Math.Floor(f);
             return (float)Math.Floor(f);
         }
         }
 
 
+        /// <summary>
+        /// Rounds the provided value to the nearest integral.
+        /// </summary>
+        /// <param name="f">Value to round.</param>
+        /// <returns>Value rounded to the nearest integral.</returns>
         public static float Round(float f)
         public static float Round(float f)
         {
         {
             return (float)Math.Round(f);
             return (float)Math.Round(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the smallest integral value that is greater than or equal to the provided value.
+        /// </summary>
+        /// <param name="f">Value to round.</param>
+        /// <returns>Smallest integral value that is greater than or equal to the provided value.</returns>
         public static int CeilToInt(float f)
         public static int CeilToInt(float f)
         {
         {
             return (int)Math.Ceiling(f);
             return (int)Math.Ceiling(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the largest integral value that is lesser than or equal to the provided value.
+        /// </summary>
+        /// <param name="f">Value to round.</param>
+        /// <returns>Largest integral value that is lessert than or equal to the provided value.</returns>
         public static int FloorToInt(float f)
         public static int FloorToInt(float f)
         {
         {
             return (int)Math.Floor(f);
             return (int)Math.Floor(f);
         }
         }
 
 
+        /// <summary>
+        /// Rounds the provided value to the nearest integral.
+        /// </summary>
+        /// <param name="f">Value to round.</param>
+        /// <returns>Value rounded to the nearest integral.</returns>
         public static int RoundToInt(float f)
         public static int RoundToInt(float f)
         {
         {
             return (int)Math.Round(f);
             return (int)Math.Round(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the sign of the provided value (positive or negative).
+        /// </summary>
+        /// <param name="f">Value to get the sign of.</param>
+        /// <returns>-1.0f if negative or 1.0f if positive.</returns>
         public static float Sign(float f)
         public static float Sign(float f)
         {
         {
             return f >= 0.0f ? 1.0f : -1.0f;
             return f >= 0.0f ? 1.0f : -1.0f;
         }
         }
 
 
+        /// <summary>
+        /// Returns the sine of the provided value.
+        /// </summary>
+        /// <param name="f">Angle in radians.</param>
+        /// <returns>Sine of the angle.</returns>
         public static float Sin(float f)
         public static float Sin(float f)
         {
         {
             return (float)Math.Sin(f);
             return (float)Math.Sin(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the cosine of the provided value.
+        /// </summary>
+        /// <param name="f">Angle in radians.</param>
+        /// <returns>Cosine of the angle.</returns>
         public static float Cos(float f)
         public static float Cos(float f)
         {
         {
             return (float)Math.Cos(f);
             return (float)Math.Cos(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the tangent of the provided value.
+        /// </summary>
+        /// <param name="f">Angle in radians.</param>
+        /// <returns>Tangent of the angle.</returns>
         public static float Tan(float f)
         public static float Tan(float f)
         {
         {
             return (float)Math.Tan(f);
             return (float)Math.Tan(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the angle whose sine is the specified number.
+        /// </summary>
+        /// <param name="f">Sine of an angle.</param>
+        /// <returns>Angle in radians.</returns>
         public static float Asin(float f)
         public static float Asin(float f)
         {
         {
             return (float)Math.Asin(f);
             return (float)Math.Asin(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the angle whose cosine is the specified number.
+        /// </summary>
+        /// <param name="f">Cosine of an angle.</param>
+        /// <returns>Angle in radians.</returns>
         public static float Acos(float f)
         public static float Acos(float f)
         {
         {
             return (float)Math.Acos(f);
             return (float)Math.Acos(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns the angle whose tangent is the specified number.
+        /// </summary>
+        /// <param name="f">Tangent of an angle.</param>
+        /// <returns>Angle in radians.</returns>
         public static float Atan(float f)
         public static float Atan(float f)
         {
         {
             return (float)Math.Atan(f);
             return (float)Math.Atan(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns an angle of a point.
+        /// </summary>
+        /// <param name="y">Y coordinate of the point.</param>
+        /// <param name="x">X coordinate of the point.</param>
+        /// <returns>Angle in radians in range [Pi, -Pi].</returns>
         public static float Atan2(float y, float x)
         public static float Atan2(float y, float x)
         {
         {
             return (float)Math.Atan2(y, x);
             return (float)Math.Atan2(y, x);
         }
         }
 
 
+        /// <summary>
+        /// Returns the sine of the provided value.
+        /// </summary>
+        /// <param name="f">Angle in radians.</param>
+        /// <returns>Sine of the angle.</returns>
         public static float Sin(Radian f)
         public static float Sin(Radian f)
         {
         {
             return (float)Math.Sin(f.Radians);
             return (float)Math.Sin(f.Radians);
         }
         }
 
 
+        /// <summary>
+        /// Returns the cosine of the provided value.
+        /// </summary>
+        /// <param name="f">Angle in radians.</param>
+        /// <returns>Cosine of the angle.</returns>
         public static float Cos(Radian f)
         public static float Cos(Radian f)
         {
         {
             return (float)Math.Cos(f.Radians);
             return (float)Math.Cos(f.Radians);
         }
         }
 
 
+        /// <summary>
+        /// Returns the tangent of the provided value.
+        /// </summary>
+        /// <param name="f">Angle in radians.</param>
+        /// <returns>Tangent of the angle.</returns>
         public static float Tan(Radian f)
         public static float Tan(Radian f)
         {
         {
             return (float)Math.Tan(f.Radians);
             return (float)Math.Tan(f.Radians);
         }
         }
 
 
+        /// <summary>
+        /// Returns the angle whose sine is the specified number.
+        /// </summary>
+        /// <param name="f">Sine of an angle.</param>
+        /// <returns>Angle in radians.</returns>
         public static float Asin(Radian f)
         public static float Asin(Radian f)
         {
         {
             return (float)Math.Asin(f.Radians);
             return (float)Math.Asin(f.Radians);
         }
         }
 
 
+        /// <summary>
+        /// Returns the angle whose cosine is the specified number.
+        /// </summary>
+        /// <param name="f">Cosine of an angle.</param>
+        /// <returns>Angle in radians.</returns>
         public static float Acos(Radian f)
         public static float Acos(Radian f)
         {
         {
             return (float)Math.Acos(f.Radians);
             return (float)Math.Acos(f.Radians);
         }
         }
 
 
+        /// <summary>
+        /// Returns the angle whose tangent is the specified number.
+        /// </summary>
+        /// <param name="f">Tangent of an angle.</param>
+        /// <returns>Angle in radians.</returns>
         public static float Atan(Radian f)
         public static float Atan(Radian f)
         {
         {
             return (float)Math.Atan(f.Radians);
             return (float)Math.Atan(f.Radians);
         }
         }
 
 
+        /// <summary>
+        /// Returns an angle of a point.
+        /// </summary>
+        /// <param name="y">Y coordinate of the point.</param>
+        /// <param name="x">X coordinate of the point.</param>
+        /// <returns>Angle in radians in range [Pi, -Pi].</returns>
         public static float Atan2(Radian y, Radian x)
         public static float Atan2(Radian y, Radian x)
         {
         {
             return (float)Math.Atan2(y.Radians, x.Radians);
             return (float)Math.Atan2(y.Radians, x.Radians);
         }
         }
 
 
+        /// <summary>
+        /// Returns a square root of the provided value.
+        /// </summary>
+        /// <param name="f">Value to take the square root of. Must not be negative.</param>
+        /// <returns>Square root of the provided value.</returns>
         public static float Sqrt(float f)
         public static float Sqrt(float f)
         {
         {
             return (float)Math.Sqrt(f);
             return (float)Math.Sqrt(f);
         }
         }
 
 
+        /// <summary>
+        /// Returns an inverse square root (1/sqrt(x)) of the provided value.
+        /// </summary>
+        /// <param name="f">Value to take the inverse square root of. Must not be negative or zero.</param>
+        /// <returns>Inverse square root of the provided value.</returns>
         public static float InvSqrt(float f)
         public static float InvSqrt(float f)
         {
         {
             return 1.0f/(float) Math.Sqrt(f);
             return 1.0f/(float) Math.Sqrt(f);
         }
         }
 
 
+        /// <summary>
+        /// Clamps a value between two other values.
+        /// </summary>
+        /// <param name="value">Value to clamp.</param>
+        /// <param name="min">Minimum value of the range to clamp. Must be lower than <paramref name="max"/>
+        /// </param>
+        /// <param name="max">Maximum value of the range to clamp. Must be higher than <paramref name="min"/>
+        /// </param>
+        /// <returns>Returns unchanged value if it is in valid range, otherwise returns value clamped to the range
+        /// extremes. </returns>
         public static float Clamp(float value, float min, float max)
         public static float Clamp(float value, float min, float max)
         {
         {
             if (value < min)
             if (value < min)
@@ -276,6 +509,16 @@ namespace BansheeEngine
             return value;
             return value;
         }
         }
 
 
+        /// <summary>
+        /// Clamps a value between two other values.
+        /// </summary>
+        /// <param name="value">Value to clamp.</param>
+        /// <param name="min">Minimum value of the range to clamp. Must be lower than <paramref name="max"/>
+        /// </param>
+        /// <param name="max">Maximum value of the range to clamp. Must be higher than <paramref name="min"/>
+        /// </param>
+        /// <returns>Returns unchanged value if it is in valid range, otherwise returns value clamped to the range
+        /// extremes. </returns>
         public static int Clamp(int value, int min, int max)
         public static int Clamp(int value, int min, int max)
         {
         {
             if (value < min)
             if (value < min)
@@ -286,6 +529,13 @@ namespace BansheeEngine
             return value;
             return value;
         }
         }
 
 
+        /// <summary>
+        /// Clamps a value between zero and one.
+        /// </summary>
+        /// <param name="value">Value to clamp.
+        // </param>
+        /// <returns>Returns unchanged value if it is in [0, 1] range, otherwise returns value clamped to the range. 
+        /// </returns>
         public static float Clamp01(float value)
         public static float Clamp01(float value)
         {
         {
             if (value < 0.0)
             if (value < 0.0)
@@ -297,6 +547,12 @@ namespace BansheeEngine
             return value;
             return value;
         }
         }
 
 
+        /// <summary>
+        /// Wraps an angle in [0, 360) range. Values lower than zero, or higher or equal to 360
+        /// will get wrapped around back into [0, 360) range.
+        /// </summary>
+        /// <param name="angle">Angle to wrap.</param>
+        /// <returns>Angle in [0, 360) range.</returns>
         public static Degree WrapAngle(Degree angle)
         public static Degree WrapAngle(Degree angle)
         {
         {
             const float inv360 = 1.0f/360.0f;
             const float inv360 = 1.0f/360.0f;

+ 126 - 10
MBansheeEngine/Math/Matrix3.cs

@@ -3,9 +3,15 @@ using System.Runtime.InteropServices;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+    /// <summary>
+    /// A 3x3 matrix. Can be used for non-homogenous transformations of three dimensional vectors and points.
+    /// </summary>
     [StructLayout(LayoutKind.Sequential), SerializeObject]
     [StructLayout(LayoutKind.Sequential), SerializeObject]
-    public struct Matrix3
+    public struct Matrix3 // Note: Must match C++ class Matrix3
     {
     {
+        /// <summary>
+        /// Contains constant data that is used when calculating euler angles in a certain order.
+        /// </summary>
         private struct EulerAngleOrderData
         private struct EulerAngleOrderData
 		{
 		{
             public EulerAngleOrderData(int a, int b, int c, float sign)
             public EulerAngleOrderData(int a, int b, int c, float sign)
@@ -24,8 +30,15 @@ namespace BansheeEngine
 		{ new EulerAngleOrderData(0, 1, 2, 1.0f), new EulerAngleOrderData(0, 2, 1, -1.0f), new EulerAngleOrderData(1, 0, 2, -1.0f),
 		{ new EulerAngleOrderData(0, 1, 2, 1.0f), new EulerAngleOrderData(0, 2, 1, -1.0f), new EulerAngleOrderData(1, 0, 2, -1.0f),
 		  new EulerAngleOrderData(1, 2, 0, 1.0f), new EulerAngleOrderData(2, 0, 1,  1.0f), new EulerAngleOrderData(2, 1, 0, -1.0f) };
 		  new EulerAngleOrderData(1, 2, 0, 1.0f), new EulerAngleOrderData(2, 0, 1,  1.0f), new EulerAngleOrderData(2, 1, 0, -1.0f) };
 
 
-        public static readonly Matrix3 zero = new Matrix3();
-        public static readonly Matrix3 identity = new Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1);
+        /// <summary>
+        /// A matrix with all zero values.
+        /// </summary>
+        public static readonly Matrix3 Zero = new Matrix3();
+
+        /// <summary>
+        /// Identity matrix.
+        /// </summary>
+        public static readonly Matrix3 Identity = new Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1);
 
 
         public float m00;
         public float m00;
         public float m01;
         public float m01;
@@ -37,6 +50,9 @@ namespace BansheeEngine
         public float m21;
         public float m21;
         public float m22;
         public float m22;
 
 
+        /// <summary>
+        /// Creates a new matrix with the specified elements.
+        /// </summary>
         public Matrix3(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
         public Matrix3(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
         {
         {
             this.m00 = m00;
             this.m00 = m00;
@@ -50,6 +66,12 @@ namespace BansheeEngine
             this.m22 = m22;
             this.m22 = m22;
         }
         }
 
 
+        /// <summary>
+        /// Value of the specified element in the matrix.
+        /// </summary>
+        /// <param name="row">Row index of the element to retrieve.</param>
+        /// <param name="column">Column index of the element to retrieve.</param>
+        /// <returns>Value of the element.</returns>
         public float this[int row, int column]
         public float this[int row, int column]
         {
         {
             get
             get
@@ -62,6 +84,12 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Value of the specified element in the matrix using a linear index.
+        /// Linear index can be calculated using the following formula: idx = row * 3 + column. 
+        /// </summary>
+        /// <param name="index">Linear index to get the value of.</param>
+        /// <returns>Value of the element.</returns>
         public float this[int index]
         public float this[int index]
         {
         {
             get
             get
@@ -159,6 +187,7 @@ namespace BansheeEngine
             return !(lhs == rhs);
             return !(lhs == rhs);
         }
         }
 
 
+        /// <inheritdoc/>
         public override int GetHashCode()
         public override int GetHashCode()
         {
         {
             float hash1 = m00.GetHashCode() ^ m10.GetHashCode() << 2 ^ m20.GetHashCode() >> 2;
             float hash1 = m00.GetHashCode() ^ m10.GetHashCode() << 2 ^ m20.GetHashCode() >> 2;
@@ -168,6 +197,7 @@ namespace BansheeEngine
             return hash1.GetHashCode() ^ hash2.GetHashCode() << 2 ^ hash3.GetHashCode() >> 2;
             return hash1.GetHashCode() ^ hash2.GetHashCode() << 2 ^ hash3.GetHashCode() >> 2;
         }
         }
 
 
+        /// <inheritdoc/>
         public override bool Equals(object other)
         public override bool Equals(object other)
         {
         {
             if (!(other is Matrix3))
             if (!(other is Matrix3))
@@ -182,6 +212,9 @@ namespace BansheeEngine
                 return false;
                 return false;
         }
         }
 
 
+        /// <summary>
+        /// Calculates an inverse of the matrix if it exists.
+        /// </summary>
         public void Invert()
         public void Invert()
         {
         {
             float[,] invVals = new float[3,3];
             float[,] invVals = new float[3,3];
@@ -212,6 +245,9 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Returns a transpose of the matrix (switched columns and rows).
+        /// </summary>
         public void Transpose()
         public void Transpose()
         {
         {
             float tmp = m10;
             float tmp = m10;
@@ -227,6 +263,10 @@ namespace BansheeEngine
             m21 = tmp;
             m21 = tmp;
         }
         }
 
 
+        /// <summary>
+        /// Calculates the matrix determinant.
+        /// </summary>
+        /// <returns>Determinant of the matrix.</returns>
         public float Determinant()
         public float Determinant()
         {
         {
             float cofactor00 = m11 * m22 - m12 * m21;
             float cofactor00 = m11 * m22 - m12 * m21;
@@ -238,6 +278,11 @@ namespace BansheeEngine
             return det;
             return det;
         }
         }
 
 
+        /// <summary>
+        /// Transforms the given vector by this matrix and returns the newly transformed vector.
+        /// </summary>
+        /// <param name="vec">Three dimensional vector to transform.</param>
+        /// <returns>Vector transformed by the matrix.</returns>
         public Vector3 Transform(Vector3 vec)
         public Vector3 Transform(Vector3 vec)
         {
         {
             Vector3 outVec;
             Vector3 outVec;
@@ -247,6 +292,14 @@ namespace BansheeEngine
             return outVec;
             return outVec;
         }
         }
 
 
+        /// <summary>
+        /// Decomposes the matrix into a set of values.
+        /// </summary>
+        /// <param name="matQ">Columns form orthonormal bases. If your matrix is affine and doesn't use non-uniform scaling 
+        /// this matrix will be the rotation part of the matrix.
+        /// </param>
+        /// <param name="vecD">If the matrix is affine these will be scaling factors of the matrix.</param>
+        /// <param name="vecU">If the matrix is affine these will be shear factors of the matrix.</param>
         public void QDUDecomposition(out Matrix3 matQ, out Vector3 vecD, out Vector3 vecU)
         public void QDUDecomposition(out Matrix3 matQ, out Vector3 vecD, out Vector3 vecU)
         {
         {
             matQ = new Matrix3();
             matQ = new Matrix3();
@@ -323,9 +376,10 @@ namespace BansheeEngine
             vecU[2] = matRight.m12 / vecD[1];
             vecU[2] = matRight.m12 / vecD[1];
         }
         }
 
 
-        /**
-         * @note    Returns angles in degrees.
-         */
+        /// <summary>
+        /// Converts an orthonormal matrix to euler angle (pitch/yaw/roll) representation.
+        /// </summary>
+        /// <returns>Euler angles in degrees representing the rotation in this matrix.</returns>
         public Vector3 ToEulerAngles()
         public Vector3 ToEulerAngles()
         {
         {
             float xAngle = -MathEx.Asin(this[1, 2]);
             float xAngle = -MathEx.Asin(this[1, 2]);
@@ -359,11 +413,20 @@ namespace BansheeEngine
 		    }
 		    }
         }
         }
 
 
+        /// <summary>
+        /// Converts an orthonormal matrix to quaternion representation.
+        /// </summary>
+        /// <returns>Quaternion representing the rotation in this matrix.</returns>
         public Quaternion ToQuaternion()
         public Quaternion ToQuaternion()
         {
         {
             return Quaternion.FromRotationMatrix(this);
             return Quaternion.FromRotationMatrix(this);
         }
         }
 
 
+        /// <summary>
+        /// Converts an orthonormal matrix to axis angle representation.
+        /// </summary>
+        /// <param name="axis">Axis around which the rotation is performed.</param>
+        /// <param name="angle">Amount of rotation.</param>
         public void ToAxisAngle(out Vector3 axis, out Degree angle)
         public void ToAxisAngle(out Vector3 axis, out Degree angle)
         {
         {
             float trace = m00 + m11 + m22;
             float trace = m00 + m11 + m22;
@@ -437,6 +500,11 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Calculates the inverse of the matrix if it exists.
+        /// </summary>
+        /// <param name="mat">Matrix to calculate the inverse of.</param>
+        /// <returns>Inverse of the matrix.</returns>
         public static Matrix3 Inverse(Matrix3 mat)
         public static Matrix3 Inverse(Matrix3 mat)
         {
         {
             Matrix3 copy = mat;
             Matrix3 copy = mat;
@@ -444,6 +512,12 @@ namespace BansheeEngine
             return copy;
             return copy;
         }
         }
 
 
+
+        /// <summary>
+        /// Calculates the transpose of the matrix.
+        /// </summary>
+        /// <param name="mat">Matrix to calculate the transpose of.</param>
+        /// <returns>Transpose of the matrix.</returns>
         public static Matrix3 Transpose(Matrix3 mat)
         public static Matrix3 Transpose(Matrix3 mat)
         {
         {
             Matrix3 copy = mat;
             Matrix3 copy = mat;
@@ -451,11 +525,27 @@ namespace BansheeEngine
             return copy;
             return copy;
         }
         }
 
 
-        public static Matrix3 FromEuler(Vector3 eulerDeg, EulerAngleOrder order)
+        /// <summary>
+        /// Creates a rotation matrix from the provided euler angle (pitch/yaw/roll) rotation.
+        /// </summary>
+        /// <param name="euler">Euler angles in degrees.</param>
+        /// <param name="order">The order in which rotations will be applied. Different rotations can be created depending 
+        /// on the order.</param>
+        /// <returns>Rotation matrix that can rotate an object to the specified angles.</returns>
+        public static Matrix3 FromEuler(Vector3 euler, EulerAngleOrder order)
         {
         {
-            return FromEuler(new Degree(eulerDeg.x), new Degree(eulerDeg.y), new Degree(eulerDeg.y), order);
+            return FromEuler(new Degree(euler.x), new Degree(euler.y), new Degree(euler.y), order);
         }
         }
 
 
+        /// <summary>
+        /// Creates a rotation matrix from the provided euler angle (pitch/yaw/roll) rotation.
+        /// </summary>
+        /// <param name="xAngle">Pitch angle of rotation.</param>
+        /// <param name="yAngle">Yar angle of rotation.</param>
+        /// <param name="zAngle">Roll angle of rotation.</param>
+        /// <param name="order">The order in which rotations will be applied. Different rotations can be created depending
+        /// on the order.</param>
+        /// <returns>Rotation matrix that can rotate an object to the specified angles.</returns>
         public static Matrix3 FromEuler(Radian xAngle, Radian yAngle, Radian zAngle, EulerAngleOrder order)
         public static Matrix3 FromEuler(Radian xAngle, Radian yAngle, Radian zAngle, EulerAngleOrder order)
         {
         {
             EulerAngleOrderData l = EA_LOOKUP[(int)order];
             EulerAngleOrderData l = EA_LOOKUP[(int)order];
@@ -486,11 +576,25 @@ namespace BansheeEngine
 		    return mats[l.a]*(mats[l.b]*mats[l.c]);
 		    return mats[l.a]*(mats[l.b]*mats[l.c]);
         }
         }
 
 
-        public static Matrix3 FromEuler(Vector3 eulerDeg)
+        /// <summary>
+        /// Creates a rotation matrix from the provided euler angle (pitch/yaw/roll) rotation. Angles are applied in YXZ 
+        /// order.
+        /// </summary>
+        /// <param name="euler">Euler angles in degrees.</param>
+        /// <returns>Rotation matrix that can rotate an object to the specified angles.</returns>
+        public static Matrix3 FromEuler(Vector3 euler)
         {
         {
-            return FromEuler(new Degree(eulerDeg.x), new Degree(eulerDeg.y), new Degree(eulerDeg.y));
+            return FromEuler(new Degree(euler.x), new Degree(euler.y), new Degree(euler.y));
         }
         }
 
 
+        /// <summary>
+        /// Creates a rotation matrix from the provided euler angle (pitch/yaw/roll) rotation. Angles are applied in YXZ 
+        /// order.
+        /// </summary>
+        /// <param name="xAngle">Pitch angle of rotation.</param>
+        /// <param name="yAngle">Yar angle of rotation.</param>
+        /// <param name="zAngle">Roll angle of rotation.</param>
+        /// <returns>Rotation matrix that can rotate an object to the specified angles.</returns>
         public static Matrix3 FromEuler(Radian xAngle, Radian yAngle, Radian zAngle)
         public static Matrix3 FromEuler(Radian xAngle, Radian yAngle, Radian zAngle)
         {
         {
             Matrix3 m = new Matrix3();
             Matrix3 m = new Matrix3();
@@ -519,6 +623,12 @@ namespace BansheeEngine
             return m;
             return m;
         }
         }
 
 
+        /// <summary>
+        /// Creates a rotation matrix from axis/angle rotation.
+        /// </summary>
+        /// <param name="axis">Axis around which the rotation is performed.</param>
+        /// <param name="angle">Amount of rotation.</param>
+        /// <returns>Rotation matrix that can rotate an object around the specified axis for the specified amount.</returns>
         public static Matrix3 FromAxisAngle(Vector3 axis, Degree angle)
         public static Matrix3 FromAxisAngle(Vector3 axis, Degree angle)
         {
         {
             Matrix3 mat;
             Matrix3 mat;
@@ -549,11 +659,17 @@ namespace BansheeEngine
             return mat;
             return mat;
         }
         }
 
 
+        /// <summary>
+        /// Creates a rotation matrix from a quaternion rotation.
+        /// </summary>
+        /// <param name="quat">Quaternion to create the matrix from.</param>
+        /// <returns>Rotation matrix containing the equivalent rotation of the provided quaternion.</returns>
         public static Matrix3 FromQuaternion(Quaternion quat)
         public static Matrix3 FromQuaternion(Quaternion quat)
         {
         {
             return quat.ToRotationMatrix();
             return quat.ToRotationMatrix();
         }
         }
 
 
+        /// <inheritdoc/>
         public override string ToString()
         public override string ToString()
         {
         {
             return String.Format("({0}, {1}, {2},\n{3}, {4}, {5}\n{6}, {7}, {8})",
             return String.Format("({0}, {1}, {2},\n{3}, {4}, {5}\n{6}, {7}, {8})",

+ 133 - 44
MBansheeEngine/Math/Matrix4.cs

@@ -3,11 +3,21 @@ using System.Runtime.InteropServices;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+    /// <summary>
+    /// A 4x4 matrix. Can be used for homogenous transformations of three dimensional vectors and points.
+    /// </summary>
     [StructLayout(LayoutKind.Sequential), SerializeObject]
     [StructLayout(LayoutKind.Sequential), SerializeObject]
-    public struct Matrix4
+    public struct Matrix4 // Note: Must match C++ class Matrix4
     {
     {
-        public static readonly Matrix4 zero = new Matrix4();
-        public static readonly Matrix4 identity = new Matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
+        /// <summary>
+        /// A matrix with all zero values.
+        /// </summary>
+        public static readonly Matrix4 Zero = new Matrix4();
+
+        /// <summary>
+        /// Identity matrix.
+        /// </summary>
+        public static readonly Matrix4 Identity = new Matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
 
 
         public float m00;
         public float m00;
         public float m01;
         public float m01;
@@ -26,6 +36,9 @@ namespace BansheeEngine
         public float m32;
         public float m32;
         public float m33;
         public float m33;
 
 
+        /// <summary>
+        /// Creates a new matrix with the specified elements.
+        /// </summary>
         public Matrix4(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, 
         public Matrix4(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, 
             float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
             float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
         {
         {
@@ -47,6 +60,12 @@ namespace BansheeEngine
             this.m33 = m33;
             this.m33 = m33;
         }
         }
 
 
+        /// <summary>
+        /// Value of the specified element in the matrix.
+        /// </summary>
+        /// <param name="row">Row index of the element to retrieve.</param>
+        /// <param name="column">Column index of the element to retrieve.</param>
+        /// <returns>Value of the element.</returns>
         public float this[int row, int column]
         public float this[int row, int column]
         {
         {
             get
             get
@@ -59,6 +78,12 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Value of the specified element in the matrix using a linear index.
+        /// Linear index can be calculated using the following formula: idx = row * 4 + column. 
+        /// </summary>
+        /// <param name="index">Linear index to get the value of.</param>
+        /// <returns>Value of the element.</returns>
         public float this[int index]
         public float this[int index]
         {
         {
             get
             get
@@ -160,6 +185,9 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Calculates the inverse of the matrix. 
+        /// </summary>
         public Matrix4 Inverse
         public Matrix4 Inverse
         {
         {
             get
             get
@@ -170,6 +198,9 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Calculates the inverse of the matrix. Use only if matrix is affine.
+        /// </summary>
         public Matrix4 InverseAffine
         public Matrix4 InverseAffine
         {
         {
             get
             get
@@ -219,6 +250,7 @@ namespace BansheeEngine
             return !(lhs == rhs);
             return !(lhs == rhs);
         }
         }
 
 
+        /// <inheritdoc/>
         public override int GetHashCode()
         public override int GetHashCode()
         {
         {
             float hash1 = m00.GetHashCode() ^ m10.GetHashCode() << 2 ^ m20.GetHashCode() >> 2 ^ m30.GetHashCode() >> 1;
             float hash1 = m00.GetHashCode() ^ m10.GetHashCode() << 2 ^ m20.GetHashCode() >> 2 ^ m30.GetHashCode() >> 1;
@@ -229,6 +261,7 @@ namespace BansheeEngine
             return hash1.GetHashCode() ^ hash2.GetHashCode() << 2 ^ hash3.GetHashCode() >> 2 ^ hash4.GetHashCode() >> 1;
             return hash1.GetHashCode() ^ hash2.GetHashCode() << 2 ^ hash3.GetHashCode() >> 2 ^ hash4.GetHashCode() >> 1;
         }
         }
 
 
+        /// <inheritdoc/>
         public override bool Equals(object other)
         public override bool Equals(object other)
         {
         {
             if (!(other is Matrix4))
             if (!(other is Matrix4))
@@ -244,6 +277,9 @@ namespace BansheeEngine
                 return false;
                 return false;
         }
         }
 
 
+        /// <summary>
+        /// Calculates the inverse of the matrix. If matrix is affine use <see cref="InvertAffine()"/> as it is faster.
+        /// </summary>
         public void Invert()
         public void Invert()
         {
         {
             float v0 = m20 * m31 - m21 * m30;
             float v0 = m20 * m31 - m21 * m30;
@@ -301,6 +337,9 @@ namespace BansheeEngine
                 d30, d31, d32, d33);
                 d30, d31, d32, d33);
         }
         }
 
 
+        /// <summary>
+        /// Calculates the inverse of the matrix. Matrix must be affine.
+        /// </summary>
         public void InvertAffine()
         public void InvertAffine()
         {
         {
             float t00 = m22 * m11 - m21 * m12;
             float t00 = m22 * m11 - m21 * m12;
@@ -336,6 +375,9 @@ namespace BansheeEngine
                   0, 0, 0, 1);
                   0, 0, 0, 1);
         }
         }
 
 
+        /// <summary>
+        /// Transposes the matrix (switched columns and rows).
+        /// </summary>
         public void Transpose()
         public void Transpose()
         {
         {
             float tmp = m01;
             float tmp = m01;
@@ -363,6 +405,10 @@ namespace BansheeEngine
             m32 = tmp;
             m32 = tmp;
         }
         }
 
 
+        /// <summary>
+        /// Calculates the determinant of the matrix.
+        /// </summary>
+        /// <returns>Determinant of the matrix.</returns>
         public float Determinant()
         public float Determinant()
         {
         {
             float m1 = m11 * (m22 * m33 - m32 * m23) -
             float m1 = m11 * (m22 * m33 - m32 * m23) -
@@ -384,13 +430,14 @@ namespace BansheeEngine
             return m00 * m1 - m01 * m2 + m02 * m3 - m03 * m4;
             return m00 * m1 - m01 * m2 + m02 * m3 - m03 * m4;
         }
         }
 
 
-        /**
-         * @brief	Decompose a Matrix4 to translation, rotation and scale.
-         *
-         * @note	Matrix must consist only of translation, rotation and uniform scale transformations,
-         * 			otherwise accurate results are not guaranteed. Applying non-uniform scale guarantees
-         * 			results will not be accurate.
-         */
+        /// <summary>
+        /// Decompose a matrix to translation, rotation and scale components. Matrix must consist only of translation, 
+        /// rotation and uniform scale transformations, otherwise accurate results are not guaranteed. Applying non-uniform 
+        /// scale guarantees results will not be accurate.
+        /// </summary>
+        /// <param name="translation">Translation offset.</param>
+        /// <param name="rotation">Rotation quaternion.</param>
+        /// <param name="scale">Scale factors.</param>
         public void GetTRS(out Vector3 translation, out Quaternion rotation, out Vector3 scale)
         public void GetTRS(out Vector3 translation, out Quaternion rotation, out Vector3 scale)
         {
         {
             Matrix3 m3x3 = ToMatrix3(this);
             Matrix3 m3x3 = ToMatrix3(this);
@@ -403,24 +450,37 @@ namespace BansheeEngine
             translation = new Vector3(m03, m13, m23);
             translation = new Vector3(m03, m13, m23);
         }
         }
 
 
-        /**
-         * @brief	Transform a 3D vector by this matrix.
-         * 			
-         * @note	Matrix must be affine, if it is not use "Multiply" method.
-         */
-        public Vector3 MultiplyAffine(Vector3 v)
+        /// <summary>
+        /// Transform a 3D point by this matrix. Matrix must be affine.
+        /// </summary>
+        /// <param name="p">Point to transform.</param>
+        /// <returns>Point transformed by this matrix.</returns>
+        public Vector3 MultiplyAffine(Vector3 p)
+        {
+            return new Vector3(
+                m00 * p.x + m01 * p.y + m02 * p.z + m03,
+                m10 * p.x + m11 * p.y + m12 * p.z + m13,
+                m20 * p.x + m21 * p.y + m22 * p.z + m23);
+        }
+
+        /// <summary>
+        /// Transform a 3D direction vector by this matrix. w component is assumed to be 0. 
+        /// </summary>
+        /// <param name="d">Direction vector to transform.</param>
+        /// <returns>Direction vector transformed by this matrix.</returns>
+        public Vector3 MultiplyDirection(Vector3 d)
         {
         {
             return new Vector3(
             return new Vector3(
-                    m00 * v.x + m01 * v.y + m02 * v.z + m03, 
-                    m10 * v.x + m11 * v.y + m12 * v.z + m13,
-                    m20 * v.x + m21 * v.y + m22 * v.z + m23);
+                    m00 * d.x + m01 * d.y + m02 * d.z + m03, 
+                    m10 * d.x + m11 * d.y + m12 * d.z + m13,
+                    m20 * d.x + m21 * d.y + m22 * d.z + m23);
         }
         }
 
 
-        /**
-         * @brief	Transform a 4D vector by this matrix.
-         * 			
-         * @note	Matrix must be affine, if it is not use "Multiply" method.
-         */
+        /// <summary>
+        /// Transform a 4D vector by this matrix. Matrix must be affine.
+        /// </summary>
+        /// <param name="v">Vector to transform.</param>
+        /// <returns>Vector transformed by this matrix.</returns>
         public Vector4 MultiplyAffine(Vector4 v)
         public Vector4 MultiplyAffine(Vector4 v)
         {
         {
             return new Vector4(
             return new Vector4(
@@ -430,34 +490,32 @@ namespace BansheeEngine
                 v.w);
                 v.w);
         }
         }
 
 
-        /**
-         * @brief	Transform a 3D vector by this matrix.  
-         *
-         * @note	w component of the vector is assumed to be 1. After transformation all components
-         * 			are projected back so that w remains 1.
-         * 			
-		 *			If your matrix doesn't contain projection components use "MultiplyAffine" method as it is faster.
-         */
-        public Vector3 Multiply(Vector3 v)
+        /// <summary>
+        /// Transform a 3D point by this matrix. w component of the vector is assumed to be 1. After transformation all 
+        /// components are projected back so that w remains 1. If your matrix doesn't contain projection components use 
+        /// <see cref="MultiplyAffine(Vector4)"/> as it is faster.
+        /// </summary>
+        /// <param name="p">Point to transform.</param>
+        /// <returns>Point transformed by this matrix.</returns>
+        public Vector3 Multiply(Vector3 p)
         {
         {
             Vector3 r = new Vector3();
             Vector3 r = new Vector3();
 
 
-            float fInvW = 1.0f / (m30 * v.x + m31 * v.y + m32 * v.z + m33);
+            float fInvW = 1.0f / (m30 * p.x + m31 * p.y + m32 * p.z + m33);
 
 
-            r.x = (m00 * v.x + m01 * v.y + m02 * v.z + m03) * fInvW;
-            r.y = (m10 * v.x + m11 * v.y + m12 * v.z + m13) * fInvW;
-            r.z = (m20 * v.x + m21 * v.y + m22 * v.z + m23) * fInvW;
+            r.x = (m00 * p.x + m01 * p.y + m02 * p.z + m03) * fInvW;
+            r.y = (m10 * p.x + m11 * p.y + m12 * p.z + m13) * fInvW;
+            r.z = (m20 * p.x + m21 * p.y + m22 * p.z + m23) * fInvW;
 
 
             return r;
             return r;
         }
         }
 
 
-        /**
-         * @brief	Transform a 3D vector by this matrix.  
-         *
-         * @note	After transformation all components are projected back so that w remains 1.
-         * 			
-		 *			If your matrix doesn't contain projection components use "MultiplyAffine" method as it is faster.
-         */
+        /// <summary>
+        /// Transform a 4D vector by this matrix. If your matrix doesn't contain projection components 
+        /// use <see cref="MultiplyAffine(Vector4)"/> as it is faster.
+        /// </summary>
+        /// <param name="v">Vector to transform.</param>
+        /// <returns>Vector transformed by this matrix.</returns>
         public Vector4 Multiply(Vector4 v)
         public Vector4 Multiply(Vector4 v)
         {
         {
             return new Vector4(
             return new Vector4(
@@ -467,6 +525,11 @@ namespace BansheeEngine
                 m30 * v.x + m31 * v.y + m32 * v.z + m33 * v.w);
                 m30 * v.x + m31 * v.y + m32 * v.z + m33 * v.w);
         }
         }
 
 
+        /// <summary>
+        /// Sets values of a specific column in the matrix.
+        /// </summary>
+        /// <param name="columnIdx">Index of the column in range [0, 3].</param>
+        /// <param name="column">Values to set in the column.</param>
         public void SetColumn(int columnIdx, Vector4 column)
         public void SetColumn(int columnIdx, Vector4 column)
         {
         {
             this[0, columnIdx] = column.x;
             this[0, columnIdx] = column.x;
@@ -475,6 +538,13 @@ namespace BansheeEngine
             this[3, columnIdx] = column.w;
             this[3, columnIdx] = column.w;
         }
         }
 
 
+        /// <summary>
+        /// Creates a new matrix that performs translation, rotation and scale.
+        /// </summary>
+        /// <param name="translation">Offset to translate by.</param>
+        /// <param name="rotation">Rotation quaternion.</param>
+        /// <param name="scale">Non-uniform scale factors.</param>
+        /// <returns>Matrix that performs scale, followed by rotation, followed by translation. </returns>
         public static Matrix4 TRS(Vector3 translation, Quaternion rotation, Vector3 scale)
         public static Matrix4 TRS(Vector3 translation, Quaternion rotation, Vector3 scale)
         {
         {
             Matrix3 rot3x3 = rotation.ToRotationMatrix();
             Matrix3 rot3x3 = rotation.ToRotationMatrix();
@@ -490,6 +560,11 @@ namespace BansheeEngine
             return mat;
             return mat;
         }
         }
 
 
+        /// <summary>
+        /// Returns the rotation/scaling parts of a 4x4 matrix.
+        /// </summary>
+        /// <param name="mat">Matrix to extract the rotation/scaling from.</param>
+        /// <returns>3x3 matrix representing an upper left portion of the provided matrix.</returns>
         public static Matrix3 ToMatrix3(Matrix4 mat)
         public static Matrix3 ToMatrix3(Matrix4 mat)
         {
         {
             return new Matrix3(
             return new Matrix3(
@@ -498,6 +573,11 @@ namespace BansheeEngine
                 mat.m20, mat.m21, mat.m22);
                 mat.m20, mat.m21, mat.m22);
         }
         }
 
 
+        /// <summary>
+        /// Returns the inverse of the specified matrix.
+        /// </summary>
+        /// <param name="mat">Matrix to take inverse of.</param>
+        /// <returns>Inverse of the provided matrix.</returns>
         public static Matrix4 Invert(Matrix4 mat)
         public static Matrix4 Invert(Matrix4 mat)
         {
         {
             Matrix4 copy = mat;
             Matrix4 copy = mat;
@@ -505,6 +585,11 @@ namespace BansheeEngine
             return copy;
             return copy;
         }
         }
 
 
+        /// <summary>
+        /// Returns the inverse of the affine matrix. Faster than <see cref="Invert(Matrix4)"/>.
+        /// </summary>
+        /// <param name="mat">Affine matrix to take inverse of.</param>
+        /// <returns>Inverse of the provided matrix.</returns>
         public static Matrix4 InvertAffine(Matrix4 mat)
         public static Matrix4 InvertAffine(Matrix4 mat)
         {
         {
             Matrix4 copy = mat;
             Matrix4 copy = mat;
@@ -512,6 +597,9 @@ namespace BansheeEngine
             return copy;
             return copy;
         }
         }
 
 
+        /// <summary>
+        /// Returns a transpose of the matrix (switched columns and rows).
+        /// </summary>
         public static Matrix4 Transpose(Matrix4 mat)
         public static Matrix4 Transpose(Matrix4 mat)
         {
         {
             Matrix4 copy = mat;
             Matrix4 copy = mat;
@@ -519,6 +607,7 @@ namespace BansheeEngine
             return copy;
             return copy;
         }
         }
 
 
+        /// <inheritdoc/>
         public override string ToString()
         public override string ToString()
         {
         {
             return String.Format("({0}, {1}, {2}, {3},\n{4}, {5}, {6}, {7}\n{8}, {9}, {10}, {11}\n{12}, {13}, {14}, {15})",
             return String.Format("({0}, {1}, {2}, {3},\n{4}, {5}, {6}, {7}\n{8}, {9}, {10}, {11}\n{12}, {13}, {14}, {15})",

+ 205 - 38
MBansheeEngine/Math/Quaternion.cs

@@ -3,9 +3,15 @@ using System.Runtime.InteropServices;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+    /// <summary>
+    /// Quaternion used for representing rotations.
+    /// </summary>
     [StructLayout(LayoutKind.Sequential), SerializeObject]
     [StructLayout(LayoutKind.Sequential), SerializeObject]
-    public struct Quaternion
+    public struct Quaternion // Note: Must match C++ class Quaternion
     {
     {
+        /// <summary>
+        /// Contains constant data that is used when calculating euler angles in a certain order.
+        /// </summary>
         private struct EulerAngleOrderData
         private struct EulerAngleOrderData
 		{
 		{
             public EulerAngleOrderData(int a, int b, int c)
             public EulerAngleOrderData(int a, int b, int c)
@@ -18,8 +24,15 @@ namespace BansheeEngine
 			public int a, b, c;
 			public int a, b, c;
 		};
 		};
 
 
-        public static readonly Quaternion zero = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f);
-        public static readonly Quaternion identity = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
+        /// <summary>
+        /// Quaternion with all zero elements.
+        /// </summary>
+        public static readonly Quaternion Zero = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f);
+
+        /// <summary>
+        /// Quaternion representing no rotation.
+        /// </summary>
+        public static readonly Quaternion Identity = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
 
 
         private static readonly float epsilon = 1e-03f;
         private static readonly float epsilon = 1e-03f;
 
 
@@ -32,6 +45,11 @@ namespace BansheeEngine
         public float z;
         public float z;
         public float w;
         public float w;
 
 
+        /// <summary>
+        /// Accesses a specific component of the quaternion.
+        /// </summary>
+        /// <param name="index">Index of the component (0 - x, 1 - y, 2 - z, 3 - w).</param>
+        /// <returns>Value of the specific component.</returns>
         public float this[int index]
         public float this[int index]
         {
         {
             get
             get
@@ -72,6 +90,9 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Gets the positive x-axis of the coordinate system transformed by this quaternion.
+        /// </summary>
         public Vector3 Right
         public Vector3 Right
         {
         {
             get
             get
@@ -89,6 +110,9 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Gets the positive y-axis of the coordinate system transformed by this quaternion.
+        /// </summary>
         public Vector3 Up
         public Vector3 Up
         {
         {
             get
             get
@@ -107,6 +131,9 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Gets the positive z-axis of the coordinate system transformed by this quaternion.
+        /// </summary>
         public Vector3 Forward
         public Vector3 Forward
         {
         {
             get
             get
@@ -125,6 +152,10 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Returns the inverse of the quaternion. Quaternion must be non-zero. Inverse quaternion has the opposite
+        /// rotation of the original.
+        /// </summary>
         public Quaternion Inverse
         public Quaternion Inverse
         {
         {
             get
             get
@@ -135,6 +166,9 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Returns a normalized copy of the quaternion.
+        /// </summary>
         public Quaternion Normalized
         public Quaternion Normalized
         {
         {
             get
             get
@@ -145,6 +179,9 @@ namespace BansheeEngine
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Constructs a new quaternion with the specified components.
+        /// </summary>
         public Quaternion(float x, float y, float z, float w)
         public Quaternion(float x, float y, float z, float w)
         {
         {
             this.x = x;
             this.x = x;
@@ -191,21 +228,47 @@ namespace BansheeEngine
             return !(lhs == rhs);
             return !(lhs == rhs);
         }
         }
 
 
+        /// <summary>
+        /// Calculates a dot product between two quaternions.
+        /// </summary>
+        /// <param name="a">First quaternion.</param>
+        /// <param name="b">Second quaternion.</param>
+        /// <returns>Dot product between the two quaternions.</returns>
         public static float Dot(Quaternion a, Quaternion b)
         public static float Dot(Quaternion a, Quaternion b)
         {
         {
             return (a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
             return (a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
         }
         }
 
 
+        /// <summary>
+        /// Applies quaternion rotation to the specified point.
+        /// </summary>
+        /// <param name="point">Point to rotate.</param>
+        /// <returns>Point rotated by the quaternion.</returns>
         public Vector3 Rotate(Vector3 point)
         public Vector3 Rotate(Vector3 point)
         {
         {
             return ToRotationMatrix().Transform(point);
             return ToRotationMatrix().Transform(point);
         }
         }
 
 
+        /// <summary>
+        /// Initializes the quaternion with rotation that rotates from one direction to another.
+        /// </summary>
+        /// <param name="fromDirection">Rotation to start at.</param>
+        /// <param name="toDirection">Rotation to end at.</param>
         public void SetFromToRotation(Vector3 fromDirection, Vector3 toDirection)
         public void SetFromToRotation(Vector3 fromDirection, Vector3 toDirection)
         {
         {
             SetFromToRotation(fromDirection, toDirection, Vector3.zero);
             SetFromToRotation(fromDirection, toDirection, Vector3.zero);
         }
         }
 
 
+        /// <summary>
+        /// Initializes the quaternion with rotation that rotates from one direction to another.
+        /// </summary>
+        /// <param name="fromDirection">Rotation to start at.
+        /// </param>
+        /// <param name="toDirection">Rotation to end at.
+        /// </param>
+        /// <param name="fallbackAxis">Fallback axis to use if the from/to vectors are almost completely opposite.
+        /// Fallback axis should be perpendicular to both vectors.
+        /// </param>
         public void SetFromToRotation(Vector3 fromDirection, Vector3 toDirection, Vector3 fallbackAxis)
         public void SetFromToRotation(Vector3 fromDirection, Vector3 toDirection, Vector3 fallbackAxis)
         {
         {
 		    fromDirection.Normalize();
 		    fromDirection.Normalize();
@@ -216,7 +279,7 @@ namespace BansheeEngine
 		    // If dot == 1, vectors are the same
 		    // If dot == 1, vectors are the same
             if (d >= 1.0f)
             if (d >= 1.0f)
             {
             {
-                this = identity;
+                this = Identity;
                 return;
                 return;
             }
             }
 
 
@@ -252,6 +315,10 @@ namespace BansheeEngine
 		    }
 		    }
         }
         }
 
 
+        /// <summary>
+        /// Normalizes the quaternion.
+        /// </summary>
+        /// <returns>Length of the quaternion prior to normalization.</returns>
         public float Normalize()
         public float Normalize()
         {
         {
             float len = w*w+x*x+y*y+z*z;
             float len = w*w+x*x+y*y+z*z;
@@ -264,6 +331,9 @@ namespace BansheeEngine
             return len;
             return len;
         }
         }
 
 
+        /// <summary>
+        /// Calculates the inverse of the quaternion. Inverse quaternion has the opposite rotation of the original.
+        /// </summary>
         public void Invert()
         public void Invert()
         {
         {
             float fNorm = w * w + x * x + y * y + z * z;
             float fNorm = w * w + x * x + y * y + z * z;
@@ -277,15 +347,24 @@ namespace BansheeEngine
             }
             }
             else
             else
             {
             {
-                this = zero;
+                this = Zero;
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Initializes the quaternion so that it orients an object so it faces in te provided direction.
+        /// </summary>
+        /// <param name="forward">Direction to orient the object towards.</param>
         public void SetLookRotation(Vector3 forward)
         public void SetLookRotation(Vector3 forward)
         {
         {
             SetLookRotation(forward, Vector3.yAxis);
             SetLookRotation(forward, Vector3.yAxis);
         }
         }
 
 
+        /// <summary>
+        /// Initializes the quaternion so that it orients an object so it faces in te provided direction.
+        /// </summary>
+        /// <param name="forward">Direction to orient the object towards.</param>
+        /// <param name="up">Axis that determines the upward direction of the object.</param>
         public void SetLookRotation(Vector3 forward, Vector3 up)
         public void SetLookRotation(Vector3 forward, Vector3 up)
         {
         {
             Quaternion forwardRot = FromToRotation(Vector3.zAxis, forward);
             Quaternion forwardRot = FromToRotation(Vector3.zAxis, forward);
@@ -294,6 +373,20 @@ namespace BansheeEngine
             this = forwardRot * upRot;
             this = forwardRot * upRot;
         }
         }
 
 
+        /// <summary>
+        /// Performs spherical interpolation between two quaternions. Spherical interpolation neatly interpolates between
+        /// two rotations without modifying the size of the vector it is applied to (unlike linear interpolation).
+        /// </summary>
+        /// <param name="from">Start quaternion.
+        /// </param>
+        /// <param name="to">End quaternion.
+        /// </param>
+        /// <param name="t">Interpolation factor in range [0, 1] that determines how much to interpolate between
+        /// <paramref name="from"/> and <paramref name="to"/>.</param>
+        /// <param name="shortestPath">Should the interpolation be performed between the shortest or longest path between
+        /// the two quaternions.</param>
+        /// <returns>Interpolated quaternion representing a rotation between <paramref name="from"/> and 
+        /// <paramref name="to"/>.</returns>
         public static Quaternion Slerp(Quaternion from, Quaternion to, float t, bool shortestPath = false)
         public static Quaternion Slerp(Quaternion from, Quaternion to, float t, bool shortestPath = false)
         {
         {
             float cos = from.w*to.w + from.x*to.x + from.y*to.y + from.z*from.z;
             float cos = from.w*to.w + from.x*to.x + from.y*to.y + from.z*from.z;
@@ -311,40 +404,29 @@ namespace BansheeEngine
 
 
             if (MathEx.Abs(cos) < (1 - epsilon))
             if (MathEx.Abs(cos) < (1 - epsilon))
             {
             {
-                // Standard case (slerp)
                 float sin = MathEx.Sqrt(1 - (cos*cos));
                 float sin = MathEx.Sqrt(1 - (cos*cos));
                 float angle = MathEx.Atan2(sin, cos);
                 float angle = MathEx.Atan2(sin, cos);
                 float invSin = 1.0f / sin;
                 float invSin = 1.0f / sin;
-                float coeff0 = MathEx.Sin((1.0f - t) * angle) * invSin;
-                float coeff1 = MathEx.Sin(t * angle) * invSin;
-                return coeff0 * from + coeff1 * quat;
+                float a = MathEx.Sin((1.0f - t) * angle) * invSin;
+                float b = MathEx.Sin(t * angle) * invSin;
+
+                return a * from + b * quat;
             }
             }
             else
             else
             {
             {
-                // There are two situations:
-                // 1. "p" and "q" are very close (fCos ~= +1), so we can do a linear
-                //    interpolation safely.
-                // 2. "p" and "q" are almost inverse of each other (fCos ~= -1), there
-                //    are an infinite number of possibilities interpolation. but we haven't
-                //    have method to fix this case, so just use linear interpolation here.
                 Quaternion ret = (1.0f - t) * from + t * quat;
                 Quaternion ret = (1.0f - t) * from + t * quat;
 
 
-                // Taking the complement requires renormalization
                 ret.Normalize();
                 ret.Normalize();
                 return ret;
                 return ret;
             }
             }
         }
         }
 
 
-        public static Quaternion RotateTowards(Quaternion from, Quaternion to, Degree maxDeg)
-        {
-            Degree num = Angle(from, to);
-            if (num == 0.0f)
-                return to;
-
-            float t = MathEx.Min(1f, (float)(maxDeg / num));
-            return Slerp(from, to, t);
-        }
-
+        /// <summary>
+        /// Returns the inverse of the quaternion. Quaternion must be non-zero. Inverse quaternion has the opposite
+        /// rotation of the original.
+        /// </summary>
+        /// <param name="rotation">Quaternion to calculate the inverse for.</param>
+        /// <returns>Inverse of the provided quaternion.</returns>
         public static Quaternion Invert(Quaternion rotation)
         public static Quaternion Invert(Quaternion rotation)
         {
         {
             Quaternion copy = rotation;
             Quaternion copy = rotation;
@@ -353,11 +435,22 @@ namespace BansheeEngine
             return copy;
             return copy;
         }
         }
 
 
+        /// <summary>
+        /// Calculates an angle between two rotations.
+        /// </summary>
+        /// <param name="a">First rotation.</param>
+        /// <param name="b">Second rotation.</param>
+        /// <returns>Angle between the rotations, in degrees.</returns>
         public static Degree Angle(Quaternion a, Quaternion b)
         public static Degree Angle(Quaternion a, Quaternion b)
         {
         {
             return (MathEx.Acos(MathEx.Min(MathEx.Abs(Dot(a, b)), 1.0f)) * 2.0f * MathEx.Rad2Deg);
             return (MathEx.Acos(MathEx.Min(MathEx.Abs(Dot(a, b)), 1.0f)) * 2.0f * MathEx.Rad2Deg);
         }
         }
 
 
+        /// <summary>
+        /// Converts the quaternion rotation into axis/angle rotation.
+        /// </summary>
+        /// <param name="axis">Axis around which the rotation is performed.</param>
+        /// <param name="angle">Amount of rotation.</param>
         public void ToAxisAngle(out Vector3 axis, out Degree angle)
         public void ToAxisAngle(out Vector3 axis, out Degree angle)
         {
         {
             float fSqrLength = x*x+y*y+z*z;
             float fSqrLength = x*x+y*y+z*z;
@@ -379,13 +472,20 @@ namespace BansheeEngine
 		    }
 		    }
         }
         }
 
 
-        // Returns angles in degrees
+        /// <summary>
+        /// Converts the quaternion rotation into euler angle (pitch/yaw/roll) rotation.
+        /// </summary>
+        /// <returns>Rotation as euler angles, in degrees.</returns>
         public Vector3 ToEuler()
         public Vector3 ToEuler()
         {
         {
             Matrix3 matRot = ToRotationMatrix();
             Matrix3 matRot = ToRotationMatrix();
             return matRot.ToEulerAngles();
             return matRot.ToEulerAngles();
         }
         }
 
 
+        /// <summary>
+        /// Converts a quaternion rotation into a rotation matrix.
+        /// </summary>
+        /// <returns>Matrix representing the rotation.</returns>
         public Matrix3 ToRotationMatrix()
         public Matrix3 ToRotationMatrix()
         {
         {
             Matrix3 mat = new Matrix3();
             Matrix3 mat = new Matrix3();
@@ -416,6 +516,13 @@ namespace BansheeEngine
             return mat;
             return mat;
         }
         }
 
 
+        /// <summary>
+        /// Creates a quaternion with rotation that rotates from one direction to another.
+        /// </summary>
+        /// <param name="fromDirection">Rotation to start at.</param>
+        /// <param name="toDirection">Rotation to end at.</param>
+        /// <returns>Quaternion that rotates an object from <paramref name="fromDirection"/> to 
+        /// <paramref name="toDirection"/></returns>
         public static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection)
         public static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection)
         {
         {
             Quaternion q = new Quaternion();
             Quaternion q = new Quaternion();
@@ -423,6 +530,18 @@ namespace BansheeEngine
             return q;
             return q;
         }
         }
 
 
+        /// <summary>
+        /// Creates a quaternion with rotation that rotates from one direction to another.
+        /// </summary>
+        /// <param name="fromDirection">Rotation to start at.
+        /// </param>
+        /// <param name="toDirection">Rotation to end at.
+        /// </param>
+        /// <param name="fallbackAxis">Fallback axis to use if the from/to vectors are almost completely opposite.
+        /// Fallback axis should be perpendicular to both vectors.
+        /// </param>
+        /// <returns>Quaternion that rotates an object from <paramref name="fromDirection"/> to 
+        /// <paramref name="toDirection"/></returns>
         public static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection, Vector3 fallbackAxis)
         public static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection, Vector3 fallbackAxis)
         {
         {
             Quaternion q = new Quaternion();
             Quaternion q = new Quaternion();
@@ -430,6 +549,10 @@ namespace BansheeEngine
             return q;
             return q;
         }
         }
 
 
+        /// <summary>
+        /// Creates a quaternion that orients an object so it faces in te provided direction.
+        /// </summary>
+        /// <param name="forward">Direction to orient the object towards.</param>
         public static Quaternion LookRotation(Vector3 forward)
         public static Quaternion LookRotation(Vector3 forward)
         {
         {
             Quaternion quat = new Quaternion();
             Quaternion quat = new Quaternion();
@@ -438,6 +561,11 @@ namespace BansheeEngine
             return quat;
             return quat;
         }
         }
 
 
+        /// <summary>
+        /// Creates a quaternion that orients an object so it faces in te provided direction.
+        /// </summary>
+        /// <param name="forward">Direction to orient the object towards.</param>
+        /// <param name="up">Axis that determines the upward direction of the object.</param>
         public static Quaternion LookRotation(Vector3 forward, Vector3 up)
         public static Quaternion LookRotation(Vector3 forward, Vector3 up)
         {
         {
             Quaternion quat = new Quaternion();
             Quaternion quat = new Quaternion();
@@ -446,16 +574,32 @@ namespace BansheeEngine
             return quat;
             return quat;
         }
         }
 
 
+        /// <summary>
+        /// Converts the quaternion rotation into euler angle (pitch/yaw/roll) rotation.
+        /// </summary>
+        /// <param name="rotation">Quaternion to convert.</param>
+        /// <returns>Rotation as euler angles, in degrees.</returns>
         public static Vector3 ToEuler(Quaternion rotation)
         public static Vector3 ToEuler(Quaternion rotation)
         {
         {
             return rotation.ToEuler();
             return rotation.ToEuler();
         }
         }
 
 
-        public static void ToAxisAngle(Quaternion rotation, out Vector3 axis, out Degree angleDeg)
+        /// <summary>
+        /// Converts the quaternion rotation into axis/angle rotation.
+        /// </summary>
+        /// <param name="rotation">Quaternion to convert.</param>
+        /// <param name="axis">Axis around which the rotation is performed.</param>
+        /// <param name="angle">Amount of rotation.</param>
+        public static void ToAxisAngle(Quaternion rotation, out Vector3 axis, out Degree angle)
         {
         {
-            rotation.ToAxisAngle(out axis, out angleDeg);
+            rotation.ToAxisAngle(out axis, out angle);
         }
         }
 
 
+        /// <summary>
+        /// Creates a quaternion from a rotation matrix.
+        /// </summary>
+        /// <param name="rotMatrix">Rotation matrix to convert to quaternion.</param>
+        /// <returns>Newly created quaternion that has equivalent rotation as the provided rotation matrix.</returns>
         public static Quaternion FromRotationMatrix(Matrix3 rotMatrix)
         public static Quaternion FromRotationMatrix(Matrix3 rotMatrix)
         {
         {
             // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
             // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
@@ -505,11 +649,17 @@ namespace BansheeEngine
             return quat;
             return quat;
         }
         }
 
 
-        public static Quaternion FromAxisAngle(Vector3 axis, Degree angleDeg)
+        /// <summary>
+        /// Creates a quaternion from axis/angle rotation.
+        /// </summary>
+        /// <param name="axis">Axis around which the rotation is performed.</param>
+        /// <param name="angle">Amount of rotation.</param>
+        /// <returns>Quaternion that rotates an object around the specified axis for the specified amount.</returns>
+        public static Quaternion FromAxisAngle(Vector3 axis, Degree angle)
         {
         {
             Quaternion quat;
             Quaternion quat;
 
 
-            float halfAngle = (float)(0.5f*angleDeg*MathEx.Deg2Rad);
+            float halfAngle = (float)(0.5f*angle*MathEx.Deg2Rad);
             float sin = (float)MathEx.Sin(halfAngle);
             float sin = (float)MathEx.Sin(halfAngle);
             quat.w = (float)MathEx.Cos(halfAngle);
             quat.w = (float)MathEx.Cos(halfAngle);
             quat.x = sin * axis.x;
             quat.x = sin * axis.x;
@@ -519,13 +669,23 @@ namespace BansheeEngine
             return quat;
             return quat;
         }
         }
 
 
-        public static Quaternion FromEuler(Degree xDeg, Degree yDeg, Degree zDeg, EulerAngleOrder order = EulerAngleOrder.YXZ)
+        /// <summary>
+        /// Creates a quaternion from the provided euler angle (pitch/yaw/roll) rotation.
+        /// </summary>
+        /// <param name="xAngle">Pitch angle of rotation.</param>
+        /// <param name="yAngle">Yar angle of rotation.</param>
+        /// <param name="zAngle">Roll angle of rotation.</param>
+        /// <param name="order">The order in which rotations will be applied. Different rotations can be created depending
+        /// on the order.</param>
+        /// <returns>Quaternion that can rotate an object to the specified angles.</returns>
+        public static Quaternion FromEuler(Degree xAngle, Degree yAngle, Degree zAngle, 
+            EulerAngleOrder order = EulerAngleOrder.YXZ)
         {
         {
 		    EulerAngleOrderData l = EA_LOOKUP[(int)order];
 		    EulerAngleOrderData l = EA_LOOKUP[(int)order];
 
 
-		    Radian halfXAngle = xDeg * 0.5f;
-		    Radian halfYAngle = yDeg * 0.5f;
-		    Radian halfZAngle = zDeg * 0.5f;
+		    Radian halfXAngle = xAngle * 0.5f;
+		    Radian halfYAngle = yAngle * 0.5f;
+		    Radian halfZAngle = zAngle * 0.5f;
 
 
 		    float cx = MathEx.Cos(halfXAngle);
 		    float cx = MathEx.Cos(halfXAngle);
 		    float sx = MathEx.Sin(halfXAngle);
 		    float sx = MathEx.Sin(halfXAngle);
@@ -544,19 +704,25 @@ namespace BansheeEngine
 		    return (quats[l.a] * quats[l.b]) * quats[l.c];
 		    return (quats[l.a] * quats[l.b]) * quats[l.c];
         }
         }
 
 
-        /**
-         * @note Angles in degrees.
-         */
+        /// <summary>
+        /// Creates a quaternion from the provided euler angle (pitch/yaw/roll) rotation.
+        /// </summary>
+        /// <param name="euler">Euler angles in degrees.</param>
+        /// <param name="order">The order in which rotations will be applied. Different rotations can be created depending
+        /// on the order.</param>
+        /// <returns>Quaternion that can rotate an object to the specified angles.</returns>
         public static Quaternion FromEuler(Vector3 euler, EulerAngleOrder order = EulerAngleOrder.YXZ)
         public static Quaternion FromEuler(Vector3 euler, EulerAngleOrder order = EulerAngleOrder.YXZ)
         {
         {
             return FromEuler(euler.x, euler.y, euler.z, order);
             return FromEuler(euler.x, euler.y, euler.z, order);
         }
         }
 
 
+        /// <inheritdoc/>
         public override int GetHashCode()
         public override int GetHashCode()
         {
         {
             return x.GetHashCode() ^ y.GetHashCode() << 2 ^ z.GetHashCode() >> 2 ^ w.GetHashCode() >> 1;
             return x.GetHashCode() ^ y.GetHashCode() << 2 ^ z.GetHashCode() >> 2 ^ w.GetHashCode() >> 1;
         }
         }
 
 
+        /// <inheritdoc/>
         public override bool Equals(object other)
         public override bool Equals(object other)
         {
         {
             if (!(other is Quaternion))
             if (!(other is Quaternion))
@@ -569,6 +735,7 @@ namespace BansheeEngine
             return false;
             return false;
         }
         }
 
 
+        /// <inheritdoc/>
         public override string ToString()
         public override string ToString()
         {
         {
             return String.Format("({0}, {1}, {2}, {3})", x, y, z, w);
             return String.Format("({0}, {1}, {2}, {3})", x, y, z, w);

+ 39 - 3
MBansheeEngine/Math/Radian.cs

@@ -6,41 +6,74 @@ using System.Text;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+    /// <summary>
+    ///	Wrapper class which indicates a given angle value is in radians. Radian values are interchangeable with degree 
+    /// values, and conversions will be done automatically between them.
+    /// </summary>
     [StructLayout(LayoutKind.Sequential), SerializeObject]
     [StructLayout(LayoutKind.Sequential), SerializeObject]
-    public struct Radian
+    public struct Radian // Note: Must match C++ class Radian
     {
     {
 		readonly float value;
 		readonly float value;
 
 
+        /// <summary>
+        /// Creates a new radian value.
+        /// </summary>
+        /// <param name="value">Value in radians.</param>
 		public Radian(float value = 0.0f)
 		public Radian(float value = 0.0f)
 	    {
 	    {
 	        this.value = value;
 	        this.value = value;
 	    }
 	    }
 
 
+        /// <summary>
+        /// Creates a new radian value.
+        /// </summary>
+        /// <param name="d">Value in degrees.</param>
         public Radian(Degree d)
         public Radian(Degree d)
         {
         {
             this.value = d.Radians;
             this.value = d.Radians;
         }
         }
 
 
+        /// <summary>
+        /// Converts a undefined angle value to a radian value.
+        /// </summary>
+        /// <param name="value">Value in degrees.</param>
+        /// <returns>Radian object wrapping the value.</returns>
         public static implicit operator Radian(float value)
         public static implicit operator Radian(float value)
         {
         {
             return new Radian(value);
             return new Radian(value);
         }
         }
 
 
+        /// <summary>
+        /// Converts a degree angle value to a radian value.
+        /// </summary>
+        /// <param name="d">Value in degrees.</param>
+        /// <returns>Radian object wrapping the value.</returns>
         public static implicit operator Radian(Degree d)
         public static implicit operator Radian(Degree d)
         {
         {
             return new Radian(d.Radians);
             return new Radian(d.Radians);
         }
         }
 
 
-        public static explicit operator float(Radian d)
+        /// <summary>
+        /// Converts a radian value to a regular floating point value.
+        /// </summary>
+        /// <param name="r">Radian value to convert.</param>
+        /// <returns>Value in radians as floating point type.</returns>
+        public static explicit operator float(Radian r)
         {
         {
-            return d.value;
+            return r.value;
         }
         }
 
 
+        /// <summary>
+        /// Returns the value in degrees as a floating point type.
+        /// </summary>
         public float Degrees
         public float Degrees
         {
         {
             get { return value*MathEx.Rad2Deg; }
             get { return value*MathEx.Rad2Deg; }
         }
         }
 
 
+        /// <summary>
+        /// Returns the value in radians as a floating point type.
+        /// </summary>
         public float Radians
         public float Radians
         {
         {
             get { return value; }
             get { return value; }
@@ -126,6 +159,7 @@ namespace BansheeEngine
             return a.value != b.value;
             return a.value != b.value;
         }
         }
 
 
+        /// <inheritdoc/>
         public override bool Equals(object other)
         public override bool Equals(object other)
         {
         {
             if (!(other is Radian))
             if (!(other is Radian))
@@ -138,11 +172,13 @@ namespace BansheeEngine
             return false;
             return false;
         }
         }
 
 
+        /// <inheritdoc/>
         public override int GetHashCode()
         public override int GetHashCode()
         {
         {
             return value.GetHashCode();
             return value.GetHashCode();
         }
         }
 
 
+        /// <inheritdoc/>
         public override string ToString()
         public override string ToString()
         {
         {
             return value.ToString();
             return value.ToString();

+ 2 - 2
MBansheeEngine/Math/Ray.cs

@@ -37,8 +37,8 @@ namespace BansheeEngine
         {
         {
             Vector3 end = this * 1.0f;
             Vector3 end = this * 1.0f;
 
 
-            origin = matrix.MultiplyAffine(origin);
-            end = matrix.MultiplyAffine(end);
+            origin = matrix.MultiplyDirection(origin);
+            end = matrix.MultiplyDirection(end);
 
 
             direction = Vector3.Normalize(end - origin);
             direction = Vector3.Normalize(end - origin);
         }
         }