首页 > 解决方案 > OpenTK 图形

问题描述

我在 Vb.Net 中使用带有 GlControl 的 OpenTK。我想知道如何编程鼠标功能以使用鼠标执行旋转和缩放。我想编写类似于 CAD 软件的鼠标功能。我正在绘制 x,y,z 向量。作为基础,我使用了我在 youtube ( https://www.youtube.com/watch?v=idnyxboXNMI ) 上找到的代码。

Private Sub GlControl1_Paint(sender As Object, e As PaintEventArgs) Handles GlControl1.Paint
    Call Scrolls()
    'First Clear Buffers
    GL.Clear(ClearBufferMask.ColorBufferBit)
    GL.Clear(ClearBufferMask.DepthBufferBit)


    'Basic Setup for viewing
    Dim perspective As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(1, 1, 1, 10000) 'Setup Perspective
    Dim lookat As Matrix4 = Matrix4.LookAt(100, 20, 0, 0, 0, 0, 0, 1, 0) 'Setup camera

    GL.MatrixMode(MatrixMode.Projection) 'Load Perspective
    GL.LoadIdentity()
    GL.LoadMatrix(perspective)
    GL.MatrixMode(MatrixMode.Modelview) 'Load Camera
    GL.LoadIdentity()
    GL.LoadMatrix(lookat)
    GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height) 'Size of window
    GL.Enable(EnableCap.DepthTest) 'Enable correct Z Drawings
    GL.DepthFunc(DepthFunction.Less) 'Enable correct Z Drawings

    GL.Rotate(mousepos.X, 1, 1, 0)

    'GL.Translate(New Vector3(0, mousepos.Y, 0))
    'Rotating
    GL.Rotate(270, 1, 0, 0)
    GL.Rotate(VSbX.Value, 1, 0, 0)
    GL.Rotate(VSbY.Value, 0, 1, 0)
    GL.Rotate(VSbZ.Value, 0, 0, 1)

    'Draw pyramid, Y is up, Z is twards you, X is left and right
    'Vertex goes (X,Y,Z)
    GL.Begin(BeginMode.Lines)
    GL.Color3(Color.Red)
    GL.Vertex3(0, 0, 0)
    GL.Vertex3(60, 0, 0)
    GL.End()

    GL.Begin(BeginMode.Lines)
    GL.Color3(Color.Green)
    GL.Vertex3(0, 0, 0)
    GL.Vertex3(0, 60, 0)
    GL.End()

    GL.Begin(BeginMode.Lines)
    GL.Color3(Color.Blue)
    GL.Vertex3(0, 0, 0)
    GL.Vertex3(0, 0, 60)
    GL.End()
    With AcceptButton Gl controddd
    'Call Graphic()
    GL.Begin(BeginMode.LineLoop)

    For i = 0 To vectorX.Count - 1
    GL.Vertex3(vectorX(i), vectorY(i), vectorZ(i))
    Next i
    
    'Finish the begin mode with "end"
    GL.End()
    'Finally...
    GraphicsContext.CurrentContext.VSync = True 'Caps frame rate as to not over run GPU
    GlControl1.SwapBuffers() 'Takes from the 'GL' and puts into control

End Sub

标签: vb.netopentk

解决方案


推荐阅读