Actually i just tested it and it seems right kinda i don’t know i dont think the 41 42 43 are supposed to be getting dot’ed at all either. the dx page says they do though i dont see why you would move the cameras position.
I have been getting strange results that might be explained by just that.
I think m41 42 and 43 are supposed to be cameraPos. x y z
so i dunno how it works exactly like that.
sent
pos {X:0 Y:0 Z:0}
forward {X:0 Y:0 Z:-1}
up {X:0 Y:1 Z:0}
creating look at as is
you get backwards right down
returned
pos {X:0 Y:0 Z:0}
forward {X:0 Y:0 Z:-1}
right {X:1 Y:0 Z:0}
up {X:0 Y:1 Z:0}
creating test look at with all th changes was a mess
ya the order was right, had to look again, that version would be all messed up
returned
pos {X:0 Y:0 Z:0}
forward {X:0 Y:0 Z:1}
right {X:0 Y:-1 Z:0}
up {X:1 Y:0 Z:0}
creating test look at
with just the target and position switch and signs removed you get forward left down
returned
pos {X:0 Y:0 Z:0}
forward {X:0 Y:0 Z:1}
right {X:-1 Y:0 Z:0}
up {X:0 Y:1 Z:0}
uh oh … im not sure the regular version is right its altering the position then again i think the view matrix is only supposed to be rotational humm i forget i cant remember if the camera position is supposed to be part of the view matrix translation or not.
woops fudged that position test here we go.
send
pos {X:1 Y:1 Z:1}
forward {X:0 Y:0 Z:-1}
up {X:0 Y:1 Z:0}
creating look at
returned
pos {X:-0.4472136 Y:-0.3651484 Z:-1.632993}
forward {X:0.4472136 Y:0.3651484 Z:-0.8164966}
right {X:0.8944272 Y:-0.1825742 Z:0.4082483}
up {X:0 Y:0.9128709 Z:0.4082483}
creating test look at my posted version below only change is t - c
returned
pos {X:-0.4472136 Y:0.3651484 Z:-1.632993}
forward {X:-0.4472136 Y:0.3651484 Z:0.8164966}
right {X:-0.8944272 Y:-0.1825742 Z:-0.4082483}
up {X:0 Y:0.912871 Z:-0.4082483}
dx Lh
zaxis = normal(cameraTarget - cameraPosition)
xaxis = normal(cross(cameraUpVector, zaxis))
yaxis = cross(zaxis, xaxis)
xaxis.x yaxis.x zaxis.x 0
xaxis.y yaxis.y zaxis.y 0
xaxis.z yaxis.z zaxis.z 0
-dot(xaxis, cameraPosition) -dot(yaxis, cameraPosition) -dot(zaxis, cameraPosition) 1
dx Rh // eye is the target
zaxis = normal(Eye - At)
xaxis = normal(cross(Up, zaxis))
yaxis = cross(zaxis, xaxis)
xaxis.x yaxis.x zaxis.x 0
xaxis.y yaxis.y zaxis.y 0
xaxis.z yaxis.z zaxis.z 0
dot(xaxis, eye) dot(yaxis, eye) dot(zaxis, eye) 1
public static Matrix TestCreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector)
{
Matrix matrix;
TestCreateLookAt(ref cameraPosition, ref cameraTarget, ref cameraUpVector, out matrix);
return matrix;
}
// is this wrong wth ?
public static void TestCreateLookAt(ref Vector3 cameraPosition, ref Vector3 cameraTarget, ref Vector3 cameraUpVector, out Matrix result)
{
// whys this like this here.
// var vector = Vector3.Normalize(cameraPosition - cameraTarget);
// var vector2 = Vector3.Normalize(Vector3.Cross(cameraUpVector, vector));
// var vector3 = Vector3.Cross(vector, vector2);
// shouldn't it be target - position
var forwardZaxis = Vector3.Normalize(cameraTarget - cameraPosition);// vector Z
var rightYaxis = Vector3.Normalize(Vector3.Cross(cameraUpVector, forwardZaxis)); // vector2 Y
var upXaxis = Vector3.Cross(forwardZaxis, rightYaxis); // vector3 X
result.M11 = rightYaxis.X;
result.M12 = upXaxis.X;
result.M13 = forwardZaxis.X;
result.M14 = 0f;
result.M21 = rightYaxis.Y;
result.M22 = upXaxis.Y;
result.M23 = forwardZaxis.Y;
result.M24 = 0f;
result.M31 = rightYaxis.Z;
result.M32 = upXaxis.Z;
result.M33 = forwardZaxis.Z;
result.M34 = 0f;
// needed a negative here ?, because the right up forward is inverted,
// because from target was used ? beats me.
result.M41 = -Vector3.Dot(rightYaxis, cameraPosition);
result.M42 = -Vector3.Dot(upXaxis, cameraPosition);
result.M43 = -Vector3.Dot(forwardZaxis, cameraPosition);
result.M44 = 1f;
}