2020-09-20 21:49:36 +00:00
|
|
|
%import floats
|
|
|
|
%import textio
|
2020-11-22 17:17:43 +00:00
|
|
|
%import test_stack
|
2020-09-20 21:49:36 +00:00
|
|
|
%zeropage basicsafe
|
2019-01-05 01:42:58 +00:00
|
|
|
|
2020-09-20 21:49:36 +00:00
|
|
|
; Note: this program is compatible with C64 and CX16.
|
2019-01-05 01:42:58 +00:00
|
|
|
|
2020-09-20 21:49:36 +00:00
|
|
|
main {
|
2019-01-05 01:42:58 +00:00
|
|
|
|
|
|
|
; 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-09-20 21:49:36 +00:00
|
|
|
|
2020-07-25 14:25:02 +00:00
|
|
|
repeat {
|
2023-04-28 21:13:03 +00:00
|
|
|
cbm.SETTIM(0,0,0)
|
2021-01-02 19:59:48 +00:00
|
|
|
|
2019-01-05 01:42:58 +00:00
|
|
|
rotate_vertices(time)
|
2020-09-20 21:49:36 +00:00
|
|
|
txt.clear_screenchars(' ')
|
2019-01-05 01:42:58 +00:00
|
|
|
draw_edges()
|
2020-09-20 21:49:36 +00:00
|
|
|
time+=0.1
|
|
|
|
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.plot(0,0)
|
2020-09-20 21:49:36 +00:00
|
|
|
txt.print("3d cube! floats. ")
|
|
|
|
|
2021-01-02 19:59:48 +00:00
|
|
|
|
2023-04-28 21:13:03 +00:00
|
|
|
ubyte jiffies = lsb(cbm.RDTIM16())
|
2021-01-02 19:59:48 +00:00
|
|
|
txt.print_ub(jiffies)
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.print(" jiffies/fr = ")
|
2021-01-02 19:59:48 +00:00
|
|
|
txt.print_ub(60/jiffies)
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.print(" fps")
|
2020-11-22 17:17:43 +00:00
|
|
|
|
|
|
|
;test_stack.test()
|
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
|
2022-04-21 22:45:54 +00:00
|
|
|
float cosa = floats.cos(t)
|
|
|
|
float sina = floats.sin(t)
|
|
|
|
float cosb = floats.cos(t*0.33)
|
|
|
|
float sinb = floats.sin(t*0.33)
|
|
|
|
float cosc = floats.cos(t*0.78)
|
|
|
|
float sinc = floats.sin(t*0.78)
|
2019-01-05 01:42:58 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-09-04 22:17:58 +00:00
|
|
|
ubyte @zp i
|
2019-08-18 01:16:23 +00:00
|
|
|
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)
|
2020-09-04 22:17:58 +00:00
|
|
|
ubyte @zp i
|
2020-09-05 00:05:28 +00:00
|
|
|
float rz
|
|
|
|
float persp
|
2019-08-04 13:33:00 +00:00
|
|
|
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-09-20 21:49:36 +00:00
|
|
|
persp = (5.0+rz)/(txt.DEFAULT_HEIGHT as float)
|
|
|
|
sx = rotatedx[i] / persp + txt.DEFAULT_WIDTH/2.0 as ubyte
|
|
|
|
sy = rotatedy[i] / persp + txt.DEFAULT_HEIGHT/2.0 as ubyte
|
|
|
|
txt.setcc(sx, sy, 46, 1)
|
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-09-20 21:49:36 +00:00
|
|
|
persp = (5.0+rz)/(txt.DEFAULT_HEIGHT as float)
|
|
|
|
sx = rotatedx[i] / persp + txt.DEFAULT_WIDTH/2.0 as ubyte
|
|
|
|
sy = rotatedy[i] / persp + txt.DEFAULT_HEIGHT/2.0 as ubyte
|
|
|
|
txt.setcc(sx, sy, 81, 1)
|
2019-01-05 01:42:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|