Sub Globals
Dim bmp As Bitmap
Type bodyframe(x As Float,y As Float,z As Float) ' body 3D coordinates
Dim body(21) As bodyframe
Dim rotbody(21) As bodyframe
Dim flat(15,3) As Float
end sub
Sub DrawBody
Dim x,y,z As Float
x = posx ' offset where to put the body
y = posy
z = posz
For i = 0 To 18
rotbody(i).x = body(i).x
rotbody(i).y = body(i).y
rotbody(i).z = body(i).z
Next
' calculate new body points
rotate
flatten
Polygons
End Sub
Sub rotate
Dim sx,cx,sy,cy,sz,cz,tempx,tempy As Float
sx = SinD(pitch)
cx = CosD(pitch)
sy = SinD(angle_xz)
cy = CosD(angle_xz)
sz = SinD(roll)
cz = CosD(roll)
For i=0 To nVertices - 1
tempx = (cz*cy-sz*sx*sy)*rotbody(i).x -(cy*sz+sy*sx*cz)*rotbody(i).y + sy*cx*rotbody(i).z
tempy = cx*sz *rotbody(i).x + cz*cx*rotbody(i).y + sx*rotbody(i).z
rotbody(i).z = -(sy*cz+cy*sx*sz)*rotbody(i).x +(sy*sz-cy*sx*cz)*rotbody(i).y + cx*cy*rotbody(i).z
rotbody(i).x = tempx
rotbody(i).y = tempy
Next
End Sub
Sub flatten
Dim zfx,zfy,newx,newy,newz As Float
zfx = SinD(45)/2 ' viewing angle
zfy = CosD(45)/2
For i=0 To nVertices -1
newx = rotbody(i).x + posx
newy = rotbody(i).y + posy
newz = rotbody(i).z + posz
flat(i,0) = centx + zoom *(newx + zfx*newz) /(1+perspective*newz)
flat(i,1) = centy - 0.92 * (zoom*(newy + zfy*newz))/(1+perspective*newz)
flat(i,2) = newz
Next
End Sub
Sub Polygons '(Int nPolygons,String [] PL , Double [,] FL,Int [] CL )
Dim det, big As Float
Dim strarr() As String 'To split the polygon String To points.
Dim m,k0,k1,k2, order As Int
Dim xy As Path
det = 0 ' determinant of 3 first points of each polygon
Dim mp, mp1 As Map
mp.Initialize
mp1.Initialize
For i = 0 To npolygons - 1
strarr = Regex.Split(",",pol(i))
Zsum(i) = 0
For j=0 To strarr.Length -1
m = strarr(j)
Zsum(i) = Zsum(i) + flat(m,2) ' add Z values To sum
Next
mp.put(i,Zsum(i))
Next
For j = 0 To npolygons - 1
big = 0
order = 0
For i = 0 To mp.Size - 1
If mp.GetValueAt(i) > big Then
big = mp.GetValueAt(i)
order = i
End If
Next
mp1.Put(order,big)
mp.Remove(mp.GetKeyAt(order))
Next
Activity.SetBackgroundImage(bmp)
gr.Initialize(Activity)
For m = 0 To npolygons - 1
strarr = Regex.Split(",",pol(m))
k0 = strarr(0)
k1 = strarr(1)
k2 = strarr(2)
det = flat(k0,0) * ( flat(k2,1) - flat(k1,1)) + flat(k1,0) * ( flat(k0,1) - flat(k2,1)) + flat(k2,0) * ( flat(k1,1) - flat(k0,1))
If det < 0 Then ' the poligon Is in front
xy.Initialize(flat(k0,0),flat(k0,1))
xy.LineTo(flat(k1,0),flat(k1,1))
xy.LineTo(flat(k2,0),flat(k2,1))
xy.LineTo(flat(k0,0),flat(k0,1))
gr.DrawPath(xy,Color(m),True,2)
End If
Next
Activity.Invalidate
End Sub
Sub s7_click
Dim stx(),sty(),stz() As String
nVertices = 15
npoligons = 18
stx = Regex.Split(",","6,0,0,0,0,-6,-1,1,0,0,0,-0.17,-1.5,1.5,0.17")
stz = Regex.Split(",","-3,-1.5,0,1.5,0,-3,-2,-2,-5,-5.5,-3.5,-3.5, -5.5,-5.5,-3.5")
sty = Regex.Split(",","1.5,0,0.5,0,-0.25,1.5,0,0,0,1.5,0.17,0,0,0,0")
For i = 0 To nVertices - 1
body(i).x = stx(i)
body(i).y = sty(i)
body(i).z = stz(i)
Next
pol(0) = "5,6,4"
Color(0) = Colors.Blue
pol(1) = "5,4,3"
Color(1) = Colors.rgb(255,125,125)
pol(2) = "0,7,2"
Color(2) = Colors.Yellow
pol(3) = "0,2,3"
Color(3) = Colors.Green 'Rgb(255,128,192)
pol(4) = "6,5,2"
Color(4) = Colors.Green
pol(5) = "2,5,3"
Color(5) = Colors.Yellow
pol(6) = "7,0,4"
Color(6) = Colors.rgb(255,125,125)
pol(7) = "4,0,3"
Color(7) = Colors.Blue
pol(8) = "2,8,6"
Color(8) = Colors.Yellow
pol(9) = "8,2,7"
Color(9) = Colors.Green
pol(10) = "4,6,8"
Color(10) = Colors.rgb(255,125,125)
pol(11) = "4,8,7"
Color(11) = Colors.Blue
pol(12) = "8,9,10"
Color(12) = Colors.Red
pol(13) = "10,9,8"
Color(13) = Colors.Red
pol(14) = "11,8,12"
Color(14) = Colors.Red
pol(15) = "14,13,8"
Color(15) = Colors.Red
pol(16) = "14,8,13"
Color(16) = Colors.Red
pol(17) = "12,8,11"
Color(17) = Colors.Red
zoom = 15
End Sub