2
Imports System.Drawing.Graphics
Imports System.Drawing.Pen
Imports System.Drawing.Color
Imports System.Drawing.Brush
Imports System.Drawing.Point
Public Class Main
Protected m_pen As Pen
Protected m_timer As Timer
Protected m_vertices(10) As Point3D
Protected m_faces(10, 4) As Integer
Protected m_angle As Integer
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create a GDI+ Pen. This will be used to draw lines.
m_pen = New Pen(Color.Red)
InitCube()
' Create the timer.
m_timer = New Timer()
' Set the timer interval to 33 milliseconds. This will give us 1000/34 ~ 30 frames per second.
m_timer.Interval = 33
' Set the callback for the timer.
AddHandler m_timer.Tick, AddressOf AnimationLoop
' Start the timer.
m_timer.Start()
End Sub
Private Sub InitCube()
' Create an array with 12 points.
m_vertices = New Point3D() {
New Point3D(0, 0, 1),
New Point3D(1, 0, -1),
New Point3D(1, 0, 1),
New Point3D(0, 0, 1),
New Point3D(0, 1, 1),
New Point3D(1, 1, 1),
New Point3D(0, 1, -1),
New Point3D(1, 1, -1),
New Point3D(-1, 0, -1),
New Point3D(-1, 0, 1),
New Point3D(-1, 1, 1),
New Point3D(-1, 1, -1)}
' Create an array representing the 6 faces of a cube. Each face is composed by indices to the vertex array
' above.
m_faces = New Integer(,) {{0, 1, 2, 3}, {0, 8, 9, 3}, {0, 1, 7, 6}, {0, 8, 6, 10}, {10, 11, 4, 6}, {4, 5, 6, 7}, {2, 3, 4, 5}, {3, 4, 11, 9}, {8, 9, 10, 11}, {1, 2, 5, 7}}
End Sub
Private Sub AnimationLoop()
' Forces the Paint event to be called.
Me.Invalidate()
' Update the variable after each frame.
m_angle += 1
End Sub
Private Sub Main_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim t(8) As Point3D
Dim f(4) As Integer
Dim v As Point3D
' Clear the window
e.Graphics.Clear(Color.LightBlue)
' Transform all the points and store them on the "t"- array.
For i = 0 To 19
v = m_vertices(i)
t(i) = v.RotateX(m_angle).RotateY(m_angle).RotateZ(m_angle)
t(i) = t(i).Project(Me.ClientSize.Width, Me.ClientSize.Height, 256, 4)
Next
' Draw the wireframe cube. Uses the "m_faces" array to find the vertices that compose each face.
For i = 0 To 17
e.Graphics.DrawLine(m_pen, CInt(t(m_faces(i, 0)).X), CInt(t(m_faces(i, 0)).Y), CInt(t(m_faces(i, 1)).X), CInt(t(m_faces(i, 1)).Y))
e.Graphics.DrawLine(m_pen, CInt(t(m_faces(i, 1)).X), CInt(t(m_faces(i, 1)).Y), CInt(t(m_faces(i, 2)).X), CInt(t(m_faces(i, 2)).Y))
e.Graphics.DrawLine(m_pen, CInt(t(m_faces(i, 2)).X), CInt(t(m_faces(i, 2)).Y), CInt(t(m_faces(i, 3)).X), CInt(t(m_faces(i, 3)).Y))
e.Graphics.DrawLine(m_pen, CInt(t(m_faces(i, 3)).X), CInt(t(m_faces(i, 3)).Y), CInt(t(m_faces(i, 0)).X), CInt(t(m_faces(i, 0)).Y))
Next
End Sub
End Class
このコードは、3つの軸の周りを回転する2つの立方体のアニメーションを示します。これは、ただ1つのキューブを示した元のプログラムの修正されたコードです。それは「indexOutOfRangeExeption発生した」vb.netのワイヤフレームキューブを使用してポイント3Dを実行しない
For i = 0 To 19
v = m_vertices(i)
t(i) = v.RotateX(m_angle).RotateY(m_angle).RotateZ(m_angle)
t(i) = t(i).Project(Me.ClientSize.Width, Me.ClientSize.Height, 256, 4)
Next
を言って、このループに当たったとき
プログラムがエラーをスローし、エラーの原因となっている(ビジュアルスタジオによる)実際の行はこれです:
t(i) = t(i).Project(Me.ClientSize.Width, Me.ClientSize.Height, 256, 4)
なぜこれが問題なのか分からないので、これを修正し、それを修正するのはなぜですか?