現在、カメラを回転および移動するようにこの更新コードを設定しています。
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);