Wireframe cubes in vb.net using point 3D not executing -


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 pen     protected m_timer timer     protected m_vertices(10) point3d     protected m_faces(10, 4) integer     protected m_angle integer      private sub main_load(byval sender system.object, byval e system.eventargs) handles mybase.load         ' create gdi+ pen. used draw lines.         m_pen = new pen(color.red)          initcube()          ' create timer.         m_timer = new timer()          ' set timer interval 33 milliseconds. give 1000/34 ~ 30 frames per second.         m_timer.interval = 33          ' set callback timer.         addhandler m_timer.tick, addressof animationloop          ' start timer.         m_timer.start()     end sub      private sub initcube()         ' create array 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 array representing 6 faces of cube. each face composed indices 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 paint event called.         me.invalidate()          ' update variable after each frame.         m_angle += 1     end sub      private sub main_paint(byval sender object, byval e system.windows.forms.painteventargs) handles me.paint         dim t(8) point3d         dim f(4) integer         dim v point3d          ' clear window         e.graphics.clear(color.lightblue)          ' transform points , store them on "t"- array.         = 0 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 wireframe cube. uses "m_faces" array find vertices compose each face.         = 0 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 

this code meant show animation of 2 cubes joined rotating around 3 axis. note modified code of original program showed single cube.

the program throws error when hits loop saying "indexoutofrangeexeption occured"

for = 0 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 

the actual line (according visual studios) causing error this:

    t(i) = t(i).project(me.clientsize.width, me.clientsize.height, 256, 4) 

whats fix , why fix don't understand why problem.

m_vertices sized 11 elements, , trying read 20. t sized 9, , trying read 20. need bigger arrays, or need change way code executes. try increasing array sizes @ protected m_vertices(10) point3d , dim t(8) point3d, though may have other issues.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -