Vectorballs Part One

BlitzMax Forums/BlitzMax Beginners Area/Vectorballs Part One

MacSven(Posted 2005) [#1]
I have found a Vectorball routine and i have it rewritten for BlitzMax.
But something is wrong!
The sort routine does not work correctly!
Need help!

Here is the Code

Strict

Graphics 800,600,32,hardsync
HideMouse

Incbin "media/bubblew2.png"

Global bob = LoadImage("incbin::media/bubblew2.png")

Global maxpoints
Global screenxcenter:Float
Global screenycenter:Float
Global distance:Float

maxpoints=125
screenxcenter=400
screenycenter=300
distance=30


Global points [maxpoints , 3]
Global tpoints [maxpoints , 3]
Global opoints [maxpoints]

Global i
Global j

Global z
Global y
Global x

Global ang1:Float
Global ang2:Float
Global ang3:Float

Global sx:Float
Global cx:Float
Global sy:Float
Global cy:Float
Global sz:Float
Global cz:Float
Global xy:Float
Global xz:Float
Global yz:Float
Global yx:Float
Global zx:Float
Global zy:Float

Global temp

i=0
For z = -2 To 2
For y = -2 To 2
For x = -2 To 2
points [i,0] = x
points [i,1] = y
points [i,2] = z
opoints [i] =i
i:+1
Print i
Next
Next
Next
HideMouse

maxpoints=i

While Not KeyHit(KEY_ESCAPE)
Cls

rotate3dpoints (ang1,ang2,ang3)
draw3dbobs()
sort3dbobs()

ang1=ang1+1
ang2=ang2+.21
ang3=ang3+.3
distance=30+Sin(ang1)*22
Flip

End While
ShowMouse
End

Function draw3dbobs()
SetColor 255,0,0
For i=0 To maxpoints-1
DrawImage bob,tpoints[i,0],tpoints[opoints[i],1]
'Plot tpoints[opoints[i],0],tpoints[opoints[i],1]
Next
End Function

Function sort3dbobs()
For i=0 To maxpoints
For j=0 To maxpoints-2
If tpoints[opoints[j],1] < tpoints[opoints[j+1],2] Then
temp=opoints[j+1]
opoints[j+1]=opoints[j]
opoints[j]=temp
EndIf
Next
Next
End Function

Function rotate3dpoints(xrot,yrot,zrot)
sx = Sin(xrot)
cx = Cos(xrot)
sy = Sin(yrot)
cy = Cos(yrot)
sz = Sin(zrot)
cz = Cos(zrot)
For i=0 To maxpoints-1
x=points[i,0]
y=points[i,1]
z=points[i,2]

'rotation x
xy=cx*y-sx*z
xz=sx*y+cx*z

'rotation y
yz=cy*xz-sy*x
yx=sy*xz+cy*x

'rotation z
zx=cz*yx-sz*xy
zy=sz*yx+cz*xy

'perspective correction
tpoints [i,0]=zx/(distance+yz)*512+screenxcenter
tpoints [i,1]=zy/(distance+yz)*512+screenycenter
tpoints [i,2]=yz
Next
End Function


SoggyP(Posted 2005) [#2]
Hello.

I hope you've paid the required license for the above.

Goodbye.


Who was John Galt?(Posted 2005) [#3]
Doesn't use marching cubes - no license required. If you put some basic commenting in the code I will take a look at it. What are tpoints, opoints?


SoggyP(Posted 2005) [#4]
Hello.

Okey-dokey, just thought it might be worth mentioning.

Goodbye.


Yan(Posted 2005) [#5]
You're comparing different axes in sort3dbobs()...
Function sort3dbobs()
  Local noSwap, temp
  Repeat
    noSwap = True
    For j=0 Until maxpoints - 1
      If tpoints[opoints[j],2] < tpoints[opoints[j+1],2]
        temp=opoints[j+1]
        opoints[j+1]=opoints[j]
        opoints[j]=temp
        noSwap = False
      EndIf
    Next
  Until noSwap
End Function



MacSven(Posted 2005) [#6]
Hi, thanx for all help, i've got it, i have forgotten one pointer. Next week i will make a Homepage, if i have time, with some blitzmax source!