private void DrawAll() { //SETGL GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.DepthTest); GL.ShadeModel(ShadingModel.Smooth); GL.ClearColor(Color.White); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); //SETVIEW GL.Viewport(0, 0, this.Bounds.Width, this.Bounds.Height); //把当前矩阵制定用于投影变换,后续的变换调用所影响的是投影矩阵projection matrix GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); /*Glu.Perspective表示创建一个表示对称透视视图平截头体的矩阵,并把它与当前矩阵相乘。fovy是YZ平面上视野的角度,范围【0,180】。 * aspect是这个平截头体的纵横比,也就是宽度除于高度。near和far值分别是观察点与近侧裁剪平面以及远侧裁剪平 * 面的距离(沿Z轴负方向)这两个值都是正的。 */ Glu.Perspective(45.0f, (float)this.Bounds.Width / (float)this.Bounds.Height, 1.0, 10.0); //摄像机位置在(0,0,4) 镜头瞄准(0,0,3) 镜头方向为方向为Y轴向上 Glu.LookAt(0.0, 0.0, 4.0, 0.0, 0.0, 3.0, 0.0, 1.0, 0.0); //调用后表示以后影响的不再是投影矩阵而是模型矩阵 GL.MatrixMode(MatrixMode.Modelview); //清除颜色和深度缓冲 GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.LoadIdentity(); GL.PushMatrix(); GL.Begin(BeginMode.Quads); GL.Color3(0.7, 0.7, 0.7); //画后墙 GL.Vertex3(-1.5f, 1.5f, -1.5f); GL.Vertex3(1.5f, 1.5f, -1.5f); GL.Vertex3(1.5f, -1.5f, -1.5f); GL.Vertex3(-1.5f, -1.5f, -1.5f); //画左墙 GL.Color3(0.7, 0.2, 0.3); GL.Vertex3(-1.5f, 1.5f, -1.5f); GL.Vertex3(-1.5f, -1.5f, -1.5f); GL.Vertex3(-1.5f, -1.5f, 1.5f); GL.Vertex3(-1.5f, 1.5f, 1.5f); //画地面 //画左墙 GL.Color3(0.2, 0.7, 0.3); GL.Vertex3(-1.5f, -1.5f, -1.5f); GL.Vertex3(1.5f, -1.5f, -1.5f); GL.Vertex3(1.5f, -1.5f, 1.5f); GL.Vertex3(-1.5f, -1.5f, 1.5f); GL.End(); GL.PopMatrix(); //对当前投影矩阵进行初始化 GL.LoadIdentity(); // 计算新的旋转矩阵,即:M = E · R = R,围绕axis向量旋转theta角度 GL.Rotate(theta, axis[0], axis[1], axis[2]); // 左乘上前一次的矩阵,即:M = R · L GL.MultMatrix(lastMatrix); // 保存此次处理结果,即:L = M GL.GetFloat(GetPName.ModelviewMatrix, lastMatrix); theta = 0.0f; // GL.LoadIdentity(); //根据角度旋转四轴 GL.Rotate(_angleX, 1, 0, 0); // GL.Rotate(_angleY, 0, 1, 0); GL.Rotate(_angleZ, 0, 0, 1); // 画坐标轴 DrawAxis(); // 画四轴 DrawAirCraft(); GL.Disable(EnableCap.DepthTest); byte[] lettersX = { 0x00, 0xef, 0x46, 0x2c, 0x2c, 0x18, 0x18, 0x18, 0x34, 0x34, 0x62, 0xf7, 0x00 }; byte[] lettersY = { 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x2c, 0x2c, 0x46, 0x46, 0xef, 0x00 }; byte[] lettersZ = { 0x00, 0xfe, 0x63, 0x63, 0x30, 0x30, 0x18, 0x0c, 0x0c, 0x06, 0xc6, 0x7f, 0x00 }; GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1.0f); GL.Color3(1.0f, 0.0f, 0.0f); GL.RasterPos3(1.4f, 0.0f, 0.0f); GL.Bitmap(8, 13, 0.0f, 0.0f, 20.0f, 0.0f, lettersX); GL.Color3(0.0f, 1.0f, 0.0f); GL.RasterPos3(0.0f, 1.4f, 0.0f); GL.Bitmap(8, 13, 0.0f, 0.0f, 20.0f, 0.0f, lettersZ); GL.Color3(0.0f, 0.0f, 1.0f); GL.RasterPos3(0.0f, 0.0f, 1.4f); GL.Bitmap(8, 13, 0.0f, 0.0f, 20.0f, 0.0f, lettersY); SwapBuffers(); }