我一直在OpenTK上进行编码,到目前为止,我编写了一个脚本,其中草纹理的立方体在照明下旋转。我已经使多维数据集可以使用W A D S进行移动,除了模拟第一人称视角之外,我还使多维数据集向相反的方向移动。我想创建一个lookAt函数,它不起作用。我已经搜索了教程,但是没有一个可以使用。现在我被困住了,有人可以帮我吗?
void Start()
{
window.Load += loaded;
window.Resize += resize;
window.RenderFrame += renderF;
window.KeyPress += keyPress;
window.Run(1.0/60.0);
}
void resize(object ob,EventArgs e)
{
GL.Viewport(0,0,window.Width,window.Height);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Matrix4 matrix = Matrix4.Perspective(45.0f,window.Width/window.Height,1.0f,1000.0f);
Matrix4 view = Matrix4.LookAt(new Vector3(0.0f, 0.0f,
0.0f),newVector3(0.0f,0.0f,0.0f),newVector3(0.0f, 0.0f, 0.0f));
Vector3 Position = new Vector3(0.0f, 0.0f, 3.0f);
GL.LoadMatrix(ref matrix);
//GL.LoadMatrix(ref view);
GL.MatrixMode(MatrixMode.Modelview);
}
void renderF(object o , EventArgs e)
{
GL.LoadIdentity();
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
//CUBE 1:
GL.PushMatrix();
GL.Translate(x,y,z);
GL.Rotate(theta,1.0,0.0,0.0);
GL.Rotate(theta,1.0,0.0,1.0);
GL.Scale(0.7,0.7,0.7);
draw_cube();
GL.PopMatrix();
window.SwapBuffers();
theta += count;
}
在Legacy OpenGL中,存在不同的当前矩阵。参见MatrixMode
。投影矩阵必须设置为当前MatrixMode
矩阵,模型矩阵必须设置为当前MatrixMode.Projection
。必须在操作矩阵的操作之前设置当前矩阵模式。