mirror of
https://github.com/irmen/prog8.git
synced 2024-12-27 05:29:38 +00:00
tweaking cobra mk3
This commit is contained in:
parent
18f5963b09
commit
2f951bd54d
@ -200,13 +200,13 @@ romsub $ff23 = GRAPH_clear() clobbers(A,X,Y)
|
||||
romsub $ff26 = GRAPH_set_window() ; uses x=r0, y=r1, width=r2, height=r3
|
||||
romsub $ff29 = GRAPH_set_colors(ubyte stroke @A, ubyte fill @X, ubyte background @Y) clobbers (A,X,Y)
|
||||
romsub $ff2c = GRAPH_draw_line() clobbers(A,X,Y) ; uses x1=r0, y1=r1, x2=r2, y2=r3
|
||||
romsub $ff2f = GRAPH_draw_rect(ubyte fill @Pc) ; uses x=r0, y=r1, width=r2, height=r3, cornerradius=r4
|
||||
romsub $ff2f = GRAPH_draw_rect(ubyte fill @Pc) clobbers(A,X,Y) ; uses x=r0, y=r1, width=r2, height=r3, cornerradius=r4
|
||||
romsub $ff32 = GRAPH_move_rect() ; uses sx=r0, sy=r1, tx=r2, ty=r3, width=r4, height=r5
|
||||
romsub $ff35 = GRAPH_draw_oval(ubyte fill @Pc) ; uses x=r0, y=r1, width=r2, height=r3
|
||||
romsub $ff38 = GRAPH_draw_image() ; uses x=r0, y=r1, ptr=r2, width=r3, height=r4
|
||||
romsub $ff3b = GRAPH_set_font() ; uses ptr=r0
|
||||
romsub $ff3e = GRAPH_get_char_size(ubyte baseline @A, ubyte width @X, ubyte height_or_style @Y, ubyte is_control @Pc)
|
||||
romsub $ff41 = GRAPH_put_char(ubyte char @A) ; uses x=r0, y=r1
|
||||
romsub $ff41 = GRAPH_put_char(ubyte char @A) clobbers(A,X,Y) ; uses x=r0, y=r1
|
||||
|
||||
; framebuffer
|
||||
romsub $fef6 = FB_init()
|
||||
|
@ -1,24 +1,14 @@
|
||||
%target cx16
|
||||
%import cx16lib
|
||||
%import conv
|
||||
|
||||
main {
|
||||
|
||||
; Ship model data converted from BBC Elite's Cobra MK 3
|
||||
; downloaded from http://www.elitehomepage.org/archive/index.htm
|
||||
|
||||
; vertices
|
||||
word[] xcoor = [ 32,-32,0,-120,120,-88,88,128,-128,0,-32,32,-36,-8,8,36,36,8,-8,-36,-1,-1,-80,-80,-88,80,88,80,1,1,1,1,-1,-1 ]
|
||||
word[] ycoor = [ 0,0,26,-3,-3,16,16,-8,-8,26,-24,-24,8,12,12,8,-12,-16,-16,-12,-1,-1,-6,6,0,6,0,-6,-1,-1,1,1,1,1 ]
|
||||
word[] zcoor = [ 76,76,24,-8,-8,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,76,90,-40,-40,-40,-40,-40,-40,76,90,76,90,76,90 ]
|
||||
|
||||
; storage for rotated coordinates
|
||||
word[len(xcoor)] rotatedx
|
||||
word[len(ycoor)] rotatedy
|
||||
word[len(zcoor)] rotatedz
|
||||
word[shipdata.totalNumberOfPoints] rotatedx
|
||||
word[shipdata.totalNumberOfPoints] rotatedy
|
||||
word[shipdata.totalNumberOfPoints] rotatedz
|
||||
|
||||
; edges
|
||||
ubyte[] edgesFrom = [ 0,1,0,10,1,0,2,0,4,0,4,7,2,1,1,3,8,3,2,5,6,5,6,16,15,14,14,18,13,12,12,26,25,25,22,23,22,20,28,21,20,28,29,30,31,30,32,20,21,20,20 ]
|
||||
ubyte[] edgesTo = [ 1,2,2,11,10,11,6,6,6,4,7,11,5,5,3,5,10,8,9,9,9,8,7,17,16,15,17,19,18,13,19,27,26,27,23,24,24,28,29,29,21,30,31,31,33,32,33,32,33,33,29 ]
|
||||
|
||||
; TODO hidden surface removal - this needs surfaces data and surface normal calculations.
|
||||
; TODO add all other Elite's ships, show their name, advance to next ship on keypress
|
||||
@ -31,18 +21,76 @@ main {
|
||||
void cx16.screen_set_mode($80)
|
||||
cx16.r0 = 0
|
||||
cx16.GRAPH_init()
|
||||
cx16.GRAPH_set_colors(1, 2, 0)
|
||||
cx16.GRAPH_set_colors(13, 6, 6)
|
||||
cx16.GRAPH_clear()
|
||||
print_ship_name()
|
||||
|
||||
|
||||
repeat {
|
||||
rotate_vertices(msb(anglex), msb(angley), msb(anglez))
|
||||
cx16.GRAPH_clear()
|
||||
|
||||
cx16.GRAPH_set_colors(0, 0, 0)
|
||||
cx16.r0 = 32
|
||||
cx16.r1 = 10
|
||||
cx16.r2 = 256
|
||||
cx16.r3 = 185
|
||||
cx16.r4 = 0
|
||||
cx16.GRAPH_draw_rect(true)
|
||||
|
||||
cx16.GRAPH_set_colors(1, 0, 0)
|
||||
draw_lines()
|
||||
anglex-=500
|
||||
angley+=217
|
||||
anglez+=452
|
||||
|
||||
anglex -= 505
|
||||
angley += 217
|
||||
anglez += 452
|
||||
}
|
||||
}
|
||||
|
||||
sub print_ship_name() {
|
||||
cx16.r0 = 32
|
||||
cx16.r1 = 8
|
||||
ubyte c
|
||||
for c in "ship: "
|
||||
cx16.GRAPH_put_char(c)
|
||||
for c in shipdata.shipName
|
||||
cx16.GRAPH_put_char(c)
|
||||
|
||||
cx16.r0 += 16
|
||||
print_number_gfx(shipdata.totalNumberOfPoints)
|
||||
for c in " vertices, "
|
||||
cx16.GRAPH_put_char(c)
|
||||
print_number_gfx(shipdata.totalNumberOfEdges)
|
||||
for c in " edges, "
|
||||
cx16.GRAPH_put_char(c)
|
||||
print_number_gfx(shipdata.totalNumberOfFaces)
|
||||
for c in " faces"
|
||||
cx16.GRAPH_put_char(c)
|
||||
}
|
||||
|
||||
asmsub print_number_gfx(ubyte num @ A) clobbers(A,Y) {
|
||||
%asm {{
|
||||
phx
|
||||
jsr conv.ubyte2decimal
|
||||
stx P8ZP_SCRATCH_REG_X
|
||||
pha
|
||||
cpy #'0'
|
||||
beq +
|
||||
tya
|
||||
jsr cx16.GRAPH_put_char
|
||||
pla
|
||||
jsr cx16.GRAPH_put_char
|
||||
jmp _ones
|
||||
+ pla
|
||||
cmp #'0'
|
||||
beq _ones
|
||||
jsr cx16.GRAPH_put_char
|
||||
_ones lda P8ZP_SCRATCH_REG_X
|
||||
jsr cx16.GRAPH_put_char
|
||||
plx
|
||||
rts
|
||||
}}
|
||||
}
|
||||
|
||||
sub rotate_vertices(ubyte ax, ubyte ay, ubyte az) {
|
||||
; rotate around origin (0,0,0)
|
||||
|
||||
@ -68,11 +116,11 @@ main {
|
||||
word Azz = wcosb*wcosc / 128
|
||||
|
||||
ubyte @zp i
|
||||
for i in 0 to len(xcoor)-1 {
|
||||
for i in 0 to shipdata.totalNumberOfPoints-1 {
|
||||
; don't normalize by dividing by 128, instead keep some precision for perspective calc later
|
||||
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]
|
||||
rotatedx[i] = Axx*shipdata.xcoor[i] + Axy*shipdata.ycoor[i] + Axz*shipdata.zcoor[i]
|
||||
rotatedy[i] = Ayx*shipdata.xcoor[i] + Ayy*shipdata.ycoor[i] + Ayz*shipdata.zcoor[i]
|
||||
rotatedz[i] = Azx*shipdata.xcoor[i] + Azy*shipdata.ycoor[i] + Azz*shipdata.zcoor[i]
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,9 +129,9 @@ main {
|
||||
|
||||
sub draw_lines() {
|
||||
ubyte @zp i
|
||||
for i in len(edgesFrom) -1 downto 0 {
|
||||
ubyte @zp vFrom = edgesFrom[i]
|
||||
ubyte @zp vTo = edgesTo[i]
|
||||
for i in shipdata.totalNumberOfEdges -1 downto 0 {
|
||||
ubyte @zp vFrom = shipdata.edgesFrom[i]
|
||||
ubyte @zp vTo = shipdata.edgesTo[i]
|
||||
word persp1 = 200 + rotatedz[vFrom]/256
|
||||
word persp2 = 200 + rotatedz[vTo]/256
|
||||
cx16.r0 = rotatedx[vFrom] / persp1 + screen_width/2 as uword
|
||||
@ -94,3 +142,70 @@ main {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shipdata {
|
||||
|
||||
; Ship model data converted from BBC Elite's Cobra MK 3
|
||||
; downloaded from http://www.elitehomepage.org/archive/index.htm
|
||||
|
||||
const ubyte totalNumberOfEdges = 51
|
||||
const ubyte totalNumberOfFaces = 22
|
||||
const ubyte totalNumberOfPoints = 34
|
||||
str shipName = "cobra-mk3"
|
||||
; vertices
|
||||
word[] xcoor = [ 32,-32,0,-120,120,-88,88,128,-128,0,-32,32,-36,-8,8,36,36,8,-8,-36,-1,-1,-80,-80,-88,80,88,80,1,1,1,1,-1,-1 ]
|
||||
word[] ycoor = [ 0,0,26,-3,-3,16,16,-8,-8,26,-24,-24,8,12,12,8,-12,-16,-16,-12,-1,-1,-6,6,0,6,0,-6,-1,-1,1,1,1,1 ]
|
||||
word[] zcoor = [ 76,76,24,-8,-8,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,76,90,-40,-40,-40,-40,-40,-40,76,90,76,90,76,90 ]
|
||||
; edges and faces
|
||||
ubyte[] edgesFrom = [ 0,1,0,10,1,0,2,0,4,0,4,7,2,1,1,3,8,3,2,5,6,5,6,16,15,14,14,18,13,12,12,26,25,25,22,23,22,20,28,21,20,28,29,30,31,30,32,20,21,20,20 ]
|
||||
ubyte[] edgesTo = [ 1,2,2,11,10,11,6,6,6,4,7,11,5,5,3,5,10,8,9,9,9,8,7,17,16,15,17,19,18,13,19,27,26,27,23,24,24,28,29,29,21,30,31,31,33,32,33,32,33,33,29 ]
|
||||
ubyte[] facesPoints = [
|
||||
0,1,2 ,255,
|
||||
11,10,1,0 ,255,
|
||||
0,2,6 ,255,
|
||||
6,4,0 ,255,
|
||||
4,7,11,0 ,255,
|
||||
5,2,1 ,255,
|
||||
1,3,5 ,255,
|
||||
10,8,3,1 ,255,
|
||||
9,2,5 ,255,
|
||||
9,6,2 ,255,
|
||||
3,8,5 ,255,
|
||||
4,6,7 ,255,
|
||||
5,8,10,11,7,6,9 ,255,
|
||||
17,16,15,14 ,255,
|
||||
19,18,13,12 ,255,
|
||||
27,26,25 ,255,
|
||||
22,23,24 ,255,
|
||||
20,28,29,21 ,255,
|
||||
30,28,29,31 ,255,
|
||||
33,31,30,32 ,255,
|
||||
20,32,33,21 ,255,
|
||||
29,31,33,20 ,255
|
||||
]
|
||||
ubyte[] facesEdges = [
|
||||
0,1,2 ,255,
|
||||
3,4,0,5 ,255,
|
||||
2,6,7 ,255,
|
||||
8,9,7 ,255,
|
||||
10,11,5,9 ,255,
|
||||
12,1,13 ,255,
|
||||
14,15,13 ,255,
|
||||
16,17,14,4 ,255,
|
||||
18,12,19 ,255,
|
||||
20,6,18 ,255,
|
||||
17,21,15 ,255,
|
||||
8,22,10 ,255,
|
||||
21,16,3,11,22,20,19 ,255,
|
||||
23,24,25,26 ,255,
|
||||
27,28,29,30 ,255,
|
||||
31,32,33 ,255,
|
||||
34,35,36 ,255,
|
||||
37,38,39,40 ,255,
|
||||
41,38,42,43 ,255,
|
||||
44,43,45,46 ,255,
|
||||
47,46,48,40 ,255,
|
||||
42,44,49,50 ,255
|
||||
]
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user