OpenTK.Matrix4 Struct Reference

Represents a 4x4 Matrix. More...

List of all members.

Public Member Functions

 Matrix4 (Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3)
 Constructs a new instance.
 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)
 Constructs a new instance.
void Invert ()
 Converts this instance into its inverse.
void Transpose ()
 Converts this instance into its transpose.
override string ToString ()
 Returns a System.String that represents the current Matrix44.
override int GetHashCode ()
 Returns the hashcode for this instance.
override bool Equals (object obj)
 Indicates whether this instance and a specified object are equal.
bool Equals (Matrix4 other)
 Indicates whether the current matrix is equal to another matrix.

Static Public Member Functions

static void CreateFromAxisAngle (Vector3 axis, float angle, out Matrix4 result)
 Build a rotation matrix from the specified axis/angle rotation.
static Matrix4 CreateFromAxisAngle (Vector3 axis, float angle)
 Build a rotation matrix from the specified axis/angle rotation.
static void CreateRotationX (float angle, out Matrix4 result)
 Builds a rotation matrix for a rotation around the x-axis.
static Matrix4 CreateRotationX (float angle)
 Builds a rotation matrix for a rotation around the x-axis.
static void CreateRotationY (float angle, out Matrix4 result)
 Builds a rotation matrix for a rotation around the y-axis.
static Matrix4 CreateRotationY (float angle)
 Builds a rotation matrix for a rotation around the y-axis.
static void CreateRotationZ (float angle, out Matrix4 result)
 Builds a rotation matrix for a rotation around the z-axis.
static Matrix4 CreateRotationZ (float angle)
 Builds a rotation matrix for a rotation around the z-axis.
static void CreateTranslation (float x, float y, float z, out Matrix4 result)
 Creates a translation matrix.
static void CreateTranslation (ref Vector3 vector, out Matrix4 result)
 Creates a translation matrix.
static Matrix4 CreateTranslation (float x, float y, float z)
 Creates a translation matrix.
static Matrix4 CreateTranslation (Vector3 vector)
 Creates a translation matrix.
static void CreateOrthographic (float width, float height, float zNear, float zFar, out Matrix4 result)
 Creates an orthographic projection matrix.
static Matrix4 CreateOrthographic (float width, float height, float zNear, float zFar)
 Creates an orthographic projection matrix.
static void CreateOrthographicOffCenter (float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result)
 Creates an orthographic projection matrix.
static Matrix4 CreateOrthographicOffCenter (float left, float right, float bottom, float top, float zNear, float zFar)
 Creates an orthographic projection matrix.
static void CreatePerspectiveFieldOfView (float fovy, float aspect, float zNear, float zFar, out Matrix4 result)
 Creates a perspective projection matrix.
static Matrix4 CreatePerspectiveFieldOfView (float fovy, float aspect, float zNear, float zFar)
 Creates a perspective projection matrix.
static void CreatePerspectiveOffCenter (float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result)
 Creates an perspective projection matrix.
static Matrix4 CreatePerspectiveOffCenter (float left, float right, float bottom, float top, float zNear, float zFar)
 Creates an perspective projection matrix.
static Matrix4 Translation (Vector3 trans)
 Builds a translation matrix.
static Matrix4 Translation (float x, float y, float z)
 Build a translation matrix with the given translation.
static Matrix4 Scale (float scale)
 Build a scaling matrix.
static Matrix4 Scale (Vector3 scale)
 Build a scaling matrix.
static Matrix4 Scale (float x, float y, float z)
 Build a scaling matrix.
static Matrix4 RotateX (float angle)
 Build a rotation matrix that rotates about the x-axis.
static Matrix4 RotateY (float angle)
 Build a rotation matrix that rotates about the y-axis.
static Matrix4 RotateZ (float angle)
 Build a rotation matrix that rotates about the z-axis.
static Matrix4 Rotate (Vector3 axis, float angle)
 Build a rotation matrix to rotate about the given axis.
static Matrix4 Rotate (Quaternion q)
 Build a rotation matrix from a quaternion.
static Matrix4 LookAt (Vector3 eye, Vector3 target, Vector3 up)
 Build a world space to camera space matrix.
static Matrix4 LookAt (float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ)
 Build a world space to camera space matrix.
static Matrix4 Frustum (float left, float right, float bottom, float top, float near, float far)
 Build a projection matrix.
static Matrix4 Perspective (float fovy, float aspect, float near, float far)
 Build a projection matrix.
static Matrix4 Mult (Matrix4 left, Matrix4 right)
 Multiplies two instances.
static void Mult (ref Matrix4 left, ref Matrix4 right, out Matrix4 result)
 Multiplies two instances.
static Matrix4 Invert (Matrix4 mat)
 Calculate the inverse of the given matrix.
static Matrix4 Transpose (Matrix4 mat)
 Calculate the transpose of the given matrix.
static void Transpose (ref Matrix4 mat, out Matrix4 result)
 Calculate the transpose of the given matrix.
static Matrix4 operator* (Matrix4 left, Matrix4 right)
 Matrix multiplication.
static bool operator== (Matrix4 left, Matrix4 right)
 Compares two instances for equality.
static bool operator!= (Matrix4 left, Matrix4 right)
 Compares two instances for inequality.

Public Attributes

Vector4 Row0
 Top row of the matrix.
Vector4 Row1
 2nd row of the matrix
Vector4 Row2
 3rd row of the matrix
Vector4 Row3
 Bottom row of the matrix.

Static Public Attributes

static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW)
 The identity matrix.

Properties

float Determinant [get]
 The determinant of this matrix.
Vector4 Column0 [get]
 The first column of this matrix.
Vector4 Column1 [get]
 The second column of this matrix.
Vector4 Column2 [get]
 The third column of this matrix.
Vector4 Column3 [get]
 The fourth column of this matrix.
float M11 [get, set]
 Gets or sets the value at row 1, column 1 of this instance.
float M12 [get, set]
 Gets or sets the value at row 1, column 2 of this instance.
float M13 [get, set]
 Gets or sets the value at row 1, column 3 of this instance.
float M14 [get, set]
 Gets or sets the value at row 1, column 4 of this instance.
float M21 [get, set]
 Gets or sets the value at row 2, column 1 of this instance.
float M22 [get, set]
 Gets or sets the value at row 2, column 2 of this instance.
float M23 [get, set]
 Gets or sets the value at row 2, column 3 of this instance.
float M24 [get, set]
 Gets or sets the value at row 2, column 4 of this instance.
float M31 [get, set]
 Gets or sets the value at row 3, column 1 of this instance.
float M32 [get, set]
 Gets or sets the value at row 3, column 2 of this instance.
float M33 [get, set]
 Gets or sets the value at row 3, column 3 of this instance.
float M34 [get, set]
 Gets or sets the value at row 3, column 4 of this instance.
float M41 [get, set]
 Gets or sets the value at row 4, column 1 of this instance.
float M42 [get, set]
 Gets or sets the value at row 4, column 2 of this instance.
float M43 [get, set]
 Gets or sets the value at row 4, column 3 of this instance.
float M44 [get, set]
 Gets or sets the value at row 4, column 4 of this instance.

Detailed Description

Represents a 4x4 Matrix.

Definition at line 35 of file Matrix4.cs.


Constructor & Destructor Documentation

OpenTK.Matrix4.Matrix4 ( Vector4  row0,
Vector4  row1,
Vector4  row2,
Vector4  row3 
)

Constructs a new instance.

Parameters:
row0 Top row of the matrix
row1 Second row of the matrix
row2 Third row of the matrix
row3 Bottom row of the matrix

Definition at line 72 of file Matrix4.cs.

00073         {
00074             Row0 = row0;
00075             Row1 = row1;
00076             Row2 = row2;
00077             Row3 = row3;
00078         }

OpenTK.Matrix4.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 
)

Constructs a new instance.

Parameters:
m00 First item of the first row of the matrix.
m01 Second item of the first row of the matrix.
m02 Third item of the first row of the matrix.
m03 Fourth item of the first row of the matrix.
m10 First item of the second row of the matrix.
m11 Second item of the second row of the matrix.
m12 Third item of the second row of the matrix.
m13 Fourth item of the second row of the matrix.
m20 First item of the third row of the matrix.
m21 Second item of the third row of the matrix.
m22 Third item of the third row of the matrix.
m23 First item of the third row of the matrix.
m30 Fourth item of the fourth row of the matrix.
m31 Second item of the fourth row of the matrix.
m32 Third item of the fourth row of the matrix.
m33 Fourth item of the fourth row of the matrix.

Definition at line 99 of file Matrix4.cs.

00104         {
00105             Row0 = new Vector4(m00, m01, m02, m03);
00106             Row1 = new Vector4(m10, m11, m12, m13);
00107             Row2 = new Vector4(m20, m21, m22, m23);
00108             Row3 = new Vector4(m30, m31, m32, m33);
00109         }


Member Function Documentation

static Matrix4 OpenTK.Matrix4.CreateFromAxisAngle ( Vector3  axis,
float  angle 
) [static]

Build a rotation matrix from the specified axis/angle rotation.

Parameters:
axis The axis to rotate about.
angle Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).
Returns:
A matrix instance.

Definition at line 306 of file Matrix4.cs.

00307         {
00308             Matrix4 result;
00309             CreateFromAxisAngle(axis, angle, out result);
00310             return result;
00311         }

static void OpenTK.Matrix4.CreateFromAxisAngle ( Vector3  axis,
float  angle,
out Matrix4  result 
) [static]

Build a rotation matrix from the specified axis/angle rotation.

Parameters:
axis The axis to rotate about.
angle Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).
result A matrix instance.

Definition at line 286 of file Matrix4.cs.

00287         {
00288             float cos = (float)System.Math.Cos(-angle);
00289             float sin = (float)System.Math.Sin(-angle);
00290             float t = 1.0f - cos;
00291 
00292             axis.Normalize();
00293 
00294             result = new Matrix4(t * axis.X * axis.X + cos, t * axis.X * axis.Y - sin * axis.Z, t * axis.X * axis.Z + sin * axis.Y, 0.0f,
00295                                  t * axis.X * axis.Y + sin * axis.Z, t * axis.Y * axis.Y + cos, t * axis.Y * axis.Z - sin * axis.X, 0.0f,
00296                                  t * axis.X * axis.Z - sin * axis.Y, t * axis.Y * axis.Z + sin * axis.X, t * axis.Z * axis.Z + cos, 0.0f,
00297                                  0, 0, 0, 1);
00298         }

static Matrix4 OpenTK.Matrix4.CreateOrthographic ( float  width,
float  height,
float  zNear,
float  zFar 
) [static]

Creates an orthographic projection matrix.

Parameters:
width The width of the projection volume.
height The height of the projection volume.
zNear The near edge of the projection volume.
zFar The far edge of the projection volume.

<rereturns>The resulting Matrix4 instance.</rereturns>

Definition at line 480 of file Matrix4.cs.

00481         {
00482             Matrix4 result;
00483             CreateOrthographicOffCenter(-width / 2, width / 2, -height / 2, height / 2, zNear, zFar, out result);
00484             return result;
00485         }

static void OpenTK.Matrix4.CreateOrthographic ( float  width,
float  height,
float  zNear,
float  zFar,
out Matrix4  result 
) [static]

Creates an orthographic projection matrix.

Parameters:
width The width of the projection volume.
height The height of the projection volume.
zNear The near edge of the projection volume.
zFar The far edge of the projection volume.
result The resulting Matrix4 instance.

Definition at line 467 of file Matrix4.cs.

00468         {
00469             CreateOrthographicOffCenter(-width / 2, width / 2, -height / 2, height / 2, zNear, zFar, out result);
00470         }

static Matrix4 OpenTK.Matrix4.CreateOrthographicOffCenter ( float  left,
float  right,
float  bottom,
float  top,
float  zNear,
float  zFar 
) [static]

Creates an orthographic projection matrix.

Parameters:
left The left edge of the projection volume.
right The right edge of the projection volume.
bottom The bottom edge of the projection volume.
top The top edge of the projection volume.
zNear The near edge of the projection volume.
zFar The far edge of the projection volume.
Returns:
The resulting Matrix4 instance.

Definition at line 529 of file Matrix4.cs.

00530         {
00531             Matrix4 result;
00532             CreateOrthographicOffCenter(left, right, bottom, top, zNear, zFar, out result);
00533             return result;
00534         }

static void OpenTK.Matrix4.CreateOrthographicOffCenter ( float  left,
float  right,
float  bottom,
float  top,
float  zNear,
float  zFar,
out Matrix4  result 
) [static]

Creates an orthographic projection matrix.

Parameters:
left The left edge of the projection volume.
right The right edge of the projection volume.
bottom The bottom edge of the projection volume.
top The top edge of the projection volume.
zNear The near edge of the projection volume.
zFar The far edge of the projection volume.
result The resulting Matrix4 instance.

Definition at line 501 of file Matrix4.cs.

00502         {
00503             result = new Matrix4();
00504 
00505             float invRL = 1 / (right - left);
00506             float invTB = 1 / (top - bottom);
00507             float invFN = 1 / (zFar - zNear);
00508 
00509             result.M11 = 2 * invRL;
00510             result.M22 = 2 * invTB;
00511             result.M33 = -2 * invFN;
00512 
00513             result.M41 = -(right + left) * invRL;
00514             result.M42 = -(top + bottom) * invTB;
00515             result.M43 = -(zFar + zNear) * invFN;
00516             result.M44 = 1;
00517         }

static Matrix4 OpenTK.Matrix4.CreatePerspectiveFieldOfView ( float  fovy,
float  aspect,
float  zNear,
float  zFar 
) [static]

Creates a perspective projection matrix.

Parameters:
fovy Angle of the field of view in the y direction (in radians)
aspect Aspect ratio of the view (width / height)
zNear Distance to the near clip plane
zFar Distance to the far clip plane
Returns:
A projection matrix that transforms camera space to raster space
Exceptions:
System.ArgumentOutOfRangeException Thrown under the following conditions:

  • fovy is zero, less than zero or larger than Math.PI
  • aspect is negative or zero
  • zNear is negative or zero
  • zFar is negative or zero
  • zNear is larger than zFar

Definition at line 597 of file Matrix4.cs.

00598         {
00599             Matrix4 result;
00600             CreatePerspectiveFieldOfView(fovy, aspect, zNear, zFar, out result);
00601             return result;
00602         }

static void OpenTK.Matrix4.CreatePerspectiveFieldOfView ( float  fovy,
float  aspect,
float  zNear,
float  zFar,
out Matrix4  result 
) [static]

Creates a perspective projection matrix.

Parameters:
fovy Angle of the field of view in the y direction (in radians)
aspect Aspect ratio of the view (width / height)
zNear Distance to the near clip plane
zFar Distance to the far clip plane
result A projection matrix that transforms camera space to raster space
Exceptions:
System.ArgumentOutOfRangeException Thrown under the following conditions:

  • fovy is zero, less than zero or larger than Math.PI
  • aspect is negative or zero
  • zNear is negative or zero
  • zFar is negative or zero
  • zNear is larger than zFar

Definition at line 558 of file Matrix4.cs.

00559         {
00560             if (fovy <= 0 || fovy > Math.PI)
00561                 throw new ArgumentOutOfRangeException("fovy");
00562             if (aspect <= 0)
00563                 throw new ArgumentOutOfRangeException("aspect");
00564             if (zNear <= 0)
00565                 throw new ArgumentOutOfRangeException("zNear");
00566             if (zFar <= 0)
00567                 throw new ArgumentOutOfRangeException("zFar");
00568             if (zNear >= zFar)
00569                 throw new ArgumentOutOfRangeException("zNear");
00570             
00571             float yMax = zNear * (float)System.Math.Tan(0.5f * fovy);
00572             float yMin = -yMax;
00573             float xMin = yMin * aspect;
00574             float xMax = yMax * aspect;
00575 
00576             CreatePerspectiveOffCenter(xMin, xMax, yMin, yMax, zNear, zFar, out result);
00577         }

static Matrix4 OpenTK.Matrix4.CreatePerspectiveOffCenter ( float  left,
float  right,
float  bottom,
float  top,
float  zNear,
float  zFar 
) [static]

Creates an perspective projection matrix.

Parameters:
left Left edge of the view frustum
right Right edge of the view frustum
bottom Bottom edge of the view frustum
top Top edge of the view frustum
zNear Distance to the near clip plane
zFar Distance to the far clip plane
Returns:
A projection matrix that transforms camera space to raster space
Exceptions:
System.ArgumentOutOfRangeException Thrown under the following conditions:

  • zNear is negative or zero
  • zFar is negative or zero
  • zNear is larger than zFar

Definition at line 666 of file Matrix4.cs.

00667         {
00668             Matrix4 result;
00669             CreatePerspectiveOffCenter(left, right, bottom, top, zNear, zFar, out result);
00670             return result;
00671         }

static void OpenTK.Matrix4.CreatePerspectiveOffCenter ( float  left,
float  right,
float  bottom,
float  top,
float  zNear,
float  zFar,
out Matrix4  result 
) [static]

Creates an perspective projection matrix.

Parameters:
left Left edge of the view frustum
right Right edge of the view frustum
bottom Bottom edge of the view frustum
top Top edge of the view frustum
zNear Distance to the near clip plane
zFar Distance to the far clip plane
result A projection matrix that transforms camera space to raster space
Exceptions:
System.ArgumentOutOfRangeException Thrown under the following conditions:

  • zNear is negative or zero
  • zFar is negative or zero
  • zNear is larger than zFar

Definition at line 626 of file Matrix4.cs.

00627         {
00628             if (zNear <= 0)
00629                 throw new ArgumentOutOfRangeException("zNear");
00630             if (zFar <= 0)
00631                 throw new ArgumentOutOfRangeException("zFar");
00632             if (zNear >= zFar)
00633                 throw new ArgumentOutOfRangeException("zNear");
00634             
00635             float x = (2.0f * zNear) / (right - left);
00636             float y = (2.0f * zNear) / (top - bottom);
00637             float a = (right + left) / (right - left);
00638             float b = (top + bottom) / (top - bottom);
00639             float c = -(zFar + zNear) / (zFar - zNear);
00640             float d = -(2.0f * zFar * zNear) / (zFar - zNear);
00641             
00642             result = new Matrix4(x, 0, 0,  0,
00643                                  0, y, 0,  0,
00644                                  a, b, c, -1,
00645                                  0, 0, d,  0);
00646         }

static Matrix4 OpenTK.Matrix4.CreateRotationX ( float  angle  )  [static]

Builds a rotation matrix for a rotation around the x-axis.

Parameters:
angle The counter-clockwise angle in radians.
Returns:
The resulting Matrix4 instance.

Definition at line 338 of file Matrix4.cs.

00339         {
00340             Matrix4 result;
00341             CreateRotationX(angle, out result);
00342             return result;
00343         }

static void OpenTK.Matrix4.CreateRotationX ( float  angle,
out Matrix4  result 
) [static]

Builds a rotation matrix for a rotation around the x-axis.

Parameters:
angle The counter-clockwise angle in radians.
result The resulting Matrix4 instance.

Definition at line 322 of file Matrix4.cs.

00323         {
00324             float cos = (float)System.Math.Cos(angle);
00325             float sin = (float)System.Math.Sin(angle);
00326 
00327             result.Row0 = Vector4.UnitX;
00328             result.Row1 = new Vector4(0.0f, cos, sin, 0.0f);
00329             result.Row2 = new Vector4(0.0f, -sin, cos, 0.0f);
00330             result.Row3 = Vector4.UnitW;
00331         }

static Matrix4 OpenTK.Matrix4.CreateRotationY ( float  angle  )  [static]

Builds a rotation matrix for a rotation around the y-axis.

Parameters:
angle The counter-clockwise angle in radians.
Returns:
The resulting Matrix4 instance.

Definition at line 366 of file Matrix4.cs.

00367         {
00368             Matrix4 result;
00369             CreateRotationY(angle, out result);
00370             return result;
00371         }

static void OpenTK.Matrix4.CreateRotationY ( float  angle,
out Matrix4  result 
) [static]

Builds a rotation matrix for a rotation around the y-axis.

Parameters:
angle The counter-clockwise angle in radians.
result The resulting Matrix4 instance.

Definition at line 350 of file Matrix4.cs.

00351         {
00352             float cos = (float)System.Math.Cos(angle);
00353             float sin = (float)System.Math.Sin(angle);
00354 
00355             result.Row0 = new Vector4(cos, 0.0f, -sin, 0.0f);
00356             result.Row1 = Vector4.UnitY;
00357             result.Row2 = new Vector4(sin, 0.0f, cos, 0.0f);
00358             result.Row3 = Vector4.UnitW;
00359         }

static Matrix4 OpenTK.Matrix4.CreateRotationZ ( float  angle  )  [static]

Builds a rotation matrix for a rotation around the z-axis.

Parameters:
angle The counter-clockwise angle in radians.
Returns:
The resulting Matrix4 instance.

Definition at line 394 of file Matrix4.cs.

00395         {
00396             Matrix4 result;
00397             CreateRotationZ(angle, out result);
00398             return result;
00399         }

static void OpenTK.Matrix4.CreateRotationZ ( float  angle,
out Matrix4  result 
) [static]

Builds a rotation matrix for a rotation around the z-axis.

Parameters:
angle The counter-clockwise angle in radians.
result The resulting Matrix4 instance.

Definition at line 378 of file Matrix4.cs.

00379         {
00380             float cos = (float)System.Math.Cos(angle);
00381             float sin = (float)System.Math.Sin(angle);
00382 
00383             result.Row0 = new Vector4(cos, sin, 0.0f, 0.0f);
00384             result.Row1 = new Vector4(-sin, cos, 0.0f, 0.0f);
00385             result.Row2 = Vector4.UnitZ;
00386             result.Row3 = Vector4.UnitW;
00387         }

static Matrix4 OpenTK.Matrix4.CreateTranslation ( Vector3  vector  )  [static]

Creates a translation matrix.

Parameters:
vector The translation vector.
Returns:
The resulting Matrix4 instance.

Definition at line 448 of file Matrix4.cs.

00449         {
00450             Matrix4 result;
00451             CreateTranslation(vector.X, vector.Y, vector.Z, out result);
00452             return result;
00453         }

static Matrix4 OpenTK.Matrix4.CreateTranslation ( float  x,
float  y,
float  z 
) [static]

Creates a translation matrix.

Parameters:
x X translation.
y Y translation.
z Z translation.
Returns:
The resulting Matrix4 instance.

Definition at line 436 of file Matrix4.cs.

00437         {
00438             Matrix4 result;
00439             CreateTranslation(x, y, z, out result);
00440             return result;
00441         }

static void OpenTK.Matrix4.CreateTranslation ( ref Vector3  vector,
out Matrix4  result 
) [static]

Creates a translation matrix.

Parameters:
vector The translation vector.
result The resulting Matrix4 instance.

Definition at line 423 of file Matrix4.cs.

00424         {
00425             result = Identity;
00426             result.Row3 = new Vector4(vector.X, vector.Y, vector.Z, 1);
00427         }

static void OpenTK.Matrix4.CreateTranslation ( float  x,
float  y,
float  z,
out Matrix4  result 
) [static]

Creates a translation matrix.

Parameters:
x X translation.
y Y translation.
z Z translation.
result The resulting Matrix4 instance.

Definition at line 412 of file Matrix4.cs.

00413         {
00414             result = Identity;
00415             result.Row3 = new Vector4(x, y, z, 1);
00416         }

bool OpenTK.Matrix4.Equals ( Matrix4  other  ) 

Indicates whether the current matrix is equal to another matrix.

Parameters:
other An matrix to compare with this matrix.
Returns:
true if the current matrix is equal to the matrix parameter; otherwise, false.

Definition at line 1212 of file Matrix4.cs.

01213         {
01214             return
01215                 Row0 == other.Row0 &&
01216                 Row1 == other.Row1 &&
01217                 Row2 == other.Row2 &&
01218                 Row3 == other.Row3;
01219         }

override bool OpenTK.Matrix4.Equals ( object  obj  ) 

Indicates whether this instance and a specified object are equal.

Parameters:
obj The object to compare tresult.
Returns:
True if the instances are equal; false otherwise.

Definition at line 1193 of file Matrix4.cs.

01194         {
01195             if (!(obj is Matrix4))
01196                 return false;
01197 
01198             return this.Equals((Matrix4)obj);
01199         }

static Matrix4 OpenTK.Matrix4.Frustum ( float  left,
float  right,
float  bottom,
float  top,
float  near,
float  far 
) [static]

Build a projection matrix.

Parameters:
left Left edge of the view frustum
right Right edge of the view frustum
bottom Bottom edge of the view frustum
top Top edge of the view frustum
near Distance to the near clip plane
far Distance to the far clip plane
Returns:
A projection matrix that transforms camera space to raster space

Definition at line 901 of file Matrix4.cs.

00902         {
00903             float invRL = 1.0f / (right - left);
00904             float invTB = 1.0f / (top - bottom);
00905             float invFN = 1.0f / (far - near);
00906             return new Matrix4(new Vector4(2.0f * near * invRL, 0.0f, 0.0f, 0.0f),
00907                                new Vector4(0.0f, 2.0f * near * invTB, 0.0f, 0.0f),
00908                                new Vector4((right + left) * invRL, (top + bottom) * invTB, -(far + near) * invFN, -1.0f),
00909                                new Vector4(0.0f, 0.0f, -2.0f * far * near * invFN, 0.0f));
00910         }

override int OpenTK.Matrix4.GetHashCode (  ) 

Returns the hashcode for this instance.

Returns:
A System.Int32 containing the unique hashcode for this instance.

Definition at line 1179 of file Matrix4.cs.

01180         {
01181             return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode();
01182         }

static Matrix4 OpenTK.Matrix4.Invert ( Matrix4  mat  )  [static]

Calculate the inverse of the given matrix.

Parameters:
mat The matrix to invert
Returns:
The inverse of the given matrix if it has one, or the input if it is singular
Exceptions:
InvalidOperationException Thrown if the Matrix4 is singular.

Definition at line 985 of file Matrix4.cs.

00986         {
00987             int[] colIdx = { 0, 0, 0, 0 };
00988             int[] rowIdx = { 0, 0, 0, 0 };
00989             int[] pivotIdx = { -1, -1, -1, -1 };
00990 
00991             // convert the matrix to an array for easy looping
00992             float[,] inverse = {{mat.Row0.X, mat.Row0.Y, mat.Row0.Z, mat.Row0.W}, 
00993                                 {mat.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W}, 
00994                                 {mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.W}, 
00995                                 {mat.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W} };
00996             int icol = 0;
00997             int irow = 0;
00998             for (int i = 0; i < 4; i++)
00999             {
01000                 // Find the largest pivot value
01001                 float maxPivot = 0.0f;
01002                 for (int j = 0; j < 4; j++)
01003                 {
01004                     if (pivotIdx[j] != 0)
01005                     {
01006                         for (int k = 0; k < 4; ++k)
01007                         {
01008                             if (pivotIdx[k] == -1)
01009                             {
01010                                 float absVal = System.Math.Abs(inverse[j, k]);
01011                                 if (absVal > maxPivot)
01012                                 {
01013                                     maxPivot = absVal;
01014                                     irow = j;
01015                                     icol = k;
01016                                 }
01017                             }
01018                             else if (pivotIdx[k] > 0)
01019                             {
01020                                 return mat;
01021                             }
01022                         }
01023                     }
01024                 }
01025 
01026                 ++(pivotIdx[icol]);
01027 
01028                 // Swap rows over so pivot is on diagonal
01029                 if (irow != icol)
01030                 {
01031                     for (int k = 0; k < 4; ++k)
01032                     {
01033                         float f = inverse[irow, k];
01034                         inverse[irow, k] = inverse[icol, k];
01035                         inverse[icol, k] = f;
01036                     }
01037                 }
01038 
01039                 rowIdx[i] = irow;
01040                 colIdx[i] = icol;
01041 
01042                 float pivot = inverse[icol, icol];
01043                 // check for singular matrix
01044                 if (pivot == 0.0f)
01045                 {
01046                     throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
01047                     //return mat;
01048                 }
01049 
01050                 // Scale row so it has a unit diagonal
01051                 float oneOverPivot = 1.0f / pivot;
01052                 inverse[icol, icol] = 1.0f;
01053                 for (int k = 0; k < 4; ++k)
01054                     inverse[icol, k] *= oneOverPivot;
01055 
01056                 // Do elimination of non-diagonal elements
01057                 for (int j = 0; j < 4; ++j)
01058                 {
01059                     // check this isn't on the diagonal
01060                     if (icol != j)
01061                     {
01062                         float f = inverse[j, icol];
01063                         inverse[j, icol] = 0.0f;
01064                         for (int k = 0; k < 4; ++k)
01065                             inverse[j, k] -= inverse[icol, k] * f;
01066                     }
01067                 }
01068             }
01069 
01070             for (int j = 3; j >= 0; --j)
01071             {
01072                 int ir = rowIdx[j];
01073                 int ic = colIdx[j];
01074                 for (int k = 0; k < 4; ++k)
01075                 {
01076                     float f = inverse[k, ir];
01077                     inverse[k, ir] = inverse[k, ic];
01078                     inverse[k, ic] = f;
01079                 }
01080             }
01081 
01082             mat.Row0 = new Vector4(inverse[0, 0], inverse[0, 1], inverse[0, 2], inverse[0, 3]);
01083             mat.Row1 = new Vector4(inverse[1, 0], inverse[1, 1], inverse[1, 2], inverse[1, 3]);
01084             mat.Row2 = new Vector4(inverse[2, 0], inverse[2, 1], inverse[2, 2], inverse[2, 3]);
01085             mat.Row3 = new Vector4(inverse[3, 0], inverse[3, 1], inverse[3, 2], inverse[3, 3]);
01086             return mat;
01087         }

void OpenTK.Matrix4.Invert (  ) 

Converts this instance into its inverse.

Definition at line 255 of file Matrix4.cs.

00256         {
00257             this = Matrix4.Invert(this);
00258         }

static Matrix4 OpenTK.Matrix4.LookAt ( float  eyeX,
float  eyeY,
float  eyeZ,
float  targetX,
float  targetY,
float  targetZ,
float  upX,
float  upY,
float  upZ 
) [static]

Build a world space to camera space matrix.

Parameters:
eyeX Eye (camera) position in world space
eyeY Eye (camera) position in world space
eyeZ Eye (camera) position in world space
targetX Target position in world space
targetY Target position in world space
targetZ Target position in world space
upX Up vector in world space (should not be parallel to the camera direction, that is target - eye)
upY Up vector in world space (should not be parallel to the camera direction, that is target - eye)
upZ Up vector in world space (should not be parallel to the camera direction, that is target - eye)
Returns:
A Matrix4 that transforms world space to camera space

Definition at line 885 of file Matrix4.cs.

00886         {
00887             return LookAt(new Vector3(eyeX, eyeY, eyeZ), new Vector3(targetX, targetY, targetZ), new Vector3(upX, upY, upZ));
00888         }

static Matrix4 OpenTK.Matrix4.LookAt ( Vector3  eye,
Vector3  target,
Vector3  up 
) [static]

Build a world space to camera space matrix.

Parameters:
eye Eye (camera) position in world space
target Target position in world space
up Up vector in world space (should not be parallel to the camera direction, that is target - eye)
Returns:
A Matrix4 that transforms world space to camera space

Definition at line 856 of file Matrix4.cs.

00857         {
00858             Vector3 z = Vector3.Normalize(eye - target);
00859             Vector3 x = Vector3.Normalize(Vector3.Cross(up, z));
00860             Vector3 y = Vector3.Normalize(Vector3.Cross(z, x));
00861 
00862             Matrix4 rot = new Matrix4(new Vector4(x.X, y.X, z.X, 0.0f),
00863                                         new Vector4(x.Y, y.Y, z.Y, 0.0f),
00864                                         new Vector4(x.Z, y.Z, z.Z, 0.0f),
00865                                         Vector4.UnitW);
00866 
00867             Matrix4 trans = Matrix4.CreateTranslation(-eye);
00868 
00869             return trans * rot;
00870         }

static void OpenTK.Matrix4.Mult ( ref Matrix4  left,
ref Matrix4  right,
out Matrix4  result 
) [static]

Multiplies two instances.

Parameters:
left The left operand of the multiplication.
right The right operand of the multiplication.
result A new instance that is the result of the multiplication

Definition at line 954 of file Matrix4.cs.

00955         {
00956             result = new Matrix4(
00957                 left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41,
00958                 left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32 + left.M14 * right.M42,
00959                 left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33 + left.M14 * right.M43,
00960                 left.M11 * right.M14 + left.M12 * right.M24 + left.M13 * right.M34 + left.M14 * right.M44,
00961                 left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31 + left.M24 * right.M41,
00962                 left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32 + left.M24 * right.M42,
00963                 left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33 + left.M24 * right.M43,
00964                 left.M21 * right.M14 + left.M22 * right.M24 + left.M23 * right.M34 + left.M24 * right.M44,
00965                 left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31 + left.M34 * right.M41,
00966                 left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32 + left.M34 * right.M42,
00967                 left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 + left.M34 * right.M43,
00968                 left.M31 * right.M14 + left.M32 * right.M24 + left.M33 * right.M34 + left.M34 * right.M44,
00969                 left.M41 * right.M11 + left.M42 * right.M21 + left.M43 * right.M31 + left.M44 * right.M41,
00970                 left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42,
00971                 left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43,
00972                 left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44);
00973         }

static Matrix4 OpenTK.Matrix4.Mult ( Matrix4  left,
Matrix4  right 
) [static]

Multiplies two instances.

Parameters:
left The left operand of the multiplication.
right The right operand of the multiplication.
Returns:
A new instance that is the result of the multiplication

Definition at line 941 of file Matrix4.cs.

00942         {
00943             Matrix4 result;
00944             Mult(ref left, ref right, out result);
00945             return result;
00946         }

static bool OpenTK.Matrix4.operator!= ( Matrix4  left,
Matrix4  right 
) [static]

Compares two instances for inequality.

Parameters:
left The first instance.
right The second instance.
Returns:
True, if left does not equal right; false otherwise.

Definition at line 1151 of file Matrix4.cs.

01152         {
01153             return !left.Equals(right);
01154         }

static Matrix4 OpenTK.Matrix4.operator* ( Matrix4  left,
Matrix4  right 
) [static]

Matrix multiplication.

Parameters:
left left-hand operand
right right-hand operand
Returns:
A new Matrix44 which holds the result of the multiplication

Definition at line 1129 of file Matrix4.cs.

01130         {
01131             return Matrix4.Mult(left, right);
01132         }

static bool OpenTK.Matrix4.operator== ( Matrix4  left,
Matrix4  right 
) [static]

Compares two instances for equality.

Parameters:
left The first instance.
right The second instance.
Returns:
True, if left equals right; false otherwise.

Definition at line 1140 of file Matrix4.cs.

01141         {
01142             return left.Equals(right);
01143         }

static Matrix4 OpenTK.Matrix4.Perspective ( float  fovy,
float  aspect,
float  near,
float  far 
) [static]

Build a projection matrix.

Parameters:
fovy Angle of the field of view in the y direction (in radians)
aspect Aspect ratio of the view (width / height)
near Distance to the near clip plane
far Distance to the far clip plane
Returns:
A projection matrix that transforms camera space to raster space

Definition at line 921 of file Matrix4.cs.

00922         {
00923             float yMax = near * (float)System.Math.Tan(0.5f * fovy);
00924             float yMin = -yMax;
00925             float xMin = yMin * aspect;
00926             float xMax = yMax * aspect;
00927 
00928             return Frustum(xMin, xMax, yMin, yMax, near, far);
00929         }

static Matrix4 OpenTK.Matrix4.Rotate ( Quaternion  q  )  [static]

Build a rotation matrix from a quaternion.

Parameters:
q the quaternion
Returns:
A rotation matrix

Definition at line 837 of file Matrix4.cs.

00838         {
00839             Vector3 axis;
00840             float angle;
00841             q.ToAxisAngle(out axis, out angle);
00842             return CreateFromAxisAngle(axis, angle);
00843         }

static Matrix4 OpenTK.Matrix4.Rotate ( Vector3  axis,
float  angle 
) [static]

Build a rotation matrix to rotate about the given axis.

Parameters:
axis the axis to rotate about
angle angle in radians to rotate counter-clockwise (looking in the direction of the given axis)
Returns:
A rotation matrix

Definition at line 816 of file Matrix4.cs.

00817         {
00818             float cos = (float)System.Math.Cos(-angle);
00819             float sin = (float)System.Math.Sin(-angle);
00820             float t = 1.0f - cos;
00821 
00822             axis.Normalize();
00823 
00824             Matrix4 result;
00825             result.Row0 = new Vector4(t * axis.X * axis.X + cos, t * axis.X * axis.Y - sin * axis.Z, t * axis.X * axis.Z + sin * axis.Y, 0.0f);
00826             result.Row1 = new Vector4(t * axis.X * axis.Y + sin * axis.Z, t * axis.Y * axis.Y + cos, t * axis.Y * axis.Z - sin * axis.X, 0.0f);
00827             result.Row2 = new Vector4(t * axis.X * axis.Z - sin * axis.Y, t * axis.Y * axis.Z + sin * axis.X, t * axis.Z * axis.Z + cos, 0.0f);
00828             result.Row3 = Vector4.UnitW;
00829             return result;
00830         }

static Matrix4 OpenTK.Matrix4.RotateX ( float  angle  )  [static]

Build a rotation matrix that rotates about the x-axis.

Parameters:
angle angle in radians to rotate counter-clockwise around the x-axis
Returns:
A rotation matrix

Definition at line 758 of file Matrix4.cs.

00759         {
00760             float cos = (float)System.Math.Cos(angle);
00761             float sin = (float)System.Math.Sin(angle);
00762 
00763             Matrix4 result;
00764             result.Row0 = Vector4.UnitX;
00765             result.Row1 = new Vector4(0.0f, cos, sin, 0.0f);
00766             result.Row2 = new Vector4(0.0f, -sin, cos, 0.0f);
00767             result.Row3 = Vector4.UnitW;
00768             return result;
00769         }

static Matrix4 OpenTK.Matrix4.RotateY ( float  angle  )  [static]

Build a rotation matrix that rotates about the y-axis.

Parameters:
angle angle in radians to rotate counter-clockwise around the y-axis
Returns:
A rotation matrix

Definition at line 777 of file Matrix4.cs.

00778         {
00779             float cos = (float)System.Math.Cos(angle);
00780             float sin = (float)System.Math.Sin(angle);
00781 
00782             Matrix4 result;
00783             result.Row0 = new Vector4(cos, 0.0f, -sin, 0.0f);
00784             result.Row1 = Vector4.UnitY;
00785             result.Row2 = new Vector4(sin, 0.0f, cos, 0.0f);
00786             result.Row3 = Vector4.UnitW;
00787             return result;
00788         }

static Matrix4 OpenTK.Matrix4.RotateZ ( float  angle  )  [static]

Build a rotation matrix that rotates about the z-axis.

Parameters:
angle angle in radians to rotate counter-clockwise around the z-axis
Returns:
A rotation matrix

Definition at line 796 of file Matrix4.cs.

00797         {
00798             float cos = (float)System.Math.Cos(angle);
00799             float sin = (float)System.Math.Sin(angle);
00800 
00801             Matrix4 result;
00802             result.Row0 = new Vector4(cos, sin, 0.0f, 0.0f);
00803             result.Row1 = new Vector4(-sin, cos, 0.0f, 0.0f);
00804             result.Row2 = Vector4.UnitZ;
00805             result.Row3 = Vector4.UnitW;
00806             return result;
00807         }

static Matrix4 OpenTK.Matrix4.Scale ( float  x,
float  y,
float  z 
) [static]

Build a scaling matrix.

Parameters:
x Scale factor for x-axis
y Scale factor for y-axis
z Scale factor for z-axis
Returns:
A scaling matrix

Definition at line 738 of file Matrix4.cs.

00739         {
00740             Matrix4 result;
00741             result.Row0 = Vector4.UnitX * x;
00742             result.Row1 = Vector4.UnitY * y;
00743             result.Row2 = Vector4.UnitZ * z;
00744             result.Row3 = Vector4.UnitW;
00745             return result;
00746         }

static Matrix4 OpenTK.Matrix4.Scale ( Vector3  scale  )  [static]

Build a scaling matrix.

Parameters:
scale Scale factors for x,y and z axes
Returns:
A scaling matrix

Definition at line 726 of file Matrix4.cs.

00727         {
00728             return Scale(scale.X, scale.Y, scale.Z);
00729         }

static Matrix4 OpenTK.Matrix4.Scale ( float  scale  )  [static]

Build a scaling matrix.

Parameters:
scale Single scale factor for x,y and z axes
Returns:
A scaling matrix

Definition at line 716 of file Matrix4.cs.

00717         {
00718             return Scale(scale, scale, scale);
00719         }

override string OpenTK.Matrix4.ToString (  ) 

Returns a System.String that represents the current Matrix44.

Returns:

Definition at line 1166 of file Matrix4.cs.

01167         {
01168             return String.Format("{0}\n{1}\n{2}\n{3}", Row0, Row1, Row2, Row3);
01169         }

static Matrix4 OpenTK.Matrix4.Translation ( float  x,
float  y,
float  z 
) [static]

Build a translation matrix with the given translation.

Parameters:
x X translation
y Y translation
z Z translation
Returns:
A Translation matrix

Definition at line 698 of file Matrix4.cs.

00699         {
00700             Matrix4 result = Identity;
00701             result.Row3 = new Vector4(x, y, z, 1.0f);
00702             return result;
00703         }

static Matrix4 OpenTK.Matrix4.Translation ( Vector3  trans  )  [static]

Builds a translation matrix.

Parameters:
trans The translation vector.
Returns:
A new Matrix4 instance.

Definition at line 685 of file Matrix4.cs.

00686         {
00687             return Translation(trans.X, trans.Y, trans.Z);
00688         }

static void OpenTK.Matrix4.Transpose ( ref Matrix4  mat,
out Matrix4  result 
) [static]

Calculate the transpose of the given matrix.

Parameters:
mat The matrix to transpose
result The result of the calculation

Definition at line 1109 of file Matrix4.cs.

01110         {
01111             result.Row0 = mat.Column0;
01112             result.Row1 = mat.Column1;
01113             result.Row2 = mat.Column2;
01114             result.Row3 = mat.Column3;
01115         }

static Matrix4 OpenTK.Matrix4.Transpose ( Matrix4  mat  )  [static]

Calculate the transpose of the given matrix.

Parameters:
mat The matrix to transpose
Returns:
The transpose of the given matrix

Definition at line 1098 of file Matrix4.cs.

01099         {
01100             return new Matrix4(mat.Column0, mat.Column1, mat.Column2, mat.Column3);
01101         }

void OpenTK.Matrix4.Transpose (  ) 

Converts this instance into its transpose.

Definition at line 267 of file Matrix4.cs.

00268         {
00269             this = Matrix4.Transpose(this);
00270         }


Member Data Documentation

The identity matrix.

Definition at line 59 of file Matrix4.cs.

Top row of the matrix.

Definition at line 42 of file Matrix4.cs.

2nd row of the matrix

Definition at line 46 of file Matrix4.cs.

3rd row of the matrix

Definition at line 50 of file Matrix4.cs.

Bottom row of the matrix.

Definition at line 54 of file Matrix4.cs.


Property Documentation

Vector4 OpenTK.Matrix4.Column0 [get]

The first column of this matrix.

Definition at line 138 of file Matrix4.cs.

Vector4 OpenTK.Matrix4.Column1 [get]

The second column of this matrix.

Definition at line 146 of file Matrix4.cs.

Vector4 OpenTK.Matrix4.Column2 [get]

The third column of this matrix.

Definition at line 154 of file Matrix4.cs.

Vector4 OpenTK.Matrix4.Column3 [get]

The fourth column of this matrix.

Definition at line 162 of file Matrix4.cs.

float OpenTK.Matrix4.Determinant [get]

The determinant of this matrix.

Definition at line 121 of file Matrix4.cs.

float OpenTK.Matrix4.M11 [get, set]

Gets or sets the value at row 1, column 1 of this instance.

Definition at line 169 of file Matrix4.cs.

float OpenTK.Matrix4.M12 [get, set]

Gets or sets the value at row 1, column 2 of this instance.

Definition at line 174 of file Matrix4.cs.

float OpenTK.Matrix4.M13 [get, set]

Gets or sets the value at row 1, column 3 of this instance.

Definition at line 179 of file Matrix4.cs.

float OpenTK.Matrix4.M14 [get, set]

Gets or sets the value at row 1, column 4 of this instance.

Definition at line 184 of file Matrix4.cs.

float OpenTK.Matrix4.M21 [get, set]

Gets or sets the value at row 2, column 1 of this instance.

Definition at line 189 of file Matrix4.cs.

float OpenTK.Matrix4.M22 [get, set]

Gets or sets the value at row 2, column 2 of this instance.

Definition at line 194 of file Matrix4.cs.

float OpenTK.Matrix4.M23 [get, set]

Gets or sets the value at row 2, column 3 of this instance.

Definition at line 199 of file Matrix4.cs.

float OpenTK.Matrix4.M24 [get, set]

Gets or sets the value at row 2, column 4 of this instance.

Definition at line 204 of file Matrix4.cs.

float OpenTK.Matrix4.M31 [get, set]

Gets or sets the value at row 3, column 1 of this instance.

Definition at line 209 of file Matrix4.cs.

float OpenTK.Matrix4.M32 [get, set]

Gets or sets the value at row 3, column 2 of this instance.

Definition at line 214 of file Matrix4.cs.

float OpenTK.Matrix4.M33 [get, set]

Gets or sets the value at row 3, column 3 of this instance.

Definition at line 219 of file Matrix4.cs.

float OpenTK.Matrix4.M34 [get, set]

Gets or sets the value at row 3, column 4 of this instance.

Definition at line 224 of file Matrix4.cs.

float OpenTK.Matrix4.M41 [get, set]

Gets or sets the value at row 4, column 1 of this instance.

Definition at line 229 of file Matrix4.cs.

float OpenTK.Matrix4.M42 [get, set]

Gets or sets the value at row 4, column 2 of this instance.

Definition at line 234 of file Matrix4.cs.

float OpenTK.Matrix4.M43 [get, set]

Gets or sets the value at row 4, column 3 of this instance.

Definition at line 239 of file Matrix4.cs.

float OpenTK.Matrix4.M44 [get, set]

Gets or sets the value at row 4, column 4 of this instance.

Definition at line 244 of file Matrix4.cs.

 All Classes Functions Variables Enumerations Properties Events

Generated on Tue Mar 9 14:59:14 2010 for The Open Toolkit library by  doxygen 1.6.1