旋转图像后,我正在尝试纠正模型的平移和旋转行为。这似乎是一个普遍的问题。我以前见过这个问题,但我没有看到它以我理解如何将它应用于我的代码的方式回答。我只是希望平移和旋转行为在旋转图像之前保持不变。第一次旋转后,平移和旋转永远倾斜。另外,我对 OpenGL 非常熟悉,所以请慢慢说。
Private Sub GlControl1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles GlControl1.MouseMove
If _MouseButtonLeft Then
'
' get new position of mouse
_XposEnd = e.X - _Xpos
_YposEnd = _Ypos - e.Y
'
' reset the mouse start position
_Xpos = e.X
_Ypos = e.Y
'
' change projection
GL.MatrixMode(MatrixMode.Projection)
GL.Translate(_XposEnd * _MouseSpeed, _YposEnd * _MouseSpeed, 0)
GlControl1.Invalidate()
'
End If
'
If _MouseButtonRight Then
'
' get new position of mouse
_XposEnd = e.X - _Xpos
_YposEnd = _Ypos - e.Y
'
' reset the mouse start position
_Xpos = e.X
_Ypos = e.Y
'
' change projection
GL.MatrixMode(MatrixMode.Projection)
GL.Rotate(_XposEnd * _MouseSpeed, 1, 0, 0)
GL.Rotate(_YposEnd * _MouseSpeed, 0, 1, 0)
GlControl1.Invalidate()
'
End If
End Sub
编辑1:
我的绘制循环是:
GL.Clear(ClearBufferMask.ColorBufferBit)
GL.Clear(ClearBufferMask.DepthBufferBit)
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadIdentity()
drawStuff()
GlControl1.SwapBuffers()
投影矩阵:让我备份一下。我正在绘制一个在 3D 空间 [Vertex3] 中有数千个顶点的 CAD 模型。我正在二维空间 [Ortho] 中查看它们。我修改投影矩阵以从不同的角度查看模型。我认为这比重新绘制整个模型并转换所有顶点更容易。在我看来,移动相机比重新计算数千个顶点的位置更容易。我认为这是标准的。如果没有,我会全神贯注。