RenderStack 11.06.1
Public Member Functions | Static Public Member Functions | Public Attributes | Properties
RenderStack.Math.Matrix4 Struct Reference

Generic 4 by 4 matrix class - compatible with OpenGL conventions. More...

List of all members.

Public Member Functions

 Matrix4 (float _00, float _01, float _02, float _03, float _10, float _11, float _12, float _13, float _20, float _21, float _22, float _23, float _30, float _31, float _32, float _33)
void Set (Matrix4 m)
void SetLookAtBroken (Vector3 eye, Vector3 center, Vector3 up0)
Vector3 GetRow3 (int rowI)
Vector4 GetRow (int rowI)
Vector3 GetColumn3 (int columnI)
Vector4 GetColumn (int columnI)
Vector3 TransformPoint (Vector3 p)
Vector3 TransformDirection (Vector3 d)
Vector3 UnProject (float winx, float winy, float winz, float viewportX, float viewportY, float viewportWidth, float viewportHeight)
Vector2 ProjectToScreenSpace (Vector3 positionInWorld, float viewportX, float viewportY, float viewportWidth, float viewportHeight, out float depthInClip)
override string ToString ()
bool Equals (Matrix4 other)

Static Public Member Functions

static Matrix4 CreateLookAt (Vector3 eye, Vector3 center, Vector3 up)
static void CreateLookAt (Vector3 eye, Vector3 center, Vector3 up0, out Matrix4 result)
static void CreateProjection (float s, float p, float n, float f, float w, float h, Vector3 v, Vector3 e, out Matrix4 result)
static void CreateOrthographic (float left, float right, float bottom, float top, float near, float far, out Matrix4 result)
static void CreateOrthographicCentered (float width, float height, float near, float far, out Matrix4 result)
static void CreateFrustum (float left, float right, float bottom, float top, float near, float far, out Matrix4 result)
static void CreateFrustumSimple (float width, float height, float near, float far, out Matrix4 result)
static void CreatePerspective (float fovXRadians, float fovYRadians, float near, float far, out Matrix4 result)
static void CreatePerspectiveVertical (float fovYRadians, float aspectRatio, float near, float far, out Matrix4 result)
static void CreatePerspectiveHorizontal (float fovXRadians, float aspectRatio, float near, float far, out Matrix4 result)
static Matrix4 CreateTranslation (float x, float y, float z)
static void CreateTranslation (float x, float y, float z, out Matrix4 result)
static Matrix4 CreateRotation (float angleRadians, Vector3 axis)
static void CreateRotation (float angleRadians, Vector3 axis, out Matrix4 result)
static Matrix4 CreateScale (float x)
static void CreateScale (float s, out Matrix4 result)
static Matrix4 CreateScale (float x, float y, float z)
static void CreateScale (float x, float y, float z, out Matrix4 result)
static Vector4 operator* (Matrix4 l, Vector4 r)
static Vector3 operator* (Matrix4 l, Vector3 r)
static Matrix4 operator* (Matrix4 l, Matrix4 r)
static void Invert (Matrix4 mat, out Matrix4 result)
static Matrix4 Invert (Matrix4 mat)
static Matrix4 Transpose (Matrix4 mat)
static void Transpose (Matrix4 mat, out Matrix4 result)

Public Attributes

float _00
float _10
float _20
float _30
float _01
float _11
float _21
float _31
float _02
float _12
float _22
float _32
float _03
float _13
float _23
float _33

Properties

float this[int row, int column] [get]
static Matrix4 Identity [get]
float Trace3 [get]
float Trace [get]

Detailed Description

Note:
Mostly stable

Definition at line 135 of file Matrix4.cs.


Constructor & Destructor Documentation

RenderStack.Math.Matrix4.Matrix4 ( float  _00,
float  _01,
float  _02,
float  _03,
float  _10,
float  _11,
float  _12,
float  _13,
float  _20,
float  _21,
float  _22,
float  _23,
float  _30,
float  _31,
float  _32,
float  _33 
)

Definition at line 163 of file Matrix4.cs.

        {
            /*  Set the first column  */
            this._00 = _00;
            this._10 = _10;
            this._20 = _20;
            this._30 = _30;

            /*  Set the second column  */
            this._01 = _01;
            this._11 = _11;
            this._21 = _21;
            this._31 = _31;

            /*  Set the third column  */
            this._02 = _02;
            this._12 = _12;
            this._22 = _22;
            this._32 = _32;

            /*  Set the fourth column  */
            this._03 = _03;
            this._13 = _13;
            this._23 = _23;
            this._33 = _33;
        }

Member Function Documentation

void RenderStack.Math.Matrix4.Set ( Matrix4  m)
static Matrix4 RenderStack.Math.Matrix4.CreateLookAt ( Vector3  eye,
Vector3  center,
Vector3  up 
) [static]

Definition at line 220 of file Matrix4.cs.

Referenced by example.RenderToTexture.Application.OnLoad(), and example.Simple.Application.OnLoad().

        {
            Matrix4 matrix;
            CreateLookAt(eye, center, up, out matrix);
            return matrix;
        }
static void RenderStack.Math.Matrix4.CreateLookAt ( Vector3  eye,
Vector3  center,
Vector3  up0,
out Matrix4  result 
) [static]

Definition at line 231 of file Matrix4.cs.

References RenderStack.Math.Vector3.Cross(), RenderStack.Math.Vector3.MinAxis, RenderStack.Math.Vector3.Normalize(), RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector3.Z.

        {
            Vector3 back    = Vector3.Normalize(eye - center);
            if(up0 == back)
            {
                up0 = back.MinAxis;
            }

            Vector3 right   = Vector3.Normalize(Vector3.Cross(up0, back));
            Vector3 up      = Vector3.Cross(back, right);

            /*  right axis = column0  */ 
            result._00 = right.X;
            result._10 = right.Y;
            result._20 = right.Z;

            /*  up axis = column1  */ 
            result._01 = up.X;
            result._11 = up.Y;
            result._21 = up.Z;

            /*  back axis = column2 */ 
            result._02 = back.X;
            result._12 = back.Y;
            result._22 = back.Z;

            result._03 = eye.X;
            result._13 = eye.Y;
            result._23 = eye.Z;

            result._30 = 0.0f;
            result._31 = 0.0f;
            result._32 = 0.0f;
            result._33 = 1.0f;
        }
void RenderStack.Math.Matrix4.SetLookAtBroken ( Vector3  eye,
Vector3  center,
Vector3  up0 
)

Definition at line 272 of file Matrix4.cs.

References RenderStack.Math.Vector3.Cross(), RenderStack.Math.Vector3.Dot(), RenderStack.Math.Vector3.Normalize(), RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector3.Z.

        {
            Vector3 view    = Vector3.Normalize(center - eye);
            Vector3 right   = Vector3.Normalize(Vector3.Cross(up0, view));
            Vector3 up      = Vector3.Cross(view, right);

            /*  right axis = row0  */ 
            _00 = right.X;
            _01 = right.Y;
            _02 = right.Z;
            _03 = -Vector3.Dot(right, eye);

            /*  up axis = row1  */ 
            _10 = up.X;
            _11 = up.Y;
            _12 = up.Z;
            _13 = -Vector3.Dot(up, eye);

            /*  view axis = row2 */ 
            _20 = view.X;
            _21 = view.Y;
            _22 = view.Z;
            _23 = -Vector3.Dot(view, eye);

            _30 = 0.0f;
            _31 = 0.0f;
            _32 = 0.0f;
            _33 = 1.0f;
        }
Vector3 RenderStack.Math.Matrix4.GetRow3 ( int  rowI)

Definition at line 338 of file Matrix4.cs.

References RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector3.Z.

        {
            Vector3 row;

            switch(rowI)
            {
                case 0: row.X = _00; row.Y = _01; row.Z = _02; break;
                case 1: row.X = _10; row.Y = _11; row.Z = _12; break;
                case 2: row.X = _20; row.Y = _21; row.Z = _22; break;
                case 3: row.X = _30; row.Y = _31; row.Z = _32; break;
                default: row.X = 0; row.Y = 0; row.Z = 0; break;
            }
            return row;
        }
Vector4 RenderStack.Math.Matrix4.GetRow ( int  rowI)

Definition at line 353 of file Matrix4.cs.

References RenderStack.Math.Vector4.W, RenderStack.Math.Vector4.X, RenderStack.Math.Vector4.Y, and RenderStack.Math.Vector4.Z.

        {
            Vector4 row;

            switch(rowI)
            {
                case 0: row.X = _00; row.Y = _01; row.Z = _02; row.W = _03; break;
                case 1: row.X = _10; row.Y = _11; row.Z = _12; row.W = _13; break;
                case 2: row.X = _20; row.Y = _21; row.Z = _22; row.W = _23; break;
                case 3: row.X = _30; row.Y = _31; row.Z = _32; row.W = _33; break;
                default: row.X = 0; row.Y = 0; row.Z = 0; row.W = 0; break;
            }
            return row;
        }
Vector3 RenderStack.Math.Matrix4.GetColumn3 ( int  columnI)

Definition at line 368 of file Matrix4.cs.

References RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector3.Z.

Referenced by example.UI.FrameController.SetTransform(), and example.Scene.FrameController.SetTransform().

        {
            Vector3 column;

            switch(columnI)
            {
                case 0: column.X = _00; column.Y = _10; column.Z = _20; break;
                case 1: column.X = _01; column.Y = _11; column.Z = _21; break;
                case 2: column.X = _02; column.Y = _12; column.Z = _22; break;
                case 3: column.X = _03; column.Y = _13; column.Z = _23; break;
                default: column.X = 0; column.Y = 0; column.Z = 0; break;
            }
            return column;
        }
Vector4 RenderStack.Math.Matrix4.GetColumn ( int  columnI)

Definition at line 383 of file Matrix4.cs.

References RenderStack.Math.Vector4.W, RenderStack.Math.Vector4.X, RenderStack.Math.Vector4.Y, and RenderStack.Math.Vector4.Z.

        {
            Vector4 column;

            switch(columnI)
            {
                case 0: column.X = _00; column.Y = _10; column.Z = _20; column.W = _30; break;
                case 1: column.X = _01; column.Y = _11; column.Z = _21; column.W = _31; break;
                case 2: column.X = _02; column.Y = _12; column.Z = _22; column.W = _32; break;
                case 3: column.X = _03; column.Y = _13; column.Z = _23; column.W = _33; break;
                default: column.X = 0; column.Y = 0; column.Z = 0; column.W = 0; break;
            }
            return column;
        }
static void RenderStack.Math.Matrix4.CreateProjection ( float  s,
float  p,
float  n,
float  f,
float  w,
float  h,
Vector3  v,
Vector3  e,
out Matrix4  result 
) [static]

Definition at line 474 of file Matrix4.cs.

References RenderStack.Math.Matrix4._00, RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector3.Z.

Referenced by RenderStack.Scene.Transform.SetProjection().

        {
            result._00 =  2.0f / w;
            result._01 =  0.0f;
            result._02 = (2.0f * (e.X - v.X) + s) / (w * (v.Z - e.Z));
            result._03 = (2.0f * ((v.X * e.Z) - (e.X * v.Z)) - s * v.Z) / (w * (v.Z - e.Z));

            result._10 =  0.0f;
            result._11 =  2.0f / h;
            result._12 =  2.0f * (e.Y - v.Y) / (h * (v.Z - e.Z));
            result._13 =  2.0f * ((v.Y * e.Z) - (e.Y * v.Z)) / (h * (v.Z - e.Z));

            result._20 =  0.0f;
            result._21 =  0.0f;
            result._22 = (2.0f * (v.Z * (1.0f - p) - e.Z) + p * (f + n)) / ((f - n) * (v.Z - e.Z));
            result._23 = -((v.Z * (1.0f - p) - e.Z) * (f + n) + 2.0f * f * n * p) / ((f - n) * (v.Z - e.Z));

            result._30 =  0.0f;
            result._31 =  0.0f;
            result._32 = p / (v.Z - e.Z);
            result._33 = (v.Z * (1.0f - p) - e.Z) / (v.Z - e.Z);

            /*  Changes handedness  */
            result._02 = -result._02;
            result._12 = -result._12;
            result._22 = -result._22;
            result._32 = -result._32;
        }
static void RenderStack.Math.Matrix4.CreateOrthographic ( float  left,
float  right,
float  bottom,
float  top,
float  near,
float  far,
out Matrix4  result 
) [static]

Definition at line 511 of file Matrix4.cs.

Referenced by RenderStack.Scene.Transform.SetOrthographic().

        {
            float width  = right - left;
            float height = top - bottom;
            float depth  = far - near;
            float x     =  2.0f / width;
            float y     =  2.0f / height;
            float z     = -2.0f / depth;
            float xt    = -(right + left) / width;
            float yt    = -(top + bottom) / height;
            float zt    = -(far + near) / depth;

            result._00 = x;    result._01 = 0.0f; result._02 = 0.0f; result._03 = xt;
            result._10 = 0.0f; result._11 = y;    result._12 = 0.0f; result._13 = yt;
            result._20 = 0.0f; result._21 = 0.0f; result._22 = z;    result._23 = zt;
            result._30 = 0.0f; result._31 = 0.0f; result._32 = 0.0f; result._33 = 1.0f;
        }
static void RenderStack.Math.Matrix4.CreateOrthographicCentered ( float  width,
float  height,
float  near,
float  far,
out Matrix4  result 
) [static]

Definition at line 528 of file Matrix4.cs.

Referenced by RenderStack.Scene.Transform.SetOrthographicCentered().

        {
            float depth = far - near;
            float faddn = far + near;
            float x     =  2.0f / width;
            float y     =  2.0f / height;
            float z     = -2.0f / depth;
            float zt    = -faddn / depth;

            result._00 = x;    result._01 = 0.0f; result._02 = 0.0f; result._03 = 0.0f;
            result._10 = 0.0f; result._11 = y;    result._12 = 0.0f; result._13 = 0.0f;
            result._20 = 0.0f; result._21 = 0.0f; result._22 = z;    result._23 = zt;
            result._30 = 0.0f; result._31 = 0.0f; result._32 = 0.0f; result._33 = 1.0f;
        }
static void RenderStack.Math.Matrix4.CreateFrustum ( float  left,
float  right,
float  bottom,
float  top,
float  near,
float  far,
out Matrix4  result 
) [static]

Definition at line 542 of file Matrix4.cs.

Referenced by RenderStack.Scene.Transform.SetFrustum().

        {
            float x, y, a, b, c, d;

            //  TODO Do we need to do something about potential division by zero?
            x =  (2.0f  * near)   / (right - left);
            y =  (2.0f  * near)   / (top   - bottom);
            a =  (right + left)   / (right - left);
            b =  (top   + bottom) / (top   - bottom);
            c = -(far   + near)   / (far   - near);
            d = -(2.0f * far * near) / (far - near);

            result._00 = x;     result._01 = 0.0f;  result._02 = a;      result._03 = 0.0f;
            result._10 = 0.0f;  result._11 = y;     result._12 = b;      result._13 = 0.0f;
            result._20 = 0.0f;  result._21 = 0.0f;  result._22 = c;      result._23 = d;
            result._30 = 0.0f;  result._31 = 0.0f;  result._32 = -1.0f;  result._33 = 0.0f;
        }
static void RenderStack.Math.Matrix4.CreateFrustumSimple ( float  width,
float  height,
float  near,
float  far,
out Matrix4  result 
) [static]

Definition at line 559 of file Matrix4.cs.

Referenced by RenderStack.Scene.Transform.SetFrustumSimple().

        {
            float x;
            float y;
            float c;
            float d;
            float near2;
            float far_plus__near;
            float far_minus_near;
            float far_times_near;

            near2          = 2.0f * near;
            far_plus__near = far + near;
            far_minus_near = far - near;
            far_times_near = far * near;

            x = near2 / width;
            y = near2 / height;
            c = -       far_plus__near / far_minus_near;
            d = -2.0f * far_times_near / far_minus_near;

            result._00 = x; result._01 = 0; result._02 = 0;     result._03 = 0;
            result._10 = 0; result._11 = y; result._12 = 0;     result._13 = 0;
            result._20 = 0; result._21 = 0; result._22 = c;     result._23 = d;
            result._30 = 0; result._31 = 0; result._32 = -1.0f; result._33 = 0;
        }
static void RenderStack.Math.Matrix4.CreatePerspective ( float  fovXRadians,
float  fovYRadians,
float  near,
float  far,
out Matrix4  result 
) [static]

Definition at line 585 of file Matrix4.cs.

Referenced by RenderStack.Scene.Transform.SetPerspective().

        {
            fovYRadians = System.Math.Max(fovYRadians, 0.01f);
            fovYRadians = System.Math.Min(fovYRadians, (float)(System.Math.PI * 0.99));
            fovXRadians = System.Math.Max(fovXRadians, 0.01f);
            fovXRadians = System.Math.Min(fovXRadians, (float)(System.Math.PI * 0.99));
            float tanXHalfAngle = (float)System.Math.Tan(fovXRadians * 0.5);
            float tanYHalfAngle = (float)System.Math.Tan(fovYRadians * 0.5);
            float width         = 2.0f * near * tanXHalfAngle;
            float height        = 2.0f * near * tanYHalfAngle;
            CreateFrustumSimple(width, height, near, far, out result);
        }
static void RenderStack.Math.Matrix4.CreatePerspectiveVertical ( float  fovYRadians,
float  aspectRatio,
float  near,
float  far,
out Matrix4  result 
) [static]

Definition at line 597 of file Matrix4.cs.

Referenced by RenderStack.Scene.Transform.SetPerspectiveVertical().

        {
            fovYRadians = System.Math.Max(fovYRadians, 0.01f);
            fovYRadians = System.Math.Min(fovYRadians, (float)(System.Math.PI * 0.99));
            float tanHalfAngle = (float)System.Math.Tan(fovYRadians * 0.5);
            float height       = 2.0f * near * tanHalfAngle;
            float width        = height * aspectRatio;

            CreateFrustumSimple(width, height, near, far, out result);
        }
static void RenderStack.Math.Matrix4.CreatePerspectiveHorizontal ( float  fovXRadians,
float  aspectRatio,
float  near,
float  far,
out Matrix4  result 
) [static]

Definition at line 607 of file Matrix4.cs.

Referenced by RenderStack.Scene.Transform.SetPerspectiveHorizontal().

        {
            fovXRadians = System.Math.Max(fovXRadians, 0.01f);
            fovXRadians = System.Math.Min(fovXRadians, (float)(System.Math.PI * 0.99));
            float tanHalfAngle = (float)System.Math.Tan(fovXRadians * 0.5);
            float width        = 2.0f * near * tanHalfAngle;
            float height       = width / aspectRatio;

            CreateFrustumSimple(width, height, near, far, out result);
        }
static Matrix4 RenderStack.Math.Matrix4.CreateTranslation ( float  x,
float  y,
float  z 
) [static]

Definition at line 619 of file Matrix4.cs.

Referenced by example.UI.Slider.BeginPlace(), example.Simple.Application.OnLoad(), and RenderStack.Scene.Transform.SetTranslation().

        {
            Matrix4 matrix;
            CreateTranslation(x, y, z, out matrix);
            return matrix;
        }
static void RenderStack.Math.Matrix4.CreateTranslation ( float  x,
float  y,
float  z,
out Matrix4  result 
) [static]

Definition at line 625 of file Matrix4.cs.

        {
            /*  Translation goes to fourth column  */

            /*  Set the first column  */
            result._00 = 1.0f;
            result._10 = 0.0f;
            result._20 = 0.0f;
            result._30 = 0.0f;

            /*  Set the second column  */
            result._01 = 0.0f;
            result._11 = 1.0f;
            result._21 = 0.0f;
            result._31 = 0.0f;

            /*  Set the third column  */
            result._02 = 0.0f;
            result._12 = 0.0f;
            result._22 = 1.0f;
            result._32 = 0.0f;    /*  Opengl 15th  */

            /*  Set the fourth column  */
            result._03 = x;
            result._13 = y;
            result._23 = z;
            result._33 = 1.0f;
        }
static Matrix4 RenderStack.Math.Matrix4.CreateRotation ( float  angleRadians,
Vector3  axis 
) [static]
static void RenderStack.Math.Matrix4.CreateRotation ( float  angleRadians,
Vector3  axis,
out Matrix4  result 
) [static]

Definition at line 659 of file Matrix4.cs.

References RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector3.Z.

        {
            float rsin = (float)System.Math.Sin(angleRadians);
            float rcos = (float)System.Math.Cos(angleRadians);

            float u = axis.X;
            float v = axis.Y;
            float w = axis.Z;

            /*  Set the first row  */
            result._00 =      rcos + u * u * (1 - rcos);
            result._01 = -w * rsin + v * u * (1 - rcos);
            result._02 =  v * rsin + w * u * (1 - rcos);
            result._03 =                              0;

            /*  Set the second row  */
            result._10 =  w * rsin + u * v * (1 - rcos);
            result._11 =      rcos + v * v * (1 - rcos);
            result._12 = -u * rsin + w * v * (1 - rcos);
            result._13 =                              0;

            /*  Set the third row  */
            result._20 = -v * rsin + u * w * (1 - rcos);
            result._21 =  u * rsin + v * w * (1 - rcos);
            result._22 =      rcos + w * w * (1 - rcos);
            result._23 =                              0;

            /*  Set the fourth row  */
            result._30 = 0.0f;
            result._31 = 0.0f;
            result._32 = 0.0f;
            result._33 = 1.0f;
        }
static Matrix4 RenderStack.Math.Matrix4.CreateScale ( float  x) [static]

Definition at line 692 of file Matrix4.cs.

Referenced by RenderStack.Scene.Transform.SetScale().

        {
            Matrix4 matrix;
            CreateScale(x, out matrix);
            return matrix;
        }
static void RenderStack.Math.Matrix4.CreateScale ( float  s,
out Matrix4  result 
) [static]

Definition at line 698 of file Matrix4.cs.

        {
            /*  Set the first column  */
            result._00 = s;
            result._10 = 0.0f;
            result._20 = 0.0f;
            result._30 = 0.0f;

            /*  Set the second column  */
            result._01 = 0.0f;
            result._11 = s;
            result._21 = 0.0f;
            result._31 = 0.0f;

            /*  Set the third column  */
            result._02 = 0.0f;
            result._12 = 0.0f;
            result._22 = s;
            result._32 = 0.0f;

            /*  Set the fourth column  */
            result._03 = 0.0f;  /*  X translation  */
            result._13 = 0.0f;  /*  Y translation  */
            result._23 = 0.0f;  /*  Z translation  */
            result._33 = 1.0f;
        }
static Matrix4 RenderStack.Math.Matrix4.CreateScale ( float  x,
float  y,
float  z 
) [static]

Definition at line 724 of file Matrix4.cs.

        {
            Matrix4 matrix;
            CreateScale(x, y, z, out matrix);
            return matrix;
        }
static void RenderStack.Math.Matrix4.CreateScale ( float  x,
float  y,
float  z,
out Matrix4  result 
) [static]

Definition at line 730 of file Matrix4.cs.

        {
            /*  Set the first column  */
            result._00 = x;
            result._10 = 0.0f;
            result._20 = 0.0f;
            result._30 = 0.0f;

            /*  Set the second column  */
            result._01 = 0.0f;
            result._11 = y;
            result._21 = 0.0f;
            result._31 = 0.0f;

            /*  Set the third column  */
            result._02 = 0.0f;
            result._12 = 0.0f;
            result._22 = z;
            result._32 = 0.0f;

            /*  Set the fourth column  */
            result._03 = 0.0f;  /*  X translation  */
            result._13 = 0.0f;  /*  Y translation  */
            result._23 = 0.0f;  /*  Z translation  */
            result._33 = 1.0f;
        }
static Vector4 RenderStack.Math.Matrix4.operator* ( Matrix4  l,
Vector4  r 
) [static]
static Vector3 RenderStack.Math.Matrix4.operator* ( Matrix4  l,
Vector3  r 
) [static]
static Matrix4 RenderStack.Math.Matrix4.operator* ( Matrix4  l,
Matrix4  r 
) [static]

Definition at line 914 of file Matrix4.cs.

References RenderStack.Math.Matrix4._00, RenderStack.Math.Matrix4._01, RenderStack.Math.Matrix4._02, RenderStack.Math.Matrix4._03, RenderStack.Math.Matrix4._10, RenderStack.Math.Matrix4._11, RenderStack.Math.Matrix4._12, RenderStack.Math.Matrix4._13, RenderStack.Math.Matrix4._20, RenderStack.Math.Matrix4._21, RenderStack.Math.Matrix4._22, RenderStack.Math.Matrix4._23, RenderStack.Math.Matrix4._30, RenderStack.Math.Matrix4._31, RenderStack.Math.Matrix4._32, and RenderStack.Math.Matrix4._33.

        {
            Matrix4 p;

            /* _rw  row column  */
            /*  left: rows  */
            /*  right: columns */ 

            /*  First column  */ 

            p._00 = l._00 * r._00  +  l._01 * r._10  +  l._02 * r._20  +  l._03 * r._30;
            p._10 = l._10 * r._00  +  l._11 * r._10  +  l._12 * r._20  +  l._13 * r._30;
            p._20 = l._20 * r._00  +  l._21 * r._10  +  l._22 * r._20  +  l._23 * r._30;
            p._30 = l._30 * r._00  +  l._31 * r._10  +  l._32 * r._20  +  l._33 * r._30;

            /*  Second column  */
            p._01 = l._00 * r._01  +  l._01 * r._11  +  l._02 * r._21  +  l._03 * r._31;
            p._11 = l._10 * r._01  +  l._11 * r._11  +  l._12 * r._21  +  l._13 * r._31;
            p._21 = l._20 * r._01  +  l._21 * r._11  +  l._22 * r._21  +  l._23 * r._31;
            p._31 = l._30 * r._01  +  l._31 * r._11  +  l._32 * r._21  +  l._33 * r._31;

            /*  Third column  */
            p._02 = l._00 * r._02  +  l._01 * r._12  +  l._02 * r._22  +  l._03 * r._32;
            p._12 = l._10 * r._02  +  l._11 * r._12  +  l._12 * r._22  +  l._13 * r._32;
            p._22 = l._20 * r._02  +  l._21 * r._12  +  l._22 * r._22  +  l._23 * r._32;
            p._32 = l._30 * r._02  +  l._31 * r._12  +  l._32 * r._22  +  l._33 * r._32;

            /*  Fourth column  */
            p._03 = l._00 * r._03  +  l._01 * r._13  +  l._02 * r._23  +  l._03 * r._33;
            p._13 = l._10 * r._03  +  l._11 * r._13  +  l._12 * r._23  +  l._13 * r._33;
            p._23 = l._20 * r._03  +  l._21 * r._13  +  l._22 * r._23  +  l._23 * r._33;
            p._33 = l._30 * r._03  +  l._31 * r._13  +  l._32 * r._23  +  l._33 * r._33;
            return p;
        }
Vector3 RenderStack.Math.Matrix4.TransformPoint ( Vector3  p)

Definition at line 951 of file Matrix4.cs.

References RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector3.Z.

        {
            Vector3 tp;
            tp.X = _00 * p.X + _01 * p.Y + _02 * p.Z + _03;
            tp.Y = _10 * p.X + _11 * p.Y + _12 * p.Z + _13;
            tp.Z = _20 * p.X + _21 * p.Y + _22 * p.Z + _23;
            return tp;
        }
Vector3 RenderStack.Math.Matrix4.TransformDirection ( Vector3  d)

Definition at line 959 of file Matrix4.cs.

References RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector3.Z.

        {
            Vector3 tp;
            tp.X = _00 * d.X + _01 * d.Y + _02 * d.Z;
            tp.Y = _10 * d.X + _11 * d.Y + _12 * d.Z;
            tp.Z = _20 * d.X + _21 * d.Y + _22 * d.Z;
            return tp;
        }
Vector3 RenderStack.Math.Matrix4.UnProject ( float  winx,
float  winy,
float  winz,
float  viewportX,
float  viewportY,
float  viewportWidth,
float  viewportHeight 
)

Definition at line 968 of file Matrix4.cs.

References RenderStack.Math.Vector4.W, RenderStack.Math.Vector4.X, RenderStack.Math.Vector4.Y, and RenderStack.Math.Vector4.Z.

        {
            Vector4 @in;
            Vector4 @out;

            @in.X = (winx - viewportX + 0.5f) / viewportWidth  * 2.0f - 1.0f;
            @in.Y = (winy - viewportY + 0.5f) / viewportHeight * 2.0f - 1.0f;
            @in.Z = 2.0f * winz - 1.0f;
            @in.W = 1.0f;

            //  Objects coordinates
            @out = this * @in;
            if(@out.W == 0.0f)
            {
                throw new ArgumentException();
            }

            return new Vector3(@out.X / @out.W, @out.Y / @out.W, @out.Z / @out.W);
        }
Vector2 RenderStack.Math.Matrix4.ProjectToScreenSpace ( Vector3  positionInWorld,
float  viewportX,
float  viewportY,
float  viewportWidth,
float  viewportHeight,
out float  depthInClip 
)

Definition at line 997 of file Matrix4.cs.

References RenderStack.Math.Vector4.Homogenize(), RenderStack.Math.Vector4.W, RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector4.Z.

        {
            //  Apply projection
            Vector4 positionInClip = this * new Vector4(positionInWorld, 1.0f);

            // depthInClip = positionInClip.Z;
            depthInClip = positionInClip.Z / positionInClip.W;

            //  Normalized device coordinate
            Vector3 positionInNDC = Vector4.Homogenize(positionInClip);

            //  window coordinate
            Vector2 positionInScreen = new Vector2(
                (0.5f + (positionInNDC.X * 0.5f)) * viewportWidth  + viewportX,
                (0.5f + (positionInNDC.Y * 0.5f)) * viewportHeight + viewportY
            );

            return positionInScreen;
        }
override string RenderStack.Math.Matrix4.ToString ( )

Definition at line 1024 of file Matrix4.cs.

        {
            return String.Format(
                "\t{0,3}, {1,3}, {2,3}, {3,3}\n" +
                "\t{4,3}, {5,3}, {6,3}, {7,3}\n" + 
                "\t{8,3}, {9,3}, {10,3}, {11,3}\n" + 
                "\t{12,3}, {13,3}, {14,3}, {15,3}\n",
                _00, _01, _02, _03,
                _10, _11, _12, _13,
                _20, _21, _22, _23,
                _30, _31, _32, _33
            );
        }
static void RenderStack.Math.Matrix4.Invert ( Matrix4  mat,
out Matrix4  result 
) [static]

Definition at line 1042 of file Matrix4.cs.

References RenderStack.Math.Matrix4._00, RenderStack.Math.Matrix4._01, RenderStack.Math.Matrix4._02, RenderStack.Math.Matrix4._03, RenderStack.Math.Matrix4._10, RenderStack.Math.Matrix4._11, RenderStack.Math.Matrix4._12, RenderStack.Math.Matrix4._13, RenderStack.Math.Matrix4._20, RenderStack.Math.Matrix4._21, RenderStack.Math.Matrix4._22, RenderStack.Math.Matrix4._23, RenderStack.Math.Matrix4._30, RenderStack.Math.Matrix4._31, RenderStack.Math.Matrix4._32, and RenderStack.Math.Matrix4._33.

Referenced by RenderStack.Scene.Transform.Catenate(), RenderStack.Scene.Transform.FixInverse(), RenderStack.Scene.Transform.Set(), RenderStack.Scene.Transform.SetFrustum(), RenderStack.Scene.Transform.SetFrustumSimple(), RenderStack.Scene.Transform.SetOrthographic(), RenderStack.Scene.Transform.SetOrthographicCentered(), RenderStack.Scene.Transform.SetPerspective(), RenderStack.Scene.Transform.SetPerspectiveHorizontal(), RenderStack.Scene.Transform.SetPerspectiveVertical(), RenderStack.Scene.Transform.SetProjection(), RenderStack.Scene.Transform.Transform(), and RenderStack.Geometry.Geometry.Transform().

        {
            colIdx[0] = 0; colIdx[1] = 0; colIdx[2] = 0; colIdx[3] = 0;
            rowIdx[0] = 0; rowIdx[1] = 0; rowIdx[2] = 0; rowIdx[3] = 0;
            pivotIdx[0] = -1; pivotIdx[1] = -1; pivotIdx[2] = -1; pivotIdx[3] = -1;

            // convert the matrix to an array for easy looping
#if true
            inverse[0,0] = mat._00; inverse[0,1] = mat._01; inverse[0,2] = mat._02; inverse[0,3] = mat._03;
            inverse[1,0] = mat._10; inverse[1,1] = mat._11; inverse[1,2] = mat._12; inverse[1,3] = mat._13;
            inverse[2,0] = mat._20; inverse[2,1] = mat._21; inverse[2,2] = mat._22; inverse[2,3] = mat._23;
            inverse[3,0] = mat._30; inverse[3,1] = mat._31; inverse[3,2] = mat._32; inverse[3,3] = mat._33;
#else
            inverse[0,0] = mat._00; inverse[1,0] = mat._01; inverse[2,0] = mat._02; inverse[3,0] = mat._03;
            inverse[0,1] = mat._00; inverse[1,1] = mat._01; inverse[2,1] = mat._02; inverse[3,1] = mat._03;
            inverse[0,2] = mat._00; inverse[1,2] = mat._01; inverse[2,2] = mat._02; inverse[3,2] = mat._03;
            inverse[0,3] = mat._00; inverse[1,3] = mat._01; inverse[2,3] = mat._02; inverse[3,3] = mat._03;
#endif
            int icol = 0;
            int irow = 0;
            for (int i = 0; i < 4; i++)
            {
                // Find the largest pivot value
                float maxPivot = 0.0f;
                for (int j = 0; j < 4; j++)
                {
                    if (pivotIdx[j] != 0)
                    {
                        for (int k = 0; k < 4; ++k)
                        {
                            if (pivotIdx[k] == -1)
                            {
                                float absVal = System.Math.Abs(inverse[j, k]);
                                if (absVal > maxPivot)
                                {
                                    maxPivot = absVal;
                                    irow = j;
                                    icol = k;
                                }
                            }
                            else if (pivotIdx[k] > 0)
                            {
                                result._00 = mat._00; result._01 = mat._01; result._02 = mat._02; result._03 = mat._03;
                                result._10 = mat._10; result._11 = mat._11; result._12 = mat._12; result._13 = mat._13;
                                result._20 = mat._20; result._21 = mat._21; result._22 = mat._22; result._23 = mat._23;
                                result._30 = mat._30; result._31 = mat._31; result._32 = mat._32; result._33 = mat._33;
                                return;
                            }
                        }
                    }
                }

                ++(pivotIdx[icol]);

                // Swap rows over so pivot is on diagonal
                if (irow != icol)
                {
                    for (int k = 0; k < 4; ++k)
                    {
                        float f = inverse[irow, k];
                        inverse[irow, k] = inverse[icol, k];
                        inverse[icol, k] = f;
                    }
                }

                rowIdx[i] = irow;
                colIdx[i] = icol;

                float pivot = inverse[icol, icol];
                // check for singular matrix
                if (pivot == 0.0f)
                {
                    throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
                    //return mat;
                }

                // Scale row so it has a unit diagonal
                float oneOverPivot = 1.0f / pivot;
                inverse[icol, icol] = 1.0f;
                for (int k = 0; k < 4; ++k)
                    inverse[icol, k] *= oneOverPivot;

                // Do elimination of non-diagonal elements
                for (int j = 0; j < 4; ++j)
                {
                    // check this isn't on the diagonal
                    if (icol != j)
                    {
                        float f = inverse[j, icol];
                        inverse[j, icol] = 0.0f;
                        for (int k = 0; k < 4; ++k)
                            inverse[j, k] -= inverse[icol, k] * f;
                    }
                }
            }

            for (int j = 3; j >= 0; --j)
            {
                int ir = rowIdx[j];
                int ic = colIdx[j];
                for (int k = 0; k < 4; ++k)
                {
                    float f = inverse[k, ir];
                    inverse[k, ir] = inverse[k, ic];
                    inverse[k, ic] = f;
                }
            }

            result._00 = inverse[0, 0]; result._01 = inverse[0, 1]; result._02 = inverse[0, 2]; result._03 = inverse[0, 3];
            result._10 = inverse[1, 0]; result._11 = inverse[1, 1]; result._12 = inverse[1, 2]; result._13 = inverse[1, 3];
            result._20 = inverse[2, 0]; result._21 = inverse[2, 1]; result._22 = inverse[2, 2]; result._23 = inverse[2, 3];
            result._30 = inverse[3, 0]; result._31 = inverse[3, 1]; result._32 = inverse[3, 2]; result._33 = inverse[3, 3];
        }
static Matrix4 RenderStack.Math.Matrix4.Invert ( Matrix4  mat) [static]

Definition at line 1155 of file Matrix4.cs.

References RenderStack.Math.Matrix4._00, RenderStack.Math.Matrix4._01, RenderStack.Math.Matrix4._02, RenderStack.Math.Matrix4._03, RenderStack.Math.Matrix4._10, RenderStack.Math.Matrix4._11, RenderStack.Math.Matrix4._12, RenderStack.Math.Matrix4._13, RenderStack.Math.Matrix4._20, RenderStack.Math.Matrix4._21, RenderStack.Math.Matrix4._22, RenderStack.Math.Matrix4._23, RenderStack.Math.Matrix4._30, RenderStack.Math.Matrix4._31, RenderStack.Math.Matrix4._32, and RenderStack.Math.Matrix4._33.

        {
            int[] colIdx = { 0, 0, 0, 0 };
            int[] rowIdx = { 0, 0, 0, 0 };
            int[] pivotIdx = { -1, -1, -1, -1 };

            // convert the matrix to an array for easy looping
            float[,] inverse = {{mat._00, mat._01, mat._02, mat._03}, 
                                {mat._10, mat._11, mat._12, mat._13}, 
                                {mat._20, mat._21, mat._22, mat._23}, 
                                {mat._30, mat._31, mat._32, mat._33} };
            int icol = 0;
            int irow = 0;
            for (int i = 0; i < 4; i++)
            {
                // Find the largest pivot value
                float maxPivot = 0.0f;
                for (int j = 0; j < 4; j++)
                {
                    if (pivotIdx[j] != 0)
                    {
                        for (int k = 0; k < 4; ++k)
                        {
                            if (pivotIdx[k] == -1)
                            {
                                float absVal = System.Math.Abs(inverse[j, k]);
                                if (absVal > maxPivot)
                                {
                                    maxPivot = absVal;
                                    irow = j;
                                    icol = k;
                                }
                            }
                            else if (pivotIdx[k] > 0)
                            {
                                return mat;
                            }
                        }
                    }
                }

                ++(pivotIdx[icol]);

                // Swap rows over so pivot is on diagonal
                if (irow != icol)
                {
                    for (int k = 0; k < 4; ++k)
                    {
                        float f = inverse[irow, k];
                        inverse[irow, k] = inverse[icol, k];
                        inverse[icol, k] = f;
                    }
                }

                rowIdx[i] = irow;
                colIdx[i] = icol;

                float pivot = inverse[icol, icol];
                // check for singular matrix
                if (pivot == 0.0f)
                {
                    throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
                    //return mat;
                }

                // Scale row so it has a unit diagonal
                float oneOverPivot = 1.0f / pivot;
                inverse[icol, icol] = 1.0f;
                for (int k = 0; k < 4; ++k)
                    inverse[icol, k] *= oneOverPivot;

                // Do elimination of non-diagonal elements
                for (int j = 0; j < 4; ++j)
                {
                    // check this isn't on the diagonal
                    if (icol != j)
                    {
                        float f = inverse[j, icol];
                        inverse[j, icol] = 0.0f;
                        for (int k = 0; k < 4; ++k)
                            inverse[j, k] -= inverse[icol, k] * f;
                    }
                }
            }

            for (int j = 3; j >= 0; --j)
            {
                int ir = rowIdx[j];
                int ic = colIdx[j];
                for (int k = 0; k < 4; ++k)
                {
                    float f = inverse[k, ir];
                    inverse[k, ir] = inverse[k, ic];
                    inverse[k, ic] = f;
                }
            }

            mat._00 = inverse[0, 0]; mat._01 = inverse[0, 1]; mat._02 = inverse[0, 2]; mat._03 = inverse[0, 3];
            mat._10 = inverse[1, 0]; mat._11 = inverse[1, 1]; mat._12 = inverse[1, 2]; mat._13 = inverse[1, 3];
            mat._20 = inverse[2, 0]; mat._21 = inverse[2, 1]; mat._22 = inverse[2, 2]; mat._23 = inverse[2, 3];
            mat._30 = inverse[3, 0]; mat._31 = inverse[3, 1]; mat._32 = inverse[3, 2]; mat._33 = inverse[3, 3];
            return mat;
        }
static Matrix4 RenderStack.Math.Matrix4.Transpose ( Matrix4  mat) [static]
static void RenderStack.Math.Matrix4.Transpose ( Matrix4  mat,
out Matrix4  result 
) [static]

Definition at line 1264 of file Matrix4.cs.

References RenderStack.Math.Matrix4._00, RenderStack.Math.Matrix4._01, RenderStack.Math.Matrix4._02, RenderStack.Math.Matrix4._03, RenderStack.Math.Matrix4._10, RenderStack.Math.Matrix4._11, RenderStack.Math.Matrix4._12, RenderStack.Math.Matrix4._13, RenderStack.Math.Matrix4._20, RenderStack.Math.Matrix4._21, RenderStack.Math.Matrix4._22, RenderStack.Math.Matrix4._23, RenderStack.Math.Matrix4._30, RenderStack.Math.Matrix4._31, RenderStack.Math.Matrix4._32, and RenderStack.Math.Matrix4._33.

        {
            result._00 = mat._00;
            result._10 = mat._01;
            result._20 = mat._02;
            result._30 = mat._03;
            result._01 = mat._10;
            result._11 = mat._11;
            result._21 = mat._12;
            result._31 = mat._13;
            result._02 = mat._20;
            result._12 = mat._21;
            result._22 = mat._22;
            result._32 = mat._23;
            result._03 = mat._30;
            result._13 = mat._31;
            result._23 = mat._32;
            result._33 = mat._33;
        }
bool RenderStack.Math.Matrix4.Equals ( Matrix4  other)

Definition at line 1284 of file Matrix4.cs.

References RenderStack.Math.Matrix4._00, RenderStack.Math.Matrix4._01, RenderStack.Math.Matrix4._02, RenderStack.Math.Matrix4._03, RenderStack.Math.Matrix4._10, RenderStack.Math.Matrix4._11, RenderStack.Math.Matrix4._12, RenderStack.Math.Matrix4._13, RenderStack.Math.Matrix4._20, RenderStack.Math.Matrix4._21, RenderStack.Math.Matrix4._22, RenderStack.Math.Matrix4._23, RenderStack.Math.Matrix4._30, RenderStack.Math.Matrix4._31, RenderStack.Math.Matrix4._32, and RenderStack.Math.Matrix4._33.

        {
            return 
                other._00 == _00 &&
                other._10 == _10 &&
                other._20 == _20 &&
                other._30 == _30 &&
                other._01 == _01 &&
                other._11 == _11 &&
                other._21 == _21 &&
                other._31 == _31 &&
                other._02 == _02 &&
                other._12 == _12 &&
                other._22 == _22 &&
                other._32 == _32 &&
                other._03 == _03 &&
                other._13 == _13 &&
                other._23 == _23 &&
                other._33 == _33;
        }

Member Data Documentation


Property Documentation

float RenderStack.Math.Matrix4.this[int row, int column] [get]

Definition at line 304 of file Matrix4.cs.

Matrix4 RenderStack.Math.Matrix4.Identity [static, get]
float RenderStack.Math.Matrix4.Trace3 [get]

Definition at line 452 of file Matrix4.cs.

float RenderStack.Math.Matrix4.Trace [get]

Definition at line 459 of file Matrix4.cs.


The documentation for this struct was generated from the following file: