I do not have DBP at work so I can't test this, but here is an theoretical example of your circle function in memblock format. There may be some errors in it but it shows the memblock's format.
[edit] Function corrected when I got home.
Though the UV mapping could be tweaked a bit.
[edit2] added normal cone function and cone with bottom
[edit3] Texture UV bug fixed (I forgot to make the test variable a float lol)
function LiT_Circ(obj, rad#, longitude)
`make array to store the x and z points on the circle
dim Point_hold#(longitude-1, 1)
`set angle value steps fpr each point
step_val# = 360.0/longitude
`set angle value placeholder
a# = 0.0
`calculate points
for i = 0 to longitude-1
`store z of current point
Point_hold#(i, 0) = sin(a#)*rad#
`store x of current point
Point_hold#(i, 1) = cos(a#)*rad#
inc a#, step_val#
next i
`make memblock to store mesh data
make memblock obj, 12+((longitude*3)*32)
`memblock format for meshs with fvf format 274 are as follows
`memblock dword position 0 = fvf format
`memblock dword position 4 = vert size in bytes (32)
`memblock dword position 8 = number of verts in mesh
`position 12 through the rest of the memblock are vert data
`for i = 1 to numpolys
`for j = 1 to 3 (3 verts per poly)
`memblock float vert x pos
`memblock float vert y pos
`memblock float vert z pos
`memblock float vert x normal
`memblock float vert y normal
`memblock float vert z normal
`memblock float vert U texture data
`memblock float vert V Texture data
`next j
`next i
`************************************************************
`write mesh data to memblock
write memblock dword obj, 0, 274
write memblock dword obj, 4, 32
write memblock dword obj, 8, (longitude*3)
`store poly number
a = 0
`store memblock position
b = 12
`write each poly
for i = 1 to longitude
`write each vert of each poly
for j = 1 to 3
`write first vert
if j = 1
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
`write second (clockwise) vert
if j = 2
offset = 1
if a + offset > longitude - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, 0
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
endif
`write center vert
if j = 3
`write vert x pos
write memblock float obj, b, 0
`write vert y pos
write memblock float obj, b+4, 0
`write vert z pos
write memblock float obj, b+8, 0
endif
`write vert x normal
write memblock float obj, b+12, 0
`write vert y normal
write memblock float obj, b+16, 1
`write vert z normal
write memblock float obj, b+20, 0
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((0-testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
endif
inc b, 32
next j
inc a, 1
next i
undim Point_hold#(0)
`make mesh from object for adding the limbs
make mesh from memblock obj, obj
delete memblock obj
`create base that will copy itself
make object obj, obj, 0
delete mesh obj
set object cull obj, 0
endfunction
`makes a normal cone with no bottom
function LiT_ConeNormal(obj, rad#, height#, longitude)
`make array to store the x and z points on the circle
dim Point_hold#(longitude-1, 1)
`set angle value steps fpr each point
step_val# = 360.0/longitude
`set angle value placeholder
a# = 0.0
`calculate points
for i = 0 to longitude-1
`store z of current point
Point_hold#(i, 0) = sin(a#)*rad#
`store x of current point
Point_hold#(i, 1) = cos(a#)*rad#
inc a#, step_val#
next i
`make memblock to store mesh data
make memblock obj, 12+((longitude*3)*32)
`memblock format for meshs with fvf format 274 are as follows
`memblock dword position 0 = fvf format
`memblock dword position 4 = vert size in bytes (32)
`memblock dword position 8 = number of verts in mesh
`position 12 through the rest of the memblock are vert data
`for i = 1 to numpolys
`for j = 1 to 3 (3 verts per poly)
`memblock float vert x pos
`memblock float vert y pos
`memblock float vert z pos
`memblock float vert x normal
`memblock float vert y normal
`memblock float vert z normal
`memblock float vert U texture data
`memblock float vert V Texture data
`next j
`next i
`************************************************************
`write mesh data to memblock
write memblock dword obj, 0, 274
write memblock dword obj, 4, 32
write memblock dword obj, 8, (longitude*3)
`store poly number
a = 0
`store memblock position
b = 12
`write each poly
for i = 1 to longitude
`write each vert of each poly
for j = 1 to 3
`write first vert
if j = 1
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
`write second (clockwise) vert
if j = 2
offset = 1
if a + offset > longitude - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
endif
`write center vert
if j = 3
`write vert x pos
write memblock float obj, b, 0
`write vert y pos
write memblock float obj, b+4, height#/2
`write vert z pos
write memblock float obj, b+8, 0
endif
`write vert x normal
write memblock float obj, b+12, 0
`write vert y normal
write memblock float obj, b+16, 1
`write vert z normal
write memblock float obj, b+20, 0
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((0-testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
`calc normals for polys
`Thanks to ADR for posting this code on the DBP forums :)
`acuire vert positions
P1X# = memblock float(obj, (b-64))
P1Y# = memblock float(obj, (b-60))
P1Z# = memblock float(obj, (b-56))
P2X# = memblock float(obj, (b-32))
P2Y# = memblock float(obj, (b-28))
P2Z# = memblock float(obj, (b-24))
P3X# = memblock float(obj, (b))
P3Y# = memblock float(obj, (b+4))
P3Z# = memblock float(obj, (b+8))
null = make vector3(1)
null = make vector3(2)
null = make vector3(3)
` -- calculate the two directional vectors for the adj and opp edges...
set vector3 1, P1X#, P1Y#, P1Z#
set vector3 2, P2X#, P2Y#, P2Z#
set vector3 3, P3X#, P3Y#, P3Z#
subtract vector3 2, 2, 1
subtract vector3 3, 3, 1 ` -- vector 3 and 1 are now directional vectors
normalize vector3 2,2 ` -- normalize em
normalize vector3 3,3
cross product vector3 1, 2,3 ` -- use the origin vector (1) to store the face normal
normalize vector3 1,1
`save normals (all 3 verts have same normals)
xnorm# = x vector3(1)
ynorm# = y vector3(1)
znorm# = z vector3(1)
write memblock float obj, (b-52), xnorm#
write memblock float obj, (b-48), ynorm#
write memblock float obj, (b-44), znorm#
write memblock float obj, (b-20), xnorm#
write memblock float obj, (b-16), ynorm#
write memblock float obj, (b-12), znorm#
write memblock float obj, (b+12), xnorm#
write memblock float obj, (b+16), ynorm#
write memblock float obj, (b+20), znorm#
null = delete vector3(1)
null = delete vector3(2)
null = delete vector3(3)
endif
inc b, 32
next j
inc a, 1
next i
undim Point_hold#(0)
`make mesh from object for adding the limbs
make mesh from memblock obj, obj
delete memblock obj
`create base that will copy itself
make object obj, obj, 0
delete mesh obj
set object cull obj, 0
endfunction
`makes cone with bottom
function LiT_Cone(obj, rad#, height#, longitude)
`make array to store the x and z points on the circle
dim Point_hold#(longitude-1, 1)
`set angle value steps fpr each point
step_val# = 360.0/longitude
`set angle value placeholder
a# = 0.0
`calculate points
for i = 0 to longitude-1
`store z of current point
Point_hold#(i, 0) = sin(a#)*rad#
`store x of current point
Point_hold#(i, 1) = cos(a#)*rad#
inc a#, step_val#
next i
`make memblock to store mesh data
make memblock obj, 12+(((longitude*3)*32)*2)
`memblock format for meshs with fvf format 274 are as follows
`memblock dword position 0 = fvf format
`memblock dword position 4 = vert size in bytes (32)
`memblock dword position 8 = number of verts in mesh
`position 12 through the rest of the memblock are vert data
`for i = 1 to numpolys
`for j = 1 to 3 (3 verts per poly)
`memblock float vert x pos
`memblock float vert y pos
`memblock float vert z pos
`memblock float vert x normal
`memblock float vert y normal
`memblock float vert z normal
`memblock float vert U texture data
`memblock float vert V Texture data
`next j
`next i
`************************************************************
`write mesh data to memblock
write memblock dword obj, 0, 274
write memblock dword obj, 4, 32
write memblock dword obj, 8, (longitude*3)*2
`store poly number
a = 0
`store memblock position
b = 12
`write each poly
for i = 1 to longitude
`write each vert of each poly
for j = 1 to 3
`write first vert
if j = 1
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
`write second (clockwise) vert
if j = 2
offset = 1
if a + offset > longitude - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
endif
`write center vert
if j = 3
`write vert x pos
write memblock float obj, b, 0
`write vert y pos
write memblock float obj, b+4, height#/2
`write vert z pos
write memblock float obj, b+8, 0
endif
`write vert x normal
write memblock float obj, b+12, 0
`write vert y normal
write memblock float obj, b+16, 1
`write vert z normal
write memblock float obj, b+20, 0
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((0-testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
`calc normals for polys
`Thanks to ADR for posting this code on the DBP forums :)
`acuire vert positions
P1X# = memblock float(obj, (b-64))
P1Y# = memblock float(obj, (b-60))
P1Z# = memblock float(obj, (b-56))
P2X# = memblock float(obj, (b-32))
P2Y# = memblock float(obj, (b-28))
P2Z# = memblock float(obj, (b-24))
P3X# = memblock float(obj, (b))
P3Y# = memblock float(obj, (b+4))
P3Z# = memblock float(obj, (b+8))
null = make vector3(1)
null = make vector3(2)
null = make vector3(3)
` -- calculate the two directional vectors for the adj and opp edges...
set vector3 1, P1X#, P1Y#, P1Z#
set vector3 2, P2X#, P2Y#, P2Z#
set vector3 3, P3X#, P3Y#, P3Z#
subtract vector3 2, 2, 1
subtract vector3 3, 3, 1 ` -- vector 3 and 1 are now directional vectors
normalize vector3 2,2 ` -- normalize em
normalize vector3 3,3
cross product vector3 1, 2,3 ` -- use the origin vector (1) to store the face normal
normalize vector3 1,1
`save normals (all 3 verts have same normals)
xnorm# = x vector3(1)
ynorm# = y vector3(1)
znorm# = z vector3(1)
write memblock float obj, (b-52), xnorm#
write memblock float obj, (b-48), ynorm#
write memblock float obj, (b-44), znorm#
write memblock float obj, (b-20), xnorm#
write memblock float obj, (b-16), ynorm#
write memblock float obj, (b-12), znorm#
write memblock float obj, (b+12), xnorm#
write memblock float obj, (b+16), ynorm#
write memblock float obj, (b+20), znorm#
null = delete vector3(1)
null = delete vector3(2)
null = delete vector3(3)
endif
inc b, 32
next j
inc a, 1
next i
a = 0
`write each poly
for i = 1 to longitude
`write each vert of each poly
for j = 1 to 3
`write first vert
if j = 1
offset = 1
if a + offset > longitude - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
endif
`write second (clockwise) vert
if j = 2
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
`write center vert
if j = 3
`write vert x pos
write memblock float obj, b, 0
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, 0
endif
`write vert x normal
write memblock float obj, b+12, 0
`write vert y normal
write memblock float obj, b+16, -1
`write vert z normal
write memblock float obj, b+20, 0
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
endif
inc b, 32
next j
inc a, 1
next i
undim Point_hold#(0)
`make mesh from object for adding the limbs
make mesh from memblock obj, obj
delete memblock obj
`create base that will copy itself
make object obj, obj, 0
delete mesh obj
set object cull obj, 1
endfunction
[edit4] Here are some experimental function with slight changes plus a theoretical cylinder and cylinder with ends code. Will test and correct if they don't work when I get home.
[edit5] Fixed codes to work properly. I will try and optimize them when I get time.
function LiT_Circ(obj, rad#, numpolys)
`the actual number of polys is numpolys
`make array to store the x and z points on the circle
dim Point_hold#(numpolys-1, 1)
`set angle value steps fpr each point
step_val# = 360.0/numpolys
`set angle value placeholder
a# = 0.0
`calculate points
for i = 0 to numpolys-1
`store z of current point
Point_hold#(i, 0) = sin(a#)*rad#
`store x of current point
Point_hold#(i, 1) = cos(a#)*rad#
inc a#, step_val#
next i
`make memblock to store mesh data
make memblock obj, 12+((numpolys*3)*32)
`write mesh data to memblock
write memblock dword obj, 0, 274
write memblock dword obj, 4, 32
write memblock dword obj, 8, (numpolys*3)
`store poly number
a = 0
`store memblock position
b = 12
`write each poly
for i = 1 to numpolys
`write each vert of each poly
for j = 1 to 3
if j = 2
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
else
offset = 0
endif
if j = 3
tempx_pos# = 0.0
tempz_pos# = 0.0
else
tempx_pos# = Point_hold#(a+offset, 0)
tempz_pos# = Point_hold#(a+offset, 1)
endif
`write vert x pos
write memblock float obj, b, tempx_pos#
`write vert y pos
write memblock float obj, b+4, 0
`write vert z pos
write memblock float obj, b+8, tempz_pos#
`write vert x normal
write memblock float obj, b+12, 0
`write vert y normal
write memblock float obj, b+16, 1
`write vert z normal
write memblock float obj, b+20, 0
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((0-testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
endif
inc b, 32
next j
inc a, 1
next i
undim Point_hold#(0)
`make mesh from memblock
make mesh from memblock obj, obj
delete memblock obj
`make object from mesh
make object obj, obj, 0
delete mesh obj
set object cull obj, 0
endfunction
`makes a normal cone with no bottom
function LiT_ConeNormal(obj, rad#, height#, numpolys)
`the actual number of polys is numpolys
`make array to store the x and z points on the circle
dim Point_hold#(numpolys-1, 1)
`set angle value steps fpr each point
step_val# = 360.0/numpolys
`set angle value placeholder
a# = 0.0
`calculate points
for i = 0 to numpolys-1
`store z of current point
Point_hold#(i, 0) = sin(a#)*rad#
`store x of current point
Point_hold#(i, 1) = cos(a#)*rad#
inc a#, step_val#
next i
`make memblock to store mesh data
make memblock obj, 12+((numpolys*3)*32)
`write mesh data to memblock
write memblock dword obj, 0, 274
write memblock dword obj, 4, 32
write memblock dword obj, 8, (numpolys*3)
`store poly number
a = 0
`store memblock position
b = 12
`write each poly
for i = 1 to numpolys
`write each vert of each poly
for j = 1 to 3
`write first vert
if j = 1
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
`write second (clockwise) vert
if j = 2
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
endif
`write center vert
if j = 3
`write vert x pos
write memblock float obj, b, 0
`write vert y pos
write memblock float obj, b+4, height#/2
`write vert z pos
write memblock float obj, b+8, 0
endif
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((0-testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
`calc normals for polys
`Thanks to ADR for posting this code on the DBP forums :)
`acuire vert positions
P1X# = memblock float(obj, (b-64))
P1Y# = memblock float(obj, (b-60))
P1Z# = memblock float(obj, (b-56))
P2X# = memblock float(obj, (b-32))
P2Y# = memblock float(obj, (b-28))
P2Z# = memblock float(obj, (b-24))
P3X# = memblock float(obj, (b))
P3Y# = memblock float(obj, (b+4))
P3Z# = memblock float(obj, (b+8))
xnorm# = Calc_Normal(1,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
ynorm# = Calc_Normal(2,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
znorm# = Calc_Normal(3,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
write memblock float obj, (b-52), xnorm#
write memblock float obj, (b-48), ynorm#
write memblock float obj, (b-44), znorm#
write memblock float obj, (b-20), xnorm#
write memblock float obj, (b-16), ynorm#
write memblock float obj, (b-12), znorm#
write memblock float obj, (b+12), xnorm#
write memblock float obj, (b+16), ynorm#
write memblock float obj, (b+20), znorm#
endif
inc b, 32
next j
inc a, 1
next i
undim Point_hold#(0)
`make mesh from memblock
make mesh from memblock obj, obj
delete memblock obj
`make object from mesh
make object obj, obj, 0
delete mesh obj
set object cull obj, 0
endfunction
`makes cone with bottom
function LiT_Cone(obj, rad#, height#, numpolys)
`the actual number of polys is numpolys*2
`make array to store the x and z points on the circle
dim Point_hold#(numpolys-1, 1)
`set angle value steps fpr each point
step_val# = 360.0/numpolys
`set angle value placeholder
a# = 0.0
`calculate points
for i = 0 to numpolys-1
`store z of current point
Point_hold#(i, 0) = sin(a#)*rad#
`store x of current point
Point_hold#(i, 1) = cos(a#)*rad#
inc a#, step_val#
next i
`make memblock to store mesh data
make memblock obj, 12+(((numpolys*3)*32)*2)
`write mesh data to memblock
write memblock dword obj, 0, 274
write memblock dword obj, 4, 32
write memblock dword obj, 8, (numpolys*3)*2
`store poly number
a = 0
`store memblock position
b = 12
`write each poly
for i = 1 to numpolys
`write each vert of each poly
for j = 1 to 3
`write first vert
if j = 1
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
`write second (clockwise) vert
if j = 2
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
endif
`write center vert
if j = 3
`write vert x pos
write memblock float obj, b, 0
`write vert y pos
write memblock float obj, b+4, height#/2
`write vert z pos
write memblock float obj, b+8, 0
endif
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((0-testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
`calc normals for polys
`Thanks to ADR for posting this code on the DBP forums :)
`acuire vert positions
P1X# = memblock float(obj, (b-64))
P1Y# = memblock float(obj, (b-60))
P1Z# = memblock float(obj, (b-56))
P2X# = memblock float(obj, (b-32))
P2Y# = memblock float(obj, (b-28))
P2Z# = memblock float(obj, (b-24))
P3X# = memblock float(obj, (b))
P3Y# = memblock float(obj, (b+4))
P3Z# = memblock float(obj, (b+8))
xnorm# = Calc_Normal(1,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
ynorm# = Calc_Normal(2,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
znorm# = Calc_Normal(3,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
write memblock float obj, (b-52), xnorm#
write memblock float obj, (b-48), ynorm#
write memblock float obj, (b-44), znorm#
write memblock float obj, (b-20), xnorm#
write memblock float obj, (b-16), ynorm#
write memblock float obj, (b-12), znorm#
write memblock float obj, (b+12), xnorm#
write memblock float obj, (b+16), ynorm#
write memblock float obj, (b+20), znorm#
endif
inc b, 32
next j
inc a, 1
next i
a = 0
`write each poly
for i = 1 to numpolys
`write each vert of each poly
for j = 1 to 3
`write first vert
if j = 1
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
endif
`write second (clockwise) vert
if j = 2
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
`write center vert
if j = 3
`write vert x pos
write memblock float obj, b, 0
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, 0
endif
`write vert x normal
write memblock float obj, b+12, 0
`write vert y normal
write memblock float obj, b+16, -1
`write vert z normal
write memblock float obj, b+20, 0
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
endif
inc b, 32
next j
inc a, 1
next i
undim Point_hold#(0)
`make mesh from memblock
make mesh from memblock obj, obj
delete memblock obj
`make object from mesh
make object obj, obj, 0
delete mesh obj
set object cull obj, 1
endfunction
`makes a normal cylinder with ends
function LiT_Cylinder(obj, rad#, height#, numpolys)
`the actual number of polys is numpolys*2
`make array to store the x and z points on the circle
dim Point_hold#(numpolys-1, 1)
`set angle value steps fpr each point
step_val# = 360.0/numpolys
`set angle value placeholder
a# = 0
`set array placeholder
b = 0
`calculate points
for i = 0 to numpolys-1
`store z of current point
Point_hold#(b, 0) = sin(a#)*rad#
`store x of current point
Point_hold#(b, 1) = cos(a#)*rad#
inc a#, step_val#
dec b, 1
if b < 0 then b = numpolys-1
next i
`calc U step value
U_Step# = 1.0/numpolys
`make memblock to store mesh data
make memblock obj, 12+(((numpolys*3)*32)*4)
`write mesh data to memblock
write memblock dword obj, 0, 274
write memblock dword obj, 4, 32
write memblock dword obj, 8, (numpolys*3)*4
`********************************************************************
`write side walls
`store poly number
a = 0
`store memblock position
b = 12
Base_U# = 0.0
`write each poly
for i = 1 to numpolys
for k = 1 to 2
`write each vert of each poly
for j = 1 to 3
if k = 1
if j = 2
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, height#/2
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
`write vert U data
write memblock float obj, b+24, Base_U# + U_Step#
`write vert V data
write memblock float obj, b+28, 0.0
else
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
if j = 1
write memblock float obj, b+4, height#/2
`write vert U data
write memblock float obj, b+24, Base_U#
`write vert V data
write memblock float obj, b+28, 0.0
else
write memblock float obj, b+4, 0-(height#/2)
`write vert U data
write memblock float obj, b+24, Base_U#
`write vert V data
write memblock float obj, b+28, 1.0
endif
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
else
if j > 1
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
if j = 2
write memblock float obj, b+4, height#/2
`write vert V data
write memblock float obj, b+28, 0.0
else
write memblock float obj, b+4, 0-(height#/2)
`write vert V data
write memblock float obj, b+28, 1.0
endif
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
`write vert U data
write memblock float obj, b+24, Base_U# + U_Step#
else
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
`write vert U data
write memblock float obj, b+24, Base_U#
`write vert U data
write memblock float obj, b+28, 1.0
endif
endif
if j = 3
`calc normals for polys
`Thanks to ADR for posting this code on the DBP forums :)
`acuire vert positions
P1X# = memblock float(obj, (b-64))
P1Y# = memblock float(obj, (b-60))
P1Z# = memblock float(obj, (b-56))
P2X# = memblock float(obj, (b-32))
P2Y# = memblock float(obj, (b-28))
P2Z# = memblock float(obj, (b-24))
P3X# = memblock float(obj, (b))
P3Y# = memblock float(obj, (b+4))
P3Z# = memblock float(obj, (b+8))
xnorm# = Calc_Normal(1,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
ynorm# = Calc_Normal(2,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
znorm# = Calc_Normal(3,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
write memblock float obj, (b-52), xnorm#
write memblock float obj, (b-48), ynorm#
write memblock float obj, (b-44), znorm#
write memblock float obj, (b-20), xnorm#
write memblock float obj, (b-16), ynorm#
write memblock float obj, (b-12), znorm#
write memblock float obj, (b+12), xnorm#
write memblock float obj, (b+16), ynorm#
write memblock float obj, (b+20), znorm#
endif
inc b, 32
next j
next k
inc a, 1
inc Base_U#, U_Step#
next i
`********************************************************************
`write top face
`store poly number
a = 0
`write each poly
for i = 1 to numpolys
`write each vert of each poly
for j = 1 to 3
if j = 1
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
else
offset = 0
endif
if j = 3
tempx_pos# = 0.0
tempz_pos# = 0.0
else
tempx_pos# = Point_hold#(a+offset, 0)
tempz_pos# = Point_hold#(a+offset, 1)
endif
`write vert x pos
write memblock float obj, b, tempx_pos#
`write vert y pos
write memblock float obj, b+4, height#/2
`write vert z pos
write memblock float obj, b+8, tempz_pos#
`write vert x normal
write memblock float obj, b+12, 0
`write vert y normal
write memblock float obj, b+16, 1
`write vert z normal
write memblock float obj, b+20, 0
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((0-testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
endif
inc b, 32
next j
inc a, 1
next i
`********************************************************************
`write bottom face
a = 0
`write each poly
for i = 1 to numpolys
`write each vert of each poly
for j = 1 to 3
`write first vert
if j = 2
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
endif
`write second (clockwise) vert
if j = 1
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
`write center vert
if j = 3
`write vert x pos
write memblock float obj, b, 0
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, 0
endif
`write vert x normal
write memblock float obj, b+12, 0
`write vert y normal
write memblock float obj, b+16, -1
`write vert z normal
write memblock float obj, b+20, 0
if j < 3
testval# = memblock float (obj, b)
`write vert U data
write memblock float obj, b+24, (0.5*(testval#/rad#))+0.5
testval# = memblock float (obj, b+8)
`write vert V data
write memblock float obj, b+28, (0.5*((testval#)/rad#))+0.5
else
`write vert U data
write memblock float obj, b+24, 0.5
`write vert V data
write memblock float obj, b+28, 0.5
endif
inc b, 32
next j
inc a, 1
next i
undim Point_hold#(0)
`make mesh from memblock
make mesh from memblock obj, obj
delete memblock obj
`make object from mesh
make object obj, obj, 0
delete mesh obj
set object cull obj, 1
endfunction
`makes a normal cylinder with no ends
function LiT_CylinderNormal(obj, rad#, height#, numpolys)
`the actual number of polys is numpolys*2
`make array to store the x and z points on the circle
dim Point_hold#(numpolys-1, 1)
`set angle value steps fpr each point
step_val# = 360.0/numpolys
`set angle value placeholder
a# = 0
`set array placeholder
b = 0
`calculate points
for i = 0 to numpolys-1
`store z of current point
Point_hold#(b, 0) = sin(a#)*rad#
`store x of current point
Point_hold#(b, 1) = cos(a#)*rad#
inc a#, step_val#
dec b, 1
if b < 0 then b = numpolys-1
next i
`calc U step value
U_Step# = 1.0/numpolys
`make memblock to store mesh data
make memblock obj, 12+(((numpolys*3)*32)*2)
`write mesh data to memblock
write memblock dword obj, 0, 274
write memblock dword obj, 4, 32
write memblock dword obj, 8, (numpolys*3)*2
`store poly number
a = 0
`store memblock position
b = 12
Base_U# = 0.0
`write each poly
for i = 1 to numpolys
for k = 1 to 2
`write each vert of each poly
for j = 1 to 3
if k = 1
if j = 2
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
write memblock float obj, b+4, height#/2
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
`write vert U data
write memblock float obj, b+24, Base_U# + U_Step#
`write vert V data
write memblock float obj, b+28, 0.0
else
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
if j = 1
write memblock float obj, b+4, height#/2
`write vert U data
write memblock float obj, b+24, Base_U#
`write vert V data
write memblock float obj, b+28, 0.0
else
write memblock float obj, b+4, 0-(height#/2)
`write vert U data
write memblock float obj, b+24, Base_U#
`write vert V data
write memblock float obj, b+28, 1.0
endif
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
endif
else
if j > 1
offset = 1
if a + offset > numpolys - 1
offset = 0-a
endif
`write vert x pos
write memblock float obj, b, Point_hold#(a+offset, 0)
`write vert y pos
if j = 2
write memblock float obj, b+4, height#/2
`write vert V data
write memblock float obj, b+28, 0.0
else
write memblock float obj, b+4, 0-(height#/2)
`write vert V data
write memblock float obj, b+28, 1.0
endif
`write vert z pos
write memblock float obj, b+8, Point_hold#(a+offset, 1)
`write vert U data
write memblock float obj, b+24, Base_U# + U_Step#
else
`write vert x pos
write memblock float obj, b, Point_hold#(a, 0)
`write vert y pos
write memblock float obj, b+4, 0-(height#/2)
`write vert z pos
write memblock float obj, b+8, Point_hold#(a, 1)
`write vert U data
write memblock float obj, b+24, Base_U#
`write vert U data
write memblock float obj, b+28, 1.0
endif
endif
if j = 3
`calc normals for polys
`Thanks to ADR for posting this code on the DBP forums :)
`acuire vert positions
P1X# = memblock float(obj, (b-64))
P1Y# = memblock float(obj, (b-60))
P1Z# = memblock float(obj, (b-56))
P2X# = memblock float(obj, (b-32))
P2Y# = memblock float(obj, (b-28))
P2Z# = memblock float(obj, (b-24))
P3X# = memblock float(obj, (b))
P3Y# = memblock float(obj, (b+4))
P3Z# = memblock float(obj, (b+8))
xnorm# = Calc_Normal(1,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
ynorm# = Calc_Normal(2,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
znorm# = Calc_Normal(3,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
write memblock float obj, (b-52), xnorm#
write memblock float obj, (b-48), ynorm#
write memblock float obj, (b-44), znorm#
write memblock float obj, (b-20), xnorm#
write memblock float obj, (b-16), ynorm#
write memblock float obj, (b-12), znorm#
write memblock float obj, (b+12), xnorm#
write memblock float obj, (b+16), ynorm#
write memblock float obj, (b+20), znorm#
endif
inc b, 32
next j
next k
inc a, 1
inc Base_U#, U_Step#
next i
undim Point_hold#(0)
`make mesh from memblock
make mesh from memblock obj, obj
delete memblock obj
`make object from mesh
make object obj, obj, 0
delete mesh obj
set object cull obj, 0
endfunction
Function Calc_Normal(axis,P1X#,P1Y#,P1Z#,P2X#,P2Y#,P2Z#,P3X#,P3Y#,P3Z#)
`axis 1 is x, 2 = y, 3 is z
null = make vector3(1)
null = make vector3(2)
null = make vector3(3)
` -- calculate the two directional vectors for the adj and opp edges...
set vector3 1, P1X#, P1Y#, P1Z#
set vector3 2, P2X#, P2Y#, P2Z#
set vector3 3, P3X#, P3Y#, P3Z#
subtract vector3 2, 2, 1
subtract vector3 3, 3, 1 ` -- vector 3 and 1 are now directional vectors
normalize vector3 2,2 ` -- normalize em
normalize vector3 3,3
cross product vector3 1, 2,3 ` -- use the origin vector (1) to store the face normal
normalize vector3 1,1
`save normals (all 3 verts have same normals)
select axis
case 2 : result# = y vector3(1) : endcase
case 3 : result# = z vector3(1) : endcase
case default : result# = x vector3(1) : endcase
endselect
null = delete vector3(1)
null = delete vector3(2)
null = delete vector3(3)
endfunction result#
Set object smooting makes a world of difference. Both of these have the same number of polys but the one on the right looks much smoother.