假设选取点坐标(ScannerPoint(0),ScannerPoint(1),ScannerPoint(2))
Private Sub OpenGLControlPts_MouseClick(sender As Object, e As MouseEventArgs) Handles OpenGLControlPts.MouseClick
Dim trans As mat4 = New mat4(1.0F)
Dim model = glm.translate(trans, New vec3(-centerX_1, -centerY_1, -centerZ_1))
Dim projection = glm.perspective(glm.radians(45), CSng(SCR_WIDTH) / SCR_HEIGHT, 0.1F, 100.0F)
Dim position As New vec3(0, 0, zoomRaw)
Dim view = glm.lookAt(position, New vec3(0, 0, 0), New vec3(0, 1, 0))
view = glm.rotate(view, glm.radians(rotateRawX), New vec3(1.0F, 0.0F, 0.0F))
view = glm.rotate(view, glm.radians(rotateRawY), New vec3(0.0F, 0F, 1.0F))
Dim maxZ = -1.0F
For i = 0 To pointList.Count - 1
Dim p = projection * view * model * New vec4(pointList(i), 1.0)
If Math.Abs(p.x / (p.w * 2) - (labelX - SCR_WIDTH / 2) / SCR_WIDTH) < 10 / SCR_WIDTH And
Math.Abs(p.y / (p.w * 2) + (labelY - SCR_HEIGHT / 2) / SCR_HEIGHT) < 10 / SCR_HEIGHT And
Math.Abs(p.z / (p.w * 2)) < 1 Then
If (p.z / (p.w * 2)) > maxZ Then
ScannerPoint(0) = pointList(i).x
ScannerPoint(1) = pointList(i).y
ScannerPoint(2) = pointList(i).z
ScannerPoint(3) = 1
End If
End If
Next
End Sub
Private Sub OpenGLControlPts_MouseMove(sender As Object, e As MouseEventArgs) Handles OpenGLControlPts.MouseMove
If isMouseDown Then
rotateRawX = lastRotateRawX + e.Y - downY
rotateRawY = lastRotateRawY + e.X - downX
End If
Try
labelX = e.X
labelY = e.Y
Catch ex As Exception
End Try
End Sub
Private Sub OpenGLControlPts_MouseDown(sender As Object, e As MouseEventArgs) Handles OpenGLControlPts.MouseDown
isMouseDown = True
downX = e.X
downY = e.Y
End Sub
Private Sub OpenGLControlPts_MouseWheel(sender As Object, e As MouseEventArgs) Handles OpenGLControlPts.MouseWheel
If e.Delta > 0 And zoomRaw < 70 Then
zoomRaw += 3
Else
zoomRaw -= 3
End If
End Sub
Private Sub OpenGLControlPts_MouseUp(sender As Object, e As MouseEventArgs) Handles OpenGLControlPts.MouseUp
If isMouseDown Then
isMouseDown = False
lastRotateRawX = rotateRawX
lastRotateRawY = rotateRawY
End If
End Sub
Private Sub OpenGLControlPts_OpenGLDraw(sender As Object, e As RenderEventArgs) Handles OpenGLControlPts.OpenGLDraw
Dim gl As OpenGL = Me.OpenGLControlPts.OpenGL
centerX_1 = (aminX_1 + amaxX_1) / 2
centerY_1 = (aminY_1 + amaxY_1) / 2
centerZ_1 = (aminZ_1 + amaxZ_1) / 2
scale_X_1 = (amaxX_1 - aminX_1)
scale_Y_1 = (amaxY_1 - aminY_1)
gl.ClearColor(0.8, 0.8, 0.8, 0.1) 'alpha不透明度,设置清除颜色
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT Or OpenGL.GL_DEPTH_BUFFER_BIT)
gl.LoadIdentity()
gl.Translate(0, 0, -zoomRaw)
gl.Rotate(rotateRawX, 1.0, 0, 0)
gl.Rotate(rotateRawY, 0, 0, 1.0)
'gl.Rotate(rotateRawZ, 0, 0, 1.0)
gl.Scale(1.0, 1.0, 1.0) '缩放尺寸,由于界面可能放不下,因此整体缩小显示。
Dim projection = glm.perspective(glm.radians(45), CSng(SCR_WIDTH) / SCR_HEIGHT, 0.1F, 100.0F) '
Dim position As New vec3(0, 0, zoomRaw)
Dim view = glm.lookAt(position, New vec3(0, 0, 0), New vec3(0, 1, 0))
view = glm.rotate(view, glm.radians(rotateRawX * 360 / SCR_HEIGHT), New vec3(1.0F, 0.0F, 0.0F))
view = glm.rotate(view, glm.radians(rotateRawY * 360 / SCR_WIDTH), New vec3(0.0F, 0F, 1.0F))
Dim model As New mat4(1.0F)
pointCloudShader.use()
pointCloudShader.setMat4("projection", projection)
pointCloudShader.setMat4("view", view)
pointCloudShader.setMat4("model", model)
end sub