我正在尝试熟悉在 C# 中使用 OpenTK 编写程序。我不知道如何设置和移动相机。目前,我导入了以下库:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform.Windows;
using System.Runtime.InteropServices;
using Imaging = System.Drawing.Imaging;
using TK = OpenTK.Graphics.OpenGL;
using System.IO;
using System.Threading;
我已将此代码放在 Main 中以使我的相机工作:
var myWindow = new GameWindow(840, 600);
Matrix4 perspective = Matrix4.CreatePerspectiveFieldOfView(1.04f, 4f / 3f, 1f, 10000f);//Setup Perspective
float[] persF;
persF = new float[4] { 1.04f, 4f / 3f, 1f, 10000f };
Matrix4 lookat = Matrix4.LookAt(100, 20, 0, 0, 0, 0, 0, 1, 0);// 'Setup camera
float[] lookF;
lookF = new float[9] { 100, 20, 0, 0, 0, 0, 0, 1, 0 };
GL.MatrixMode(MatrixMode.Projection);// 'Load Perspective
GL.LoadIdentity();
GL.LoadMatrix(persF);
GL.MatrixMode(MatrixMode.Modelview);// 'Load Camera
GL.LoadIdentity();
GL.LoadMatrix(lookF);
GL.Enable(EnableCap.DepthTest);// 'Enable correct Z Drawings
GL.DepthFunc(DepthFunction.Less);// 'Enable correct Z Drawings
GL.Viewport(0, 0, myWindow.Width, myWindow.Height);
当我使用GL.LoadMatrix(perspective)
andGL.LoadMatrix(lookat)
时,我得到一个重载匹配错误。出于这个原因,我将矩阵转换为浮点数组。当我尝试绘制多边形时,它们无法显示,除非此代码被注释掉(var myWindow = new GameWindow(840, 600)
命令除外)。