From afefc93fc6282a2a93714e12c6c363ba07789921 Mon Sep 17 00:00:00 2001 From: Robert Rouhani Date: Fri, 18 Jan 2013 15:13:36 -0800 Subject: [PATCH] Fixed bug in Matrix4.LookAt. --- Source/OpenTK/Math/Matrix4.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Source/OpenTK/Math/Matrix4.cs b/Source/OpenTK/Math/Matrix4.cs index 78fd74a4..f27de106 100644 --- a/Source/OpenTK/Math/Matrix4.cs +++ b/Source/OpenTK/Math/Matrix4.cs @@ -806,13 +806,20 @@ namespace OpenTK 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 @@ namespace OpenTK 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; }