Skip to content

Commit

Permalink
Fixed bug in Matrix4.LookAt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robmaister committed Jan 18, 2013
1 parent 074af10 commit afefc93
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions Source/OpenTK/Math/Matrix4.cs
Expand Up @@ -806,13 +806,20 @@ public static void CreatePerspectiveOffCenter(float left, float right, float bot
float c = -(zFar + zNear) / (zFar - zNear); float c = -(zFar + zNear) / (zFar - zNear);
float d = -(2.0f * zFar * zNear) / (zFar - zNear); float d = -(2.0f * zFar * zNear) / (zFar - zNear);


result = Identity;
result.Row0.X = x; 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.Y = y;
result.Row1.Z = 0;
result.Row1.W = 0;
result.Row2.X = a; result.Row2.X = a;
result.Row2.Y = b; result.Row2.Y = b;
result.Row2.Z = c; result.Row2.Z = c;
result.Row2.W = -1; result.Row2.W = -1;
result.Row3.X = 0;
result.Row3.Y = 0;
result.Row3.Z = d; result.Row3.Z = d;
result.Row3.W = 0; result.Row3.W = 0;
} }
Expand Down Expand Up @@ -1040,23 +1047,24 @@ public static Matrix4 LookAt(Vector3 eye, Vector3 target, Vector3 up)
Vector3 x = Vector3.Normalize(Vector3.Cross(up, z)); Vector3 x = Vector3.Normalize(Vector3.Cross(up, z));
Vector3 y = Vector3.Normalize(Vector3.Cross(z, x)); Vector3 y = Vector3.Normalize(Vector3.Cross(z, x));


Matrix4 result = Identity; Matrix4 result;


//rotation
result.Row0.X = x.X; result.Row0.X = x.X;
result.Row0.Y = y.X; result.Row0.Y = y.X;
result.Row0.Z = z.X; result.Row0.Z = z.X;
result.Row0.W = 0;
result.Row1.X = x.Y; result.Row1.X = x.Y;
result.Row1.Y = y.Y; result.Row1.Y = y.Y;
result.Row1.Z = z.Y; result.Row1.Z = z.Y;
result.Row1.W = 0;
result.Row2.X = x.Z; result.Row2.X = x.Z;
result.Row2.Y = y.Z; result.Row2.Y = y.Z;
result.Row2.Z = z.Z; result.Row2.Z = z.Z;

result.Row2.W = 0;
//position result.Row3.X = -((x.X * eye.X) + (x.Y * eye.Y) + (x.Z * eye.Z));
result.Row0.W = -eye.X; result.Row3.Y = -((y.X * eye.X) + (y.Y * eye.Y) + (y.Z * eye.Z));
result.Row1.W = -eye.Y; result.Row3.Z = -((z.X * eye.X) + (z.Y * eye.Y) + (z.Z * eye.Z));
result.Row2.W = -eye.Z; result.Row3.W = 1;


return result; return result;
} }
Expand Down

0 comments on commit afefc93

Please sign in to comment.