Guest User

Untitled

a guest
Feb 9th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Const SLICES = 10
  2. Const BANDS = 10
  3. Const PI = 3.14159
  4.  
  5. Type Vert3D
  6.     x As Single
  7.     y As Single
  8.     z As Single
  9. End Type
  10.  
  11. Type Quad3D
  12.     v1 As Vert3D
  13.     v2 As Vert3D
  14.     v3 As Vert3D
  15.     v4 As Vert3D
  16. End Type
  17.  
  18. Dim Shared v(SLICES*BANDS) As Vert3D
  19. Dim Shared sphere As Quad3D Ptr = 0
  20. sphere = Allocate(1)
  21.  
  22. Sub CreateSphere(ByRef model As Quad3D Ptr)
  23.     Dim i As Integer
  24.     Dim j As Integer
  25.     Dim k As Integer
  26.     Dim sliceloop As Integer
  27.     Dim bandloop As Integer
  28.     Dim phi As Single
  29.     Dim theta As Single
  30.     Dim radius As Single
  31.    
  32.     radius = 10
  33.  
  34.     For sliceloop = 0 To SLICES - 1
  35.         phi = PI / SLICES * sliceloop
  36.         For bandloop = 0 To BANDS - 1
  37.             theta = 2 * -PI / BANDS * bandloop
  38.             v(i).x = radius * Sin(phi) * Cos(theta)
  39.             v(i).y = radius * Sin(phi) * Sin(theta)
  40.             v(i).z = radius * Cos(phi)
  41.             i = i + 1
  42.         Next
  43.     Next
  44.    
  45.     For i = 0 To SLICES * BANDS - 1
  46.         'Get lowest tens value of i and store it in j, then add the index of v2 and v3 to j
  47.         j = (i \ 10) * 10
  48.         ReAllocate(model, i * SizeOf(Quad3D))
  49.         model[i].v1 = v(i)
  50.         model[i].v2 = v(j+((i+1) Mod SLICES))
  51.         model[i].v3 = v(j+1+((i+1) Mod SLICES))
  52.         model[i].v4 = v((i+SLICES) Mod (SLICES * BANDS-1)) 'v(i+SLICES) ' Maybe
  53.     Next
  54. End Sub
  55.  
  56.  
  57. Print "A"
  58. CreateSphere(sphere)
  59. Dim i As Integer
  60.  
  61. Print "B"
  62. For i = 0 To (SLICES * BANDS - 1)
  63.     Print "Q[";i;"]: P1: X=";sphere[i].v1.x;"; Y=";sphere[i].v1.y;" Z=";sphere[i].v1.z
  64.     Print "Q[";i;"]: P2: X=";sphere[i].v2.x;"; Y=";sphere[i].v2.y;" Z=";sphere[i].v2.z
  65.     Print "Q[";i;"]: P3: X=";sphere[i].v3.x;"; Y=";sphere[i].v3.y;" Z=";sphere[i].v3.z
  66.     Print "Q[";i;"]: P4: X=";sphere[i].v4.x;"; Y=";sphere[i].v4.y;" Z=";sphere[i].v4.z
  67.     Sleep 100
  68. Next
  69.  
  70. Print "Done!"
  71. Print "Press escape to quit!"
  72.  
  73. Dim done As Byte
  74.  
  75. While done <> 1
  76.     If MultiKey(&H01) Then
  77.         done = 1
  78.     EndIf
  79. Wend
Add Comment
Please, Sign In to add comment