I've been playing around with memblocks and meshes again and have come up with these.
The code uses a combination of making meshes from memblock and then simply adding limbs to make the final model.
Car
`this program makes a object
`by 29 games
`06 May 2010
sync on
sync rate 60
hide mouse
autocam off
set camera range 1, 3000
cls
gosub STARTING_VARIABLES:
`syntax: MAKE_OBJECT_CAR(object number, size)
MAKE_OBJECT_CAR(1,10)
`+++++ MAIN LOOP +++++++
do
gosub CONTROLS
gosub POSITION_CAMERA
gosub PRINT_STUFF
sync
loop
end
`+++++ SUB ROUTINES +++++++
STARTING_VARIABLES:
zoom = -30
theta = 150
alpha = 30
return
CONTROLS:
theta = wrapvalue(theta + mousemovex())
alpha = wrapvalue(alpha + mousemovey())
if mouseclick() = 1 then zoom = zoom + 3
if mouseclick() = 2 then zoom = zoom - 3
if zoom > -10 then zoom = -10
if spacekey() = 1 then gosub STARTING_VARIABLES
return
POSITION_CAMERA:
position camera 0,0,0
yrotate camera theta
xrotate camera alpha
move camera zoom
return
PRINT_STUFF:
set cursor 0,0
print "Move mouse to view object. LMB to zoom in. RMB to zoom out. Spacebar to reset view."
return
`+++++ FUNCTIONS +++++++
function MAKE_OBJECT_CAR(num,size)
dim p#(8,24)
num_mesh = 3
`write car body vertex data to array
i = 1
for j = i to 24
read p#(i,j)
p#(i,j) = p#(i,j)*size
next j
`create mesh for car body
MAKE_MESH_8_POINTS(i, p#(i,1),p#(i,2),p#(i,3), p#(i,4),p#(i,5),p#(i,6), p#(i,7),p#(i,8),p#(i,9), p#(i,10),p#(i,11),p#(i,12), p#(i,13),p#(i,14),p#(i,15), p#(i,16),p#(i,17),p#(i,18), p#(i,19),p#(i,20),p#(i,21), p#(i,22),p#(i,23),p#(i,24))
`make meshes for wheels
MAKE_CYLINDER_MESH(2,size*0.25) :`front
MAKE_CYLINDER_MESH(3,size*0.3) :`rear
`create object and add limbs
make object num,1,0
add limb num,1,2
add limb num,2,2
add limb num,3,3
add limb num,4,3
`delete meshes
for i = 1 to num_mesh
delete mesh i
next i
`rotate wheels to correct orientation
for i = 1 to 4
rotate limb num,i, 0,0,90
next i
`size and position wheels
scale limb num,1,100,100,100
offset limb num,1, 0.2*size,0.125*size,0.4*size
scale limb num,2,100,100,100
offset limb num,2, -0.2*size,0.125*size,0.4*size
scale limb num,3,120,100,120
offset limb num,3, 0.25*size,0.15*size,-0.4*size
scale limb num,4,120,100,120
offset limb num,4, -0.25*size,0.15*size,-0.4*size
`colour object
color object num,rgb(250,250,0)
set object ambient num,rgb(100,100,150)
set object specular num,rgb(100,100,100),1000
`colour wheels
for i = 1 to 4
color limb num, i, rgb(70,70,70)
next i
`data
_part_data:
data 0.20,0.15,0.25, -0.20,0.15,0.25, 0.05,0.3,0.40, -0.05,0.3,0.40, 0.30,0.18,-0.25, -0.30,0.18,-0.25, 0.15,0.50,-0.6, -0.15,0.50,-0.6
endfunction
function MAKE_MESH_8_POINTS(num, ax#,ay#,az#, bx#,by#,bz#, cx#,cy#,cz#, dx#,dy#,dz#, ex#,ey#,ez#, fx#,fy#,fz#, gx#,gy#,gz#, hx#,hy#,hz#)
`a = front right bottom, b = front left bottom, c = front right top, d = front left top
`e = back right bottom, f = back left bottom, g = back right top, h = back left top
`there are six sides to a box
num_sides = 6
`memblock number
mem = 1
`header values
num_verts = num_sides * 4
pos_verts = 32
num_norms = num_verts
pos_norms = num_verts*12 + pos_verts
num_faces = num_sides*2
pos_faces = pos_norms + num_norms*12
size_faces = num_faces*7
pos_uv = pos_faces + size_faces*4
`calculate size of memblock
size_mem = 32 + (num_verts + num_norms)*12 + size_faces*4 + num_sides*32
`create the memblock
make memblock mem, size_mem
`write header values to memblock
write memblock dword mem, 0, num_verts
write memblock dword mem, 4, pos_verts
write memblock dword mem, 8, num_norms
write memblock dword mem, 12, pos_norms
write memblock dword mem, 16, num_faces
write memblock dword mem, 20, pos_faces
write memblock dword mem, 24, size_faces
write memblock dword mem, 28, pos_uv
`write vertext data to memblock
`front face
write memblock float mem, 32, ax# : write memblock float mem, 36, ay# : write memblock float mem, 40, az# : `0 vertex
write memblock float mem, 44, bx# : write memblock float mem, 48, by# : write memblock float mem, 52, bz# : `1 vertex
write memblock float mem, 56, cx# : write memblock float mem, 60, cy# : write memblock float mem, 64, cz# : `2 vertex
write memblock float mem, 68, dx# : write memblock float mem, 72, dy# : write memblock float mem, 76, dz# : `3 vertex
`back face
write memblock float mem, 80, fx# : write memblock float mem, 84, fy# : write memblock float mem, 88, fz# : `4 vertex
write memblock float mem, 92, ex# : write memblock float mem, 96, ey# : write memblock float mem, 100, ez# : `5 vertex
write memblock float mem, 104, hx# : write memblock float mem, 108, hy# : write memblock float mem, 112, hz# : `6 vertex
write memblock float mem, 116, gx# : write memblock float mem, 120, gy# : write memblock float mem, 124, gz# : `7 vertex
`left face
write memblock float mem, 128, bx# : write memblock float mem, 132, by# : write memblock float mem, 136, bz# : `8 vertex
write memblock float mem, 140, fx# : write memblock float mem, 144, fy# : write memblock float mem, 148, fz# : `9 vertex
write memblock float mem, 152, dx# : write memblock float mem, 156, dy# : write memblock float mem, 160, dz# : `10 vertex
write memblock float mem, 164, hx# : write memblock float mem, 168, hy# : write memblock float mem, 172, hz# : `11 vertex
`right face
write memblock float mem, 176, ex# : write memblock float mem, 180, ey# : write memblock float mem, 184, ez# : `12 vertex
write memblock float mem, 188, ax# : write memblock float mem, 192, ay# : write memblock float mem, 196, az# : `13 vertex
write memblock float mem, 200, gx# : write memblock float mem, 204, gy# : write memblock float mem, 208, gz# : `14 vertex
write memblock float mem, 212, cx# : write memblock float mem, 216, cy# : write memblock float mem, 220, cz# : `15 vertex
`top face
write memblock float mem, 224, hx# : write memblock float mem, 228, hy# : write memblock float mem, 232, hz# : `16 vertex
write memblock float mem, 236, gx# : write memblock float mem, 240, gy# : write memblock float mem, 244, gz# : `17 vertex
write memblock float mem, 248, dx# : write memblock float mem, 252, dy# : write memblock float mem, 256, dz# : `18 vertex
write memblock float mem, 260, cx# : write memblock float mem, 264, cy# : write memblock float mem, 268, cz# : `19 vertex
`bottom face
write memblock float mem, 272, bx# : write memblock float mem, 276, by# : write memblock float mem, 280, bz# : `20 vertex
write memblock float mem, 284, ax# : write memblock float mem, 288, ay# : write memblock float mem, 292, az# : `21 vertex
write memblock float mem, 296, fx# : write memblock float mem, 300, fy# : write memblock float mem, 304, fz# : `22 vertex
write memblock float mem, 308, ex# : write memblock float mem, 312, ey# : write memblock float mem, 316, ez# : `23 vertex
`write normal data to memblock
restore _normdata
for pos = pos_norms to pos_norms+(num_norms*12)-12 step 12
read x,y,z
write memblock float mem, pos, x
write memblock float mem, pos+4, y
write memblock float mem, pos+8, z
next pos
`write face data to memblock
restore _facedata
for pos = pos_faces to pos_faces+(num_faces*28)-28 step 28
read nvf, va,na, vb, nb, vc,nc
write memblock dword mem, pos, nvf
write memblock dword mem, pos+4, va
write memblock dword mem, pos+8, na
write memblock dword mem, pos+12, vb
write memblock dword mem, pos+16, nb
write memblock dword mem, pos+20, vc
write memblock dword mem, pos+24, nc
next pos
`write UV data to memblock
restore _uvdata
for pos = pos_uv to pos_uv+(num_sides*32)-32 step 32
read ua#,va#, ub#,vb#, uc#,vc#, ud#,vd#
write memblock float mem, pos, ua#
write memblock float mem, pos+4, va#
write memblock float mem, pos+8, ub#
write memblock float mem, pos+12, vb#
write memblock float mem, pos+16, uc#
write memblock float mem, pos+20, vc#
write memblock float mem, pos+24, ud#
write memblock float mem, pos+28, vd#
next pos
`create mesh then create object, delete mesh and memblock
make mesh from memblock num, mem
delete memblock 1
_normdata:
data 0,0,1, 0,0,1, 0,0,1, 0,0,1 :`front
data 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1 :`back
data -1,0,0, -1,0,0, -1,0,0, -1,0,0 :`left
data 1,0,0, 1,0,0, 1,0,0, 1,0,0 :`right
data 0,1,0, 0,1,0, 0,1,0, 0,1,0 :`top
data 0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0 :`bottom
_facedata:
data 3, 0,0, 3,3, 1,1 :`front face 0
data 3, 3,3, 0,0, 2,2 :`front face 1
data 3, 4,4, 7,7, 5,5 :`back face 2
data 3, 7,7, 4,4, 6,6 :`back face 3
data 3, 8,8, 11,11, 9,9 :`left face 4
data 3, 11,11, 8,8, 10,10 :`left face 5
data 3, 12,12, 15,15, 13,13 :`right face 6
data 3, 15,15, 12,12, 14,14 :`right face 7
data 3, 16,16, 19,19, 17,17 :`top face 8
data 3, 19,19, 16,16, 18,18 :`top face 9
data 3, 20,20, 23,23, 21,21 :`bottom face 10
data 3, 23,23, 20,20, 22,22 :`bottom face 11
_uvdata:
data 0.03,0.47, 0.30,0.47, 0.03,0.03, 0.30,0.03 :`front
data 0.03,0.97, 0.30,0.97, 0.03,0.53, 0.30,0.53 :`back
data 0.36,0.47, 0.63,0.47, 0.36,0.03, 0.63,0.03 :`left
data 0.36,0.97, 0.63,0.97, 0.36,0.53, 0.63,0.53 :`right
data 0.69,0.47, 0.97,0.47, 0.69,0.03, 0.97,0.03 :`top
data 0.69,0.97, 0.97,0.97, 0.69,0.53, 0.97,0.53 :`bottom
endfunction
function MAKE_CYLINDER_MESH(num,size#)
make object cylinder 255,size#
make mesh from object num, 255
delete object 255
endfunction
Aeroplane / spaceship
`this program makes a flying vehicle object
`by 29 games
`06 May 2010
sync on
sync rate 60
hide mouse
autocam off
set camera range 1, 3000
cls
gosub STARTING_VARIABLES
`syntax: MAKE_OBJECT_FLYER(object number, size)
MAKE_OBJECT_FLYER(1,10)
`+++++ MAIN LOOP +++++++
do
gosub CONTROLS
gosub POSITION_CAMERA
gosub PRINT_STUFF
sync
loop
end
`+++++ SUB ROUTINES +++++++
STARTING_VARIABLES:
zoom = -30
theta = 160
alpha = 50
return
CONTROLS:
theta = wrapvalue(theta + mousemovex())
alpha = wrapvalue(alpha + mousemovey())
if mouseclick() = 1 then zoom = zoom + 3
if mouseclick() = 2 then zoom = zoom - 3
if zoom > -10 then zoom = -10
if spacekey() = 1 then gosub STARTING_VARIABLES
return
POSITION_CAMERA:
position camera 0,0,0
yrotate camera theta
xrotate camera alpha
move camera zoom
return
PRINT_STUFF:
set cursor 0,0
print "Move mouse to view object. LMB to zoom in. RMB to zoom out. Spacebar to reset view."
return
`+++++++ FUNCTIONS ++++++++++
function MAKE_OBJECT_FLYER(num,size)
dim p#(8,24)
num_mesh = 2
`write figure vertex data to array
restore _part_data
for i = 1 to num_mesh
for j = 1 to 24
read p#(i,j)
p#(i,j) = p#(i,j)*size
next j
next i
`create meshes for body parts
for i = 1 to num_mesh
MAKE_MESH_8_POINTS(i, p#(i,1),p#(i,2),p#(i,3), p#(i,4),p#(i,5),p#(i,6), p#(i,7),p#(i,8),p#(i,9), p#(i,10),p#(i,11),p#(i,12), p#(i,13),p#(i,14),p#(i,15), p#(i,16),p#(i,17),p#(i,18), p#(i,19),p#(i,20),p#(i,21), p#(i,22),p#(i,23),p#(i,24))
next i
`create object and add limbs
make object num,1,0
add limb num,1,2
add limb num,2,2
`delete meshes
for i = 1 to num_mesh
delete mesh i
next i
`add limbs
offset limb num,1, 0.2*size,0*size,-0.7*size
rotate limb num,1, 0,0,330
offset limb num,2, -0.2*size,0*size,-0.7*size
rotate limb num,2, 0,0,210
`colour object
color object 1,rgb(200,100,200)
set object ambient 1,rgb(100,100,150)
set object specular 1,rgb(100,100,100),1000
`data
_part_data:
`vertex data fusilarge
data 0.2,0.0,0.8, 0.0,-0.1,1.0, 0.0,0.1,0.6, -0.2,0.0,0.8, 0.2,0.0,-1.0, 0.0,-0.1,-0.8, 0.0,0.1,-0.8, -0.2,0.0,-1.0
`vertex data wings
data 1.0,-0.01,0.4, 0.0,-0.08,0.2, 1.0,0.01,0.4, 0.0,0.08,0.2, 1.0,-0.01,-0.0, 0.0,-0.08,-0.5, 1.0,0.01,-0.0, 0.0,0.08,-0.5
endfunction
function MAKE_MESH_8_POINTS(num, ax#,ay#,az#, bx#,by#,bz#, cx#,cy#,cz#, dx#,dy#,dz#, ex#,ey#,ez#, fx#,fy#,fz#, gx#,gy#,gz#, hx#,hy#,hz#)
`a = front right bottom, b = front left bottom, c = front right top, d = front left top
`e = back right bottom, f = back left bottom, g = back right top, h = back left top
`there are six sides to a box
num_sides = 6
`memblock number
mem = 1
`header values
num_verts = num_sides * 4
pos_verts = 32
num_norms = num_verts
pos_norms = num_verts*12 + pos_verts
num_faces = num_sides*2
pos_faces = pos_norms + num_norms*12
size_faces = num_faces*7
pos_uv = pos_faces + size_faces*4
`calculate size of memblock
size_mem = 32 + (num_verts + num_norms)*12 + size_faces*4 + num_sides*32
`create the memblock
make memblock mem, size_mem
`write header values to memblock
write memblock dword mem, 0, num_verts
write memblock dword mem, 4, pos_verts
write memblock dword mem, 8, num_norms
write memblock dword mem, 12, pos_norms
write memblock dword mem, 16, num_faces
write memblock dword mem, 20, pos_faces
write memblock dword mem, 24, size_faces
write memblock dword mem, 28, pos_uv
`write vertext data to memblock
`front face
write memblock float mem, 32, ax# : write memblock float mem, 36, ay# : write memblock float mem, 40, az# : `0 vertex
write memblock float mem, 44, bx# : write memblock float mem, 48, by# : write memblock float mem, 52, bz# : `1 vertex
write memblock float mem, 56, cx# : write memblock float mem, 60, cy# : write memblock float mem, 64, cz# : `2 vertex
write memblock float mem, 68, dx# : write memblock float mem, 72, dy# : write memblock float mem, 76, dz# : `3 vertex
`back face
write memblock float mem, 80, fx# : write memblock float mem, 84, fy# : write memblock float mem, 88, fz# : `4 vertex
write memblock float mem, 92, ex# : write memblock float mem, 96, ey# : write memblock float mem, 100, ez# : `5 vertex
write memblock float mem, 104, hx# : write memblock float mem, 108, hy# : write memblock float mem, 112, hz# : `6 vertex
write memblock float mem, 116, gx# : write memblock float mem, 120, gy# : write memblock float mem, 124, gz# : `7 vertex
`left face
write memblock float mem, 128, bx# : write memblock float mem, 132, by# : write memblock float mem, 136, bz# : `8 vertex
write memblock float mem, 140, fx# : write memblock float mem, 144, fy# : write memblock float mem, 148, fz# : `9 vertex
write memblock float mem, 152, dx# : write memblock float mem, 156, dy# : write memblock float mem, 160, dz# : `10 vertex
write memblock float mem, 164, hx# : write memblock float mem, 168, hy# : write memblock float mem, 172, hz# : `11 vertex
`right face
write memblock float mem, 176, ex# : write memblock float mem, 180, ey# : write memblock float mem, 184, ez# : `12 vertex
write memblock float mem, 188, ax# : write memblock float mem, 192, ay# : write memblock float mem, 196, az# : `13 vertex
write memblock float mem, 200, gx# : write memblock float mem, 204, gy# : write memblock float mem, 208, gz# : `14 vertex
write memblock float mem, 212, cx# : write memblock float mem, 216, cy# : write memblock float mem, 220, cz# : `15 vertex
`top face
write memblock float mem, 224, hx# : write memblock float mem, 228, hy# : write memblock float mem, 232, hz# : `16 vertex
write memblock float mem, 236, gx# : write memblock float mem, 240, gy# : write memblock float mem, 244, gz# : `17 vertex
write memblock float mem, 248, dx# : write memblock float mem, 252, dy# : write memblock float mem, 256, dz# : `18 vertex
write memblock float mem, 260, cx# : write memblock float mem, 264, cy# : write memblock float mem, 268, cz# : `19 vertex
`bottom face
write memblock float mem, 272, bx# : write memblock float mem, 276, by# : write memblock float mem, 280, bz# : `20 vertex
write memblock float mem, 284, ax# : write memblock float mem, 288, ay# : write memblock float mem, 292, az# : `21 vertex
write memblock float mem, 296, fx# : write memblock float mem, 300, fy# : write memblock float mem, 304, fz# : `22 vertex
write memblock float mem, 308, ex# : write memblock float mem, 312, ey# : write memblock float mem, 316, ez# : `23 vertex
`write normal data to memblock
restore _normdata
for pos = pos_norms to pos_norms+(num_norms*12)-12 step 12
read x,y,z
write memblock float mem, pos, x
write memblock float mem, pos+4, y
write memblock float mem, pos+8, z
next pos
`write face data to memblock
restore _facedata
for pos = pos_faces to pos_faces+(num_faces*28)-28 step 28
read nvf, va,na, vb, nb, vc,nc
write memblock dword mem, pos, nvf
write memblock dword mem, pos+4, va
write memblock dword mem, pos+8, na
write memblock dword mem, pos+12, vb
write memblock dword mem, pos+16, nb
write memblock dword mem, pos+20, vc
write memblock dword mem, pos+24, nc
next pos
`write UV data to memblock
restore _uvdata
for pos = pos_uv to pos_uv+(num_sides*32)-32 step 32
read ua#,va#, ub#,vb#, uc#,vc#, ud#,vd#
write memblock float mem, pos, ua#
write memblock float mem, pos+4, va#
write memblock float mem, pos+8, ub#
write memblock float mem, pos+12, vb#
write memblock float mem, pos+16, uc#
write memblock float mem, pos+20, vc#
write memblock float mem, pos+24, ud#
write memblock float mem, pos+28, vd#
next pos
`create mesh then create object, delete mesh and memblock
make mesh from memblock num, mem
delete memblock 1
_normdata:
data 0,0,1, 0,0,1, 0,0,1, 0,0,1 :`front
data 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1 :`back
data -1,0,0, -1,0,0, -1,0,0, -1,0,0 :`left
data 1,0,0, 1,0,0, 1,0,0, 1,0,0 :`right
data 0,1,0, 0,1,0, 0,1,0, 0,1,0 :`top
data 0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0 :`bottom
_facedata:
data 3, 0,0, 3,3, 1,1 :`front face 0
data 3, 3,3, 0,0, 2,2 :`front face 1
data 3, 4,4, 7,7, 5,5 :`back face 2
data 3, 7,7, 4,4, 6,6 :`back face 3
data 3, 8,8, 11,11, 9,9 :`left face 4
data 3, 11,11, 8,8, 10,10 :`left face 5
data 3, 12,12, 15,15, 13,13 :`right face 6
data 3, 15,15, 12,12, 14,14 :`right face 7
data 3, 16,16, 19,19, 17,17 :`top face 8
data 3, 19,19, 16,16, 18,18 :`top face 9
data 3, 20,20, 23,23, 21,21 :`bottom face 10
data 3, 23,23, 20,20, 22,22 :`bottom face 11
_uvdata:
data 0.03,0.47, 0.30,0.47, 0.03,0.03, 0.30,0.03 :`front
data 0.03,0.97, 0.30,0.97, 0.03,0.53, 0.30,0.53 :`back
data 0.36,0.47, 0.63,0.47, 0.36,0.03, 0.63,0.03 :`left
data 0.36,0.97, 0.63,0.97, 0.36,0.53, 0.63,0.53 :`right
data 0.69,0.47, 0.97,0.47, 0.69,0.03, 0.97,0.03 :`top
data 0.69,0.97, 0.97,0.97, 0.69,0.53, 0.97,0.53 :`bottom
endfunction
Tank
`this program makes a tank object
`by 29 games
`06 May 2010
sync on
sync rate 60
hide mouse
autocam off
set camera range 1, 3000
cls
gosub STARTING_VARIABLES:
`syntax MAKE_OBJECT_TANK(object number, size)
MAKE_OBJECT_TANK(1,10)
`+++++ MAIN LOOP +++++++
do
gosub CONTROLS
gosub POSITION_CAMERA
gosub PRINT_STUFF
sync
loop
end
`+++++ SUB ROUTINES +++++++
STARTING_VARIABLES:
zoom = -30
theta = 150
alpha = 30
turret_ang = 0
barrel_ang = 358
return
CONTROLS:
theta = wrapvalue(theta + mousemovex())
alpha = wrapvalue(alpha + mousemovey())
if mouseclick() = 1 then zoom = zoom + 3
if mouseclick() = 2 then zoom = zoom - 3
if zoom > -10 then zoom = -10
if spacekey() = 1 then gosub STARTING_VARIABLES
if leftkey() = 1 then turret_ang = wrapvalue(turret_ang - 1)
if rightkey() then turret_ang = wrapvalue(turret_ang + 1)
if upkey() = 1 then barrel_ang = wrapvalue(barrel_ang - 1) : if barrel_ang < 330 then barrel_ang = 330
if downkey() = 1 then barrel_ang = wrapvalue(barrel_ang + 1) : if barrel_ang > 358 then barrel_ang = 358
`rotate turret and barrel
rotate limb 1,1,0,turret_ang,0
rotate limb 1,2,barrel_ang,0,0
return
POSITION_CAMERA:
position camera 0,0,0
yrotate camera theta
xrotate camera alpha
move camera zoom
return
PRINT_STUFF:
set cursor 0,0
print "Move mouse to view object. LMB to zoom in. RMB to zoom out. Spacebar to reset view."
print "Left and right keys to rotate turret. Up and down keys to raise and lower barrel."
return
`+++++ FUNCTIONS +++++++
function MAKE_OBJECT_TANK(num,size)
dim p#(8,24)
num_mesh = 3
`write figure vertex data to array
restore _part_data
for i = 1 to num_mesh
for j = 1 to 24
read p#(i,j)
p#(i,j) = p#(i,j)*size
next j
next i
`create meshes for body parts
for i = 1 to num_mesh
MAKE_MESH_8_POINTS(i, p#(i,1),p#(i,2),p#(i,3), p#(i,4),p#(i,5),p#(i,6), p#(i,7),p#(i,8),p#(i,9), p#(i,10),p#(i,11),p#(i,12), p#(i,13),p#(i,14),p#(i,15), p#(i,16),p#(i,17),p#(i,18), p#(i,19),p#(i,20),p#(i,21), p#(i,22),p#(i,23),p#(i,24))
next i
`create object and add limbs
make object num,1,0
add limb num,1,2
add limb num,2,3
`delete meshes
for i = 1 to num_mesh
delete mesh i
next i
`add limbs
offset limb num,1, 0.0*size,0.15*size,-0.1*size
link limb num,2,1: offset limb num,2, 0.0*size,0.06*size,0.0*size
`colour object
color object num, rgb(100,230,100)
color limb num,1,rgb(90,250,90)
color limb num,2,rgb(100,240,100)
set object ambient num,rgb(50,50,50)
` set object specular num,rgb(150,0,150),100
set object emissive num,rgb(50,20,50)
`data
_part_data:
`vertex data body
data 0.30,0.0,0.5, -0.30,0.0,0.5, 0.25,0.15,0.4, -0.25,0.15,0.4, 0.30,0.0,-0.5, -0.30,0.0,-0.5, 0.25,0.15,-0.45, -0.25,0.15,-0.45
`vertex data turret
data 0.15,0.0,0.1, -0.15,0.0,0.1, 0.10,0.12,0.08, -0.10,0.12,0.08, 0.15,0.0,-0.25, -0.15,0.0,-0.25, 0.10,0.12,-0.15, -0.10,0.12,-0.15
`vertex data barrel
data 0.03,-0.03,0.5, -0.03,-0.03,0.5, 0.03,0.03,0.5, -0.03,0.03,0.5, 0.03,-0.03,0.0, -0.03,-0.03,0.0, 0.03,0.03,0.0, -0.03,0.03,0.0
endfunction
function MAKE_MESH_8_POINTS(num, ax#,ay#,az#, bx#,by#,bz#, cx#,cy#,cz#, dx#,dy#,dz#, ex#,ey#,ez#, fx#,fy#,fz#, gx#,gy#,gz#, hx#,hy#,hz#)
`a = right bottom front, b = left bottom front, c = right top front, d = left top front
`e = right bottom back, f = left bottom back, g = right top back, h = left top back
`there are six sides to a box
num_sides = 6
`memblock number
mem = 1
`header values
num_verts = num_sides * 4
pos_verts = 32
num_norms = num_verts
pos_norms = num_verts*12 + pos_verts
num_faces = num_sides*2
pos_faces = pos_norms + num_norms*12
size_faces = num_faces*7
pos_uv = pos_faces + size_faces*4
`calculate size of memblock
size_mem = 32 + (num_verts + num_norms)*12 + size_faces*4 + num_sides*32
`create the memblock
make memblock mem, size_mem
`write header values to memblock
write memblock dword mem, 0, num_verts
write memblock dword mem, 4, pos_verts
write memblock dword mem, 8, num_norms
write memblock dword mem, 12, pos_norms
write memblock dword mem, 16, num_faces
write memblock dword mem, 20, pos_faces
write memblock dword mem, 24, size_faces
write memblock dword mem, 28, pos_uv
`write vertext data to memblock
`front face
write memblock float mem, 32, ax# : write memblock float mem, 36, ay# : write memblock float mem, 40, az# : `0 vertex
write memblock float mem, 44, bx# : write memblock float mem, 48, by# : write memblock float mem, 52, bz# : `1 vertex
write memblock float mem, 56, cx# : write memblock float mem, 60, cy# : write memblock float mem, 64, cz# : `2 vertex
write memblock float mem, 68, dx# : write memblock float mem, 72, dy# : write memblock float mem, 76, dz# : `3 vertex
`back face
write memblock float mem, 80, fx# : write memblock float mem, 84, fy# : write memblock float mem, 88, fz# : `4 vertex
write memblock float mem, 92, ex# : write memblock float mem, 96, ey# : write memblock float mem, 100, ez# : `5 vertex
write memblock float mem, 104, hx# : write memblock float mem, 108, hy# : write memblock float mem, 112, hz# : `6 vertex
write memblock float mem, 116, gx# : write memblock float mem, 120, gy# : write memblock float mem, 124, gz# : `7 vertex
`left face
write memblock float mem, 128, bx# : write memblock float mem, 132, by# : write memblock float mem, 136, bz# : `8 vertex
write memblock float mem, 140, fx# : write memblock float mem, 144, fy# : write memblock float mem, 148, fz# : `9 vertex
write memblock float mem, 152, dx# : write memblock float mem, 156, dy# : write memblock float mem, 160, dz# : `10 vertex
write memblock float mem, 164, hx# : write memblock float mem, 168, hy# : write memblock float mem, 172, hz# : `11 vertex
`right face
write memblock float mem, 176, ex# : write memblock float mem, 180, ey# : write memblock float mem, 184, ez# : `12 vertex
write memblock float mem, 188, ax# : write memblock float mem, 192, ay# : write memblock float mem, 196, az# : `13 vertex
write memblock float mem, 200, gx# : write memblock float mem, 204, gy# : write memblock float mem, 208, gz# : `14 vertex
write memblock float mem, 212, cx# : write memblock float mem, 216, cy# : write memblock float mem, 220, cz# : `15 vertex
`top face
write memblock float mem, 224, hx# : write memblock float mem, 228, hy# : write memblock float mem, 232, hz# : `16 vertex
write memblock float mem, 236, gx# : write memblock float mem, 240, gy# : write memblock float mem, 244, gz# : `17 vertex
write memblock float mem, 248, dx# : write memblock float mem, 252, dy# : write memblock float mem, 256, dz# : `18 vertex
write memblock float mem, 260, cx# : write memblock float mem, 264, cy# : write memblock float mem, 268, cz# : `19 vertex
`bottom face
write memblock float mem, 272, bx# : write memblock float mem, 276, by# : write memblock float mem, 280, bz# : `20 vertex
write memblock float mem, 284, ax# : write memblock float mem, 288, ay# : write memblock float mem, 292, az# : `21 vertex
write memblock float mem, 296, fx# : write memblock float mem, 300, fy# : write memblock float mem, 304, fz# : `22 vertex
write memblock float mem, 308, ex# : write memblock float mem, 312, ey# : write memblock float mem, 316, ez# : `23 vertex
`write normal data to memblock
restore _normdata
for pos = pos_norms to pos_norms+(num_norms*12)-12 step 12
read x,y,z
write memblock float mem, pos, x
write memblock float mem, pos+4, y
write memblock float mem, pos+8, z
next pos
`write face data to memblock
restore _facedata
for pos = pos_faces to pos_faces+(num_faces*28)-28 step 28
read nvf, va,na, vb, nb, vc,nc
write memblock dword mem, pos, nvf
write memblock dword mem, pos+4, va
write memblock dword mem, pos+8, na
write memblock dword mem, pos+12, vb
write memblock dword mem, pos+16, nb
write memblock dword mem, pos+20, vc
write memblock dword mem, pos+24, nc
next pos
`write UV data to memblock
restore _uvdata
for pos = pos_uv to pos_uv+(num_sides*32)-32 step 32
read ua#,va#, ub#,vb#, uc#,vc#, ud#,vd#
write memblock float mem, pos, ua#
write memblock float mem, pos+4, va#
write memblock float mem, pos+8, ub#
write memblock float mem, pos+12, vb#
write memblock float mem, pos+16, uc#
write memblock float mem, pos+20, vc#
write memblock float mem, pos+24, ud#
write memblock float mem, pos+28, vd#
next pos
`create mesh then create object, delete mesh and memblock
make mesh from memblock num, mem
delete memblock 1
_normdata:
data 0,0,1, 0,0,1, 0,0,1, 0,0,1 :`front
data 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1 :`back
data -1,0,0, -1,0,0, -1,0,0, -1,0,0 :`left
data 1,0,0, 1,0,0, 1,0,0, 1,0,0 :`right
data 0,1,0, 0,1,0, 0,1,0, 0,1,0 :`top
data 0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0 :`bottom
_facedata:
data 3, 0,0, 3,3, 1,1 :`front face 0
data 3, 3,3, 0,0, 2,2 :`front face 1
data 3, 4,4, 7,7, 5,5 :`back face 2
data 3, 7,7, 4,4, 6,6 :`back face 3
data 3, 8,8, 11,11, 9,9 :`left face 4
data 3, 11,11, 8,8, 10,10 :`left face 5
data 3, 12,12, 15,15, 13,13 :`right face 6
data 3, 15,15, 12,12, 14,14 :`right face 7
data 3, 16,16, 19,19, 17,17 :`top face 8
data 3, 19,19, 16,16, 18,18 :`top face 9
data 3, 20,20, 23,23, 21,21 :`bottom face 10
data 3, 23,23, 20,20, 22,22 :`bottom face 11
_uvdata:
data 0.03,0.47, 0.30,0.47, 0.03,0.03, 0.30,0.03 :`front
data 0.03,0.97, 0.30,0.97, 0.03,0.53, 0.30,0.53 :`back
data 0.36,0.47, 0.63,0.47, 0.36,0.03, 0.63,0.03 :`left
data 0.36,0.97, 0.63,0.97, 0.36,0.53, 0.63,0.53 :`right
data 0.69,0.47, 0.97,0.47, 0.69,0.03, 0.97,0.03 :`top
data 0.69,0.97, 0.97,0.97, 0.69,0.53, 0.97,0.53 :`bottom
endfunction
I'll admit now that I've gone back to a brute force method to write all the vertex values to the memblock as I was getting bored with trying to make it more elegant.
I currently drawing a texture for the aeroplane and will post an image when I'm done.