我目前已将此更新代码设置为旋转和移动我的相机。
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));
}
当我移动我的相机时,它模拟了围绕世界原点(0,0,0)而不是其当前位置旋转的效果。
我的模型视图矩阵是这样加载的:
GL.MatrixMode (MatrixMode.Modelview);
GL.LoadMatrix (ref modelview);