vb.net - 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
解决方案
推荐阅读
- visual-studio - 在 Visual Studio 中运行的 docker 映像与从 cmd 运行的不同
- php - Wordpress JSON 删除重复的对象 - functions.php
- java - 调整窗口大小会导致纹理拉伸
- php - 删除 Woocommerce 后端第一个文本编辑器
- scala - 在 spark scala 中,如何从变量中的“2315”等字符串中的小时数减去 30 分钟,以将字符串中的小时数返回为变量中的“2245”
- excel - 在 Excel 中查找重复帐户(超过 1000 个)
- jmeter - 如何使用客户端证书文件在非 GUI 模式下运行 jmeter
- amazon-web-services - 调用DescribeVpcEndpoints操作时发生错误(UnauthorizedOperation):您无权执行此操作
- php - 为什么下面函数中的数组执行会抛出异常?
- python - 计算熊猫数据框列中字符的出现次数