From 18f5963b093ddefd48d3ac6608ae7b3ffbd438e4 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 10 Sep 2020 01:31:21 +0200 Subject: [PATCH] cobra mk3 --- .../cx16/{cube3d-gfx.p8 => cobramk3-gfx.p8} | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) rename examples/cx16/{cube3d-gfx.p8 => cobramk3-gfx.p8} (62%) diff --git a/examples/cx16/cube3d-gfx.p8 b/examples/cx16/cobramk3-gfx.p8 similarity index 62% rename from examples/cx16/cube3d-gfx.p8 rename to examples/cx16/cobramk3-gfx.p8 index b25fccaae..46f7d8845 100644 --- a/examples/cx16/cube3d-gfx.p8 +++ b/examples/cx16/cobramk3-gfx.p8 @@ -3,10 +3,13 @@ main { + ; Ship model data converted from BBC Elite's Cobra MK 3 + ; downloaded from http://www.elitehomepage.org/archive/index.htm + ; vertices - word[] xcoor = [ -100, -100, -100, -100, 100, 100, 100, 100 ] - word[] ycoor = [ -100, -100, 100, 100, -100, -100, 100, 100 ] - word[] zcoor = [ -100, 100, -100, 100, -100, 100, -100, 100 ] + 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 @@ -14,9 +17,11 @@ main { word[len(zcoor)] rotatedz ; edges - ubyte[] edgesFrom = [ 0, 2, 6, 4, 1, 3, 7, 5, 0, 2, 6, 4] - ubyte[] edgesTo = [ 2, 6, 4, 0, 3, 7, 5, 1, 1, 3, 7, 5] + 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 sub start() { uword anglex @@ -65,9 +70,9 @@ main { ubyte @zp i for i in 0 to len(xcoor)-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*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] } } @@ -79,8 +84,8 @@ main { for i in len(edgesFrom) -1 downto 0 { ubyte @zp vFrom = edgesFrom[i] ubyte @zp vTo = edgesTo[i] - word persp1 = 256 + rotatedz[vFrom]/256 - word persp2 = 256 + rotatedz[vTo]/256 + word persp1 = 200 + rotatedz[vFrom]/256 + word persp2 = 200 + rotatedz[vTo]/256 cx16.r0 = rotatedx[vFrom] / persp1 + screen_width/2 as uword cx16.r1 = rotatedy[vFrom] / persp1 + screen_height/2 as uword cx16.r2 = rotatedx[vTo] / persp2 + screen_width/2 as uword