Reputation: 33
I currently have this update code set up to rotate and move my camera.
float move = 0.5f;
float look = 0.01f;
//Rotation
if (Keyboard[Key.Left]) {
modelview = Matrix4.Mult (modelview, Matrix4.CreateRotationY (-look));
}
if (Keyboard[Key.Right]) {
modelview = Matrix4.Mult (modelview, Matrix4.CreateRotationY (look));
}
if (Keyboard[Key.Up])
{
modelview = Matrix4.Mult (modelview, Matrix4.CreateRotationX (-look));
}
if (Keyboard[Key.Down])
{
modelview = Matrix4.Mult (modelview, Matrix4.CreateRotationX (look));
}
//Movement
if (Keyboard[Key.W])
{
modelview = Matrix4.Mult (modelview, Matrix4.CreateTranslation (0f, 0f, move));
}
if (Keyboard[Key.S]) {
modelview = Matrix4.Mult (modelview, Matrix4.CreateTranslation (0f, 0f, -move));
}
if (Keyboard[Key.A])
{
modelview = Matrix4.Mult (modelview, Matrix4.CreateTranslation (move, 0f, 0));
}
if (Keyboard[Key.D]) {
modelview = Matrix4.Mult (modelview, Matrix4.CreateTranslation (-move, 0f, 0));
}
When I move my camera simulates the effect of rotating around the world origin(0,0,0) rather than its current position.
My model view matrix is loaded like so:
GL.MatrixMode (MatrixMode.Modelview);
GL.LoadMatrix (ref modelview);
Upvotes: 0
Views: 1109
Reputation: 72319
There's a lot to be done with this code. Long story short:
I believe that your code is a part of a rendering loop?
You'd need to:
move
with 3 variables, for movement in x, y, z directions,look
with 2 variables, yaw
for left-right look and pitch
for up-down look, google for "Euler angles" for more theory on this;After that, in each frame, you're supposed to:
yaw
,pitch
.To sum up, you need to separate the input handling from matrix handling, and then each frame set the correct model-view matrix (as a set of transformations) basing on current position and direction.
Upvotes: 2