I have been trying to achieve a simple 3D engine in VB.NET and it's visually pretty good.
(Except i still need to add a Z-Buffer or Painter's algorithm to properly show concave shapes)
Name:  Monkey.png
Views: 511
Size:  11.6 KB
My problem is when it come to a model with a large amount of triangles(such as the monkey) the fps drop significantly to where is slightly freezes as it's rotating.
I figured my rotate function creating a new mesh every time might be too much to ask for:
vb.net Code:
  1. Public Function Rotate_X(ByVal Angle As Single) As Mesh
  2.         Dim Sin_T As Double = Math.Sin(Angle * Math.PI / 180)
  3.         Dim Cos_T As Double = Math.Cos(Angle * Math.PI / 180)
  4.         Dim MSH As New Mesh
  5.         For Each Triangle As TriFace In arr_Faces
  6.             Dim TF As TriFace = Triangle.Clone
  7.             For Each Vertex As PVector In TF.Vertices
  8.                 Dim Y As Double = Vertex.Y
  9.                 Dim Z As Double = Vertex.Z
  10.                 Vertex.Y = CSng(Y * Cos_T - Z * Sin_T)
  11.                 Vertex.Z = CSng(Z * Cos_T + Y * Sin_T)
  12.             Next
  13.             MSH.AddFace(TF)
  14.         Next
  15.         Return MSH
  16.     End Function
So I instead made a function to fetch Vertices in a mesh and rotate them directly but that was even slower.
When it comes to models with a smaller amount of face everything runs smoothly though.

I'm using the fillpath method in in paint event; Should I switch to a bitmap and make my own raster function instead using setpixel ?
vb.net Code:
  1. Dim new_Points() As Point = {New Point(PTriangle.Vertex_A.X, PTriangle.Vertex_A.Y), New Point(PTriangle.Vertex_B.X, PTriangle.Vertex_B.Y), New Point(PTriangle.Vertex_C.X, PTriangle.Vertex_C.Y)}
  2.                 Dim TrianglePath As New Drawing2D.GraphicsPath(Drawing2D.FillMode.Alternate)
  3.                 TrianglePath.AddLines(new_Points)
  4.                 TrianglePath.CloseFigure()
  5.                 Dim MyBrush As New Drawing.SolidBrush(TriColor)
  6.                 GFX.FillPath(MyBrush, TrianglePath)

Or do I just need to use a language with access to the graphics card at this point ?
I'm kind of lost ... thnx in advance for suggestions.