One more, using the new command I've introduced to create 'blank' objects ready for filling in. This is a reworking of my (rather crap) wavy flag code, using the new command, and direct vertex manipulation.
sync on
sync rate 60
autocam off
backdrop on
color backdrop rgb(0, 0, 0)
load image "UnionJack.bmp", 1
MakeObjectPlain(1, 36.0, 18.0, 36, 1)
rotate object 1, -90.0, 0.0, 0.0
fix object pivot 1
texture object 1, 1
position object 1, 0.0, 0.0, 0.0
set object cull 1, 0
rotate object 1, 0, 45, 0
position camera 18, 9, -80
point camera 18, 9, 0
global AngleOffset as integer = 0
repeat
set cursor 0, 0
print screen fps()
AngleOffset = wrapvalue( AngleOffset + 6 )
WaveTheFlag(1, 36, 1)
sync
until spacekey()
end
function WaveTheFlag(ObjectID as integer, XSegs as integer, ZSegs as integer)
local x as integer
local y as float
local z as integer
local V as integer
lock vertexdata for limb ObjectID, 0
for x = 0 to XSegs - 1
y = sin(AngleOffset+(x*20))
select x
case 0 : y = y*1.0 : endcase
case 1 : y = y*1.5 : endcase
case 2 : y = y*2.0 : endcase
case 3 : y = y*2.5 : endcase
case default : y = y*3.0 : endcase
endselect
for z = 0 to ZSegs
V = GetPlaneVertex(x, z, C_TOP_RIGHT, XSegs, ZSegs)
set vertexdata position V, get vertexdata position x(V), y, get vertexdata position z(V)
V = GetPlaneVertex(x, z, C_BOT_RIGHT, XSegs, ZSegs)
set vertexdata position V, get vertexdata position x(V), y, get vertexdata position z(V)
next
next x
unlock vertexdata
endfunction
function MakeObjectPlain(ObjectID as integer, Width as float, Depth as float, XSegs as integer, ZSegs as integer)
local XPos as float
local ZPos as float
local XStep as float
local ZStep as float
local XStart as float
local ZStart as float
XStep = Width / XSegs
XStart = 0.0 - (XStep * XSegs / 2.0)
ZStep = Depth / ZSegs
ZStart = ZStep * ZSegs / 2.0
MAKE OBJECT NEW ObjectID, (XSegs+1)*(ZSegs+1), 6*XSegs*ZSegs, 338
lock vertexdata for limb ObjectID, 0
V = 0
ZPos = ZStart
for z = 0 to ZSegs
XPos = XStart
for x = 0 to XSegs
SetVertexData(V, XPos, 0.0, ZPos, 0.0, 1.0, 0.0, 1.0 / ((XSegs + 0.0) / x), 1.0 / ((ZSegs + 0.0) / z), 0xffffffff )
inc V
inc XPos, XStep
next
dec ZPos, ZStep
next
I = 0
for z = 0 to ZSegs - 1
for x = 0 to XSegs - 1
set indexdata I , GetPlaneVertex(x, z, C_TOP_LEFT, XSegs, ZSegs)
set indexdata I + 1, GetPlaneVertex(x, z, C_TOP_RIGHT, XSegs, ZSegs)
set indexdata I + 2, GetPlaneVertex(x, z, C_BOT_LEFT, XSegs, ZSegs)
set indexdata I + 3, GetPlaneVertex(x, z, C_TOP_RIGHT, XSegs, ZSegs)
set indexdata I + 4, GetPlaneVertex(x, z, C_BOT_RIGHT, XSegs, ZSegs)
set indexdata I + 5, GetPlaneVertex(x, z, C_BOT_LEFT, XSegs, ZSegs)
inc I, 6
next
next
unlock vertexdata
endfunction
function SetVertexdata(Index as integer, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, d as dword)
set vertexdata position Index, x, y, z
set vertexdata normals Index, nx, ny, nz
set vertexdata uv Index, u, v
set vertexdata diffuse Index, d
endfunction
#constant C_TOP_LEFT 1
#constant C_TOP_RIGHT 2
#constant C_BOT_LEFT 3
#constant C_BOT_RIGHT 4
function GetPlaneVertex(X as integer, Z as integer, Corner as integer, XSegs as integer, ZSegs as integer)
local V as integer
V = (XSegs + 1) * Z + X
select Corner
case C_TOP_LEFT : : endcase
case C_TOP_RIGHT : inc V : endcase
case C_BOT_LEFT : inc V, XSegs + 1 : endcase
case C_BOT_RIGHT : inc V, XSegs + 2 : endcase
case default : V = -1 : endcase
endselect
endfunction V
The command to look for is MAKE OBJECT NEW, which allows you to specify the number of vertices, the number of indices and the FVF format of the object.
[EDIT] Added the Union Jack image