Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug in Matrix4.LookAt.

  • Loading branch information...
commit afefc93fc6282a2a93714e12c6c363ba07789921 1 parent 074af10
@Robmaister Robmaister authored
Showing with 16 additions and 8 deletions.
  1. +16 −8 Source/OpenTK/Math/Matrix4.cs
View
24 Source/OpenTK/Math/Matrix4.cs
@@ -806,13 +806,20 @@ public static void CreatePerspectiveOffCenter(float left, float right, float bot
float c = -(zFar + zNear) / (zFar - zNear);
float d = -(2.0f * zFar * zNear) / (zFar - zNear);
- result = Identity;
result.Row0.X = x;
+ result.Row0.Y = 0;
+ result.Row0.Z = 0;
+ result.Row0.W = 0;
+ result.Row1.X = 0;
result.Row1.Y = y;
+ result.Row1.Z = 0;
+ result.Row1.W = 0;
result.Row2.X = a;
result.Row2.Y = b;
result.Row2.Z = c;
result.Row2.W = -1;
+ result.Row3.X = 0;
+ result.Row3.Y = 0;
result.Row3.Z = d;
result.Row3.W = 0;
}
@@ -1040,23 +1047,24 @@ public static Matrix4 LookAt(Vector3 eye, Vector3 target, Vector3 up)
Vector3 x = Vector3.Normalize(Vector3.Cross(up, z));
Vector3 y = Vector3.Normalize(Vector3.Cross(z, x));
- Matrix4 result = Identity;
+ Matrix4 result;
- //rotation
result.Row0.X = x.X;
result.Row0.Y = y.X;
result.Row0.Z = z.X;
+ result.Row0.W = 0;
result.Row1.X = x.Y;
result.Row1.Y = y.Y;
result.Row1.Z = z.Y;
+ result.Row1.W = 0;
result.Row2.X = x.Z;
result.Row2.Y = y.Z;
result.Row2.Z = z.Z;
-
- //position
- result.Row0.W = -eye.X;
- result.Row1.W = -eye.Y;
- result.Row2.W = -eye.Z;
+ result.Row2.W = 0;
+ result.Row3.X = -((x.X * eye.X) + (x.Y * eye.Y) + (x.Z * eye.Z));
+ result.Row3.Y = -((y.X * eye.X) + (y.Y * eye.Y) + (y.Z * eye.Z));
+ result.Row3.Z = -((z.X * eye.X) + (z.Y * eye.Y) + (z.Z * eye.Z));
+ result.Row3.W = 1;
return result;
}
Please sign in to comment.
Something went wrong with that request. Please try again.