Makes a UV-mapped disc with the size and amount of polygons you specify.
` Constants -----------------------------------------
#constant TEMPORARY_MEMBLOCK_NUM 256
#constant TEMPORARY_MESH_NUM 1000
` ---------------------------------------------------
MakeObjectDisc(1, 100.0, 15) ` Object number, size, amount of tris
if file exist("texture.png")
load image "texture.png", 1
texture object 1, 1
endif
sync on
sync rate 60
do
turn object right 1, 1
sync
loop
function MakeObjectDisc(objectNum as integer, size as float, numberOfTris as dword)
local radius as float : radius = size / 2.0
local numberOfVerts as dword : numberOfVerts = numberOfTris * 3
local fvf as dword : fvf = 0x152 ` XYZ, normal, diffuse, tex
local stepValue as float : stepValue = 360.0 / numberOfTris
local fvfSize as dword : fvfSize = 36
local polySize as dword
local memblockSize as dword
local quo as float : quo = 1.0 / size
local xCoord as float
local yCoord as float
local memblockPos as dword
` Other calculations
polySize = fvfSize * 3
memblockSize = numberOfVerts * fvfSize + 12
make memblock TEMPORARY_MEMBLOCK_NUM, memblockSize
fill memory get memblock ptr(TEMPORARY_MEMBLOCK_NUM), 0, memblockSize
` Set header information
write memblock dword TEMPORARY_MEMBLOCK_NUM, 0, fvf
write memblock dword TEMPORARY_MEMBLOCK_NUM, 4, fvfSize
write memblock dword TEMPORARY_MEMBLOCK_NUM, 8, numberOfVerts
` For each polygon
for x = 0 to numberOfTris-1
` Vertex 1
xCoord = cos(x*stepValue) * radius
yCoord = sin(x*stepValue) * radius
memblockPos = x * (polySize) + 12
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos, xCoord
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos+4, yCoord
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos+28, xCoord * quo + 0.5
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos+32, 0.5 - yCoord * quo
` Vertex 2
inc memblockPos, fvfSize
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos+28, 0.5
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos+32, 0.5
` Vertex 3
xCoord = cos((x+1)*stepValue) * radius
yCoord = sin((x+1)*stepValue) * radius
inc memblockPos, fvfSize
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos, xCoord
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos+4, yCoord
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos+28, xCoord * quo + 0.5
write memblock float TEMPORARY_MEMBLOCK_NUM, memblockPos+32, 0.5 - yCoord * quo
next x
` Generate the object from the memblock
make mesh from memblock TEMPORARY_MESH_NUM, TEMPORARY_MEMBLOCK_NUM
make object objectNum, TEMPORARY_MESH_NUM, 0
delete mesh TEMPORARY_MESH_NUM
delete memblock TEMPORARY_MEMBLOCK_NUM
endfunction