这是我设置视角和绘图系统的代码:
Imports OpenTK
Imports OpenTK.Graphics
Imports OpenTK.Graphics.OpenGL
Imports System.Drawing
Public Class Form1
Private Sub GlControl1_Paint(sender As Object, e As PaintEventArgs) Handles GlControl1.Paint
GL.Clear(ClearBufferMask.ColorBufferBit)
GL.Clear(ClearBufferMask.DepthBufferBit)
Vista.Proporzioni = GlControl1.Width / GlControl1.Height
Dim perspective As Matrix4
perspective = Matrix4.CreateOrthographicOffCenter(Vista.Xmin, Vista.Xmin + Vista.Size, Vista.Ymin, Vista.Ymin + (Vista.Size / Vista.Proporzioni), Vista.ProfMin, Vista.ProfMax)
'Perspective
GL.MatrixMode(MatrixMode.Projection) 'load the camera
GL.LoadIdentity()
GL.LoadMatrix(perspective)
GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height)
GL.Enable(EnableCap.DepthTest)
GL.DepthFunc(DepthFunction.Less)
GL.Rotate(Vista.AngoloX, New Vector3(1, 0, 0)) 'asse X
GL.Rotate(0, New Vector3(0, 1, 0)) 'asse Y
GL.Rotate(Vista.AngoloZ, New Vector3(0, 0, 1)) 'asse Z
DisegnaOrg()
DisegnaGriglia()
DisegnaPezzi()
'Finally..................
GraphicsContext.CurrentContext.VSync = True ' to syncronize with the GPU ability
GlControl1.SwapBuffers() 'takes from GL and put to control
GlControl1.Invalidate()
End Sub
当我加载我的 stl 而不用代码进行转换时:
DisegnaSTL(p) 'Draw peace
DisegnaSTL 简单做:
GL.Begin(BeginMode.Triangles)
GL.Color3(Color.Silver)
GL.Vertex3(_p1.X, _p1.Y, _p1.Z)
GL.Vertex3(_p2.X, _p2.Y, _p2.Z)
GL.Vertex3(_p3.X, _p3.Y, _p3.Z)
GL.End()
对于stl的每个三角形
系统负载如下:
loading
现在对我来说,必须先在 X 轴上旋转,然后在 Z 轴上旋转,然后在最终位置上移动和平,例如 X 轴 45°,Z 轴 90°,然后在 x=20 y=30 z=10 上移动
如果我像这样只应用 X 旋转:
GL.PushMatrix() 'Fix actually situation
GL.Rotate(-45, 1, 0, 0) 'Rotation X
DisegnaSTL(p) 'Draw peace
GL.PopMatrix() 'return matrix to past state
结果正确:
only x rotation
如果我像这样只应用 Z 旋转:
GL.PushMatrix() 'Fix actually situation
GL.Rotate(90, 0, 0, 1) 'Rotation Z
DisegnaSTL(p) 'Draw peace
GL.PopMatrix() 'return matrix to past state
结果正确:
only z rotation
如果我像这样应用 X 和 Z 旋转:
GL.PushMatrix() 'Fix actually situation
GL.Rotate(-45, 1, 0, 0) 'Rotation X
GL.Rotate(90, 0, 0, 1) 'Rotation Z
DisegnaSTL(p) 'Draw peace
GL.PopMatrix() 'return matrix to past state
结果不正确:
xz rotation
然后,如果我也应用不正确的翻译,我尝试使用此代码在 Y 方向仅应用 10:
GL.PushMatrix() 'Fix actually situation
GL.Rotate(-45, 1, 0, 0) 'Rotation X
GL.Rotate(90, 0, 0, 1) 'Rotation Z
GL.Translate(-0, 10, -0) 'Translation
DisegnaSTL(p) 'Draw peace
GL.PopMatrix() 'return matrix to past state
结果是:
final
问题是,在 X 轴第一次旋转后,Z 轴也沿 X 方向旋转,我必须不是在新的正常 Z 上旋转,而是在标准 Z 上旋转,当我平移时,我必须在最终平面上非正常地在标准轴上移动