Reputation: 109
I'm experimenting with OpenGL using C# with OpenTK. I've created a scene that lays on the XY-plane, where some triangles fly around while I watch them from afar and everything was working fine. I decided to add some camera controls, so at each key press I update my view matrix. I do that using the built-in function LookAt.
This is the code of the method used to move the camera (full code can be found here):
public void Move(Vector3 move, Shader shader)
{
//Add to the camera position the change vector, which is always parallel to one of the axes
this.position += move;
//Define the target point as the current position plus the vector parallel to the Z-Axis
Vector3 target = this.position + Vector3.Forward();
//Calculate the view matrix using the current position, target and fixed up-vector
this.view = Matrix4.LookAt(position.X, position.Y, position.Z, target.X, target.Y, target.Z, 0.0f, 1.0f, 0.0f);
//Passing the matrix to the shader
shader.UpdateMatrices(this.projection, this.view);
}
(I made my own Vector3 type, so I need to pass it component by component to the function, but that shouldn't be the issue)
I would expect the camera to strafe up and down as my move vector can just be parallel to the X or Y axis. Instead it seems to move in a circle around the origin while keeping pointed towards it. It seems as if the target point was always (0,0,0) and not the position + (0,0,-1). I cannot understand why it's behaving like this, as I followed a tutorial verbatim.
I hope I managed to explain myself as this is really bugging me.
Upvotes: 0
Views: 77