Windows窗体。每次按下按钮,我的代码重新绘制一个点。例如,如果我将1,1,1放在x,y和z文本框中。它将首先显示。然后,我在文本框中放入2,2,2并按下按钮。第一个点(1,1,1)消失,只有(2,2,2)显示。我想显示多个点(比如我按两次按钮,图中会显示两个点)并尽可能以数组的形式存储所有点。反正有没有继续这个?
Public Property PointCoordinates() As Vector3
Get
Dim x As Single = 0, y As Single = 0, z As Single = 0
Single.TryParse(xcor.Text, x)
Single.TryParse(ycor.Text, y)
Single.TryParse(zcor.Text, z)
Return New Vector3(x, y, z)
End Get
Set(value As Vector3)
xcor.Text = value.X.ToString()
ycor.Text = value.Y.ToString()
zcor.Text = value.Z.ToString()
End Set
End Property
Public Sub GlControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GlControl1.Paint
'First Clear Buffers
GlControl1.MakeCurrent()
GL.ClearColor(GlControl1.BackColor)
GL.Clear(ClearBufferMask.ColorBufferBit Or ClearBufferMask.DepthBufferBit)
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadIdentity()
'Basic Setup for viewing
Dim perspective As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(1.04, 4 / 3, 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
'Rotating
'Draw pyramid, Y is up, Z is twards you, X is left and right
'Vertex goes (X,Y,Z)
GL.LineWidth(1.5F)
GL.Begin(PrimitiveType.Lines)
'Face 1
GL.Color3(Color.Red)
GL.Vertex3(0, 0, 0)
GL.Vertex3(25, 0, 0)
GL.Vertex3(21.5, 1.25, -1.25)
GL.Vertex3(25, 0, 0)
GL.Vertex3(21.5, -1.25, 1.25)
GL.Vertex3(25, 0, 0)
GL.Color3(Color.Green)
GL.Vertex3(0, 0, 0)
GL.Vertex3(0, 25, 0)
GL.Vertex3(-1.25, 21.5, 1.25)
GL.Vertex3(0, 25, 0)
GL.Vertex3(1.25, 21.5, -1.25)
GL.Vertex3(0, 25, 0)
GL.Color3(Color.Blue)
GL.Vertex3(0, 0, 0)
GL.Vertex3(0, 0, 25)
GL.Vertex3(-1.25, 1.25, 21.5)
GL.Vertex3(0, 0, 25)
GL.Vertex3(1.25, -1.25, 21.5)
GL.Vertex3(0, 0, 25)
'Finish the begin mode with "end"
GL.End()
'Draw single point on the origin
GL.PointSize(2.0F)
GL.Begin(PrimitiveType.Points)
GL.Color3(Color.Black)
GL.Vertex3(0, 0, 0)
GL.End()
Dim vector = PointCoordinates
GL.PointSize(5.0F)
GL.Begin(PrimitiveType.Points)
GL.Color3(Color.Black)
GL.Vertex3(vector)
GL.End()
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
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
GlControl1.Refresh()
End sub
答案 0 :(得分:0)
创建List(Of Vector3)
,每次需要新点时,在列表中创建Vector3
和Add
。在Paint
事件处理程序中,遍历该列表并绘制每个点。