2019-01-20 16:45:57 +00:00
|
|
|
%import c64lib
|
2019-01-05 01:42:58 +00:00
|
|
|
%import c64utils
|
2019-01-05 15:09:05 +00:00
|
|
|
%import c64flt
|
2019-01-05 01:42:58 +00:00
|
|
|
|
2019-07-29 21:11:13 +00:00
|
|
|
main {
|
2019-01-05 01:42:58 +00:00
|
|
|
|
|
|
|
const uword width = 40
|
|
|
|
const uword height = 25
|
|
|
|
|
|
|
|
; vertices
|
2019-04-15 23:19:51 +00:00
|
|
|
float[] xcoor = [ -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0 ]
|
|
|
|
float[] ycoor = [ -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0 ]
|
|
|
|
float[] zcoor = [ -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ]
|
2019-01-05 01:42:58 +00:00
|
|
|
|
|
|
|
; storage for rotated coordinates
|
|
|
|
float[len(xcoor)] rotatedx=0.0
|
|
|
|
float[len(ycoor)] rotatedy=0.0
|
|
|
|
float[len(zcoor)] rotatedz=-1.0
|
|
|
|
|
|
|
|
sub start() {
|
|
|
|
float time=0.0
|
2020-07-25 14:25:02 +00:00
|
|
|
repeat {
|
2019-01-05 01:42:58 +00:00
|
|
|
rotate_vertices(time)
|
2019-01-06 03:02:11 +00:00
|
|
|
c64scr.clear_screenchars(32)
|
2019-01-05 01:42:58 +00:00
|
|
|
draw_edges()
|
|
|
|
time+=0.2
|
2019-03-21 21:36:46 +00:00
|
|
|
c64scr.plot(0,0)
|
2019-01-06 14:53:01 +00:00
|
|
|
c64scr.print("3d cube! (float) ")
|
|
|
|
c64scr.print_ub(c64.TIME_LO)
|
2020-03-14 16:11:10 +00:00
|
|
|
c64scr.print(" jiffies/fr = ")
|
|
|
|
c64scr.print_ub(60/c64.TIME_LO)
|
|
|
|
c64scr.print(" fps")
|
2019-01-06 14:53:01 +00:00
|
|
|
c64.TIME_LO=0
|
2019-01-05 01:42:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub rotate_vertices(float t) {
|
|
|
|
; rotate around origin (0,0,0)
|
|
|
|
|
|
|
|
; set up the 3d rotation matrix values
|
|
|
|
float cosa = cos(t)
|
|
|
|
float sina = sin(t)
|
|
|
|
float cosb = cos(t*0.33)
|
|
|
|
float sinb = sin(t*0.33)
|
|
|
|
float cosc = cos(t*0.78)
|
|
|
|
float sinc = sin(t*0.78)
|
|
|
|
|
|
|
|
float cosa_sinb = cosa*sinb
|
|
|
|
float sina_sinb = sina*sinb
|
|
|
|
float Axx = cosa*cosb
|
|
|
|
float Axy = cosa_sinb*sinc - sina*cosc
|
|
|
|
float Axz = cosa_sinb*cosc + sina*sinc
|
|
|
|
float Ayx = sina*cosb
|
|
|
|
float Ayy = sina_sinb*sinc + cosa*cosc
|
|
|
|
float Ayz = sina_sinb*cosc - cosa*sinc
|
|
|
|
float Azx = -sinb
|
|
|
|
float Azy = cosb*sinc
|
|
|
|
float Azz = cosb*cosc
|
|
|
|
|
2019-08-18 01:16:23 +00:00
|
|
|
ubyte i
|
|
|
|
for i in 0 to len(xcoor)-1 {
|
2019-01-06 14:53:01 +00:00
|
|
|
rotatedx[i] = Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i]
|
|
|
|
rotatedy[i] = Ayx*xcoor[i] + Ayy*ycoor[i] + Ayz*zcoor[i]
|
|
|
|
rotatedz[i] = Azx*xcoor[i] + Azy*ycoor[i] + Azz*zcoor[i]
|
2019-01-05 01:42:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub draw_edges() {
|
|
|
|
|
|
|
|
; plot the points of the 3d cube
|
|
|
|
; first the points on the back, then the points on the front (painter algorithm)
|
2019-08-04 13:33:00 +00:00
|
|
|
ubyte i
|
|
|
|
float rz
|
|
|
|
float persp
|
|
|
|
ubyte sx
|
|
|
|
ubyte sy
|
2019-01-05 01:42:58 +00:00
|
|
|
|
2019-08-04 13:33:00 +00:00
|
|
|
for i in 0 to len(xcoor)-1 {
|
|
|
|
rz = rotatedz[i]
|
2019-01-05 01:42:58 +00:00
|
|
|
if rz >= 0.1 {
|
2020-03-14 17:11:24 +00:00
|
|
|
persp = (5.0+rz)/(height as float)
|
2019-08-04 13:33:00 +00:00
|
|
|
sx = rotatedx[i] / persp + width/2.0 as ubyte
|
|
|
|
sy = rotatedy[i] / persp + height/2.0 as ubyte
|
2019-01-06 20:46:35 +00:00
|
|
|
c64scr.setcc(sx, sy, 46, i+2)
|
2019-01-05 01:42:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-04 13:33:00 +00:00
|
|
|
for i in 0 to len(xcoor)-1 {
|
|
|
|
rz = rotatedz[i]
|
2019-01-05 01:42:58 +00:00
|
|
|
if rz < 0.1 {
|
2020-03-14 17:11:24 +00:00
|
|
|
persp = (5.0+rz)/(height as float)
|
2019-08-04 13:33:00 +00:00
|
|
|
sx = rotatedx[i] / persp + width/2.0 as ubyte
|
|
|
|
sy = rotatedy[i] / persp + height/2.0 as ubyte
|
2019-01-06 20:46:35 +00:00
|
|
|
c64scr.setcc(sx, sy, 81, i+2)
|
2019-01-05 01:42:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|