I got a name check!
By using memblocks you can get access to how images, sounds and objects are constructed, which as Phaelax said, can be used to manipulate or make images, sounds and objects. But you can also uses memblocks to in other ways. The code snippet below uses a memblock for collision purposes.
`this is a demo the demonstates using memblock to extracted vertex
`position data from an object for maths collision
`By 29 games
`11 October 2010
sync on
sync rate 65
gosub MAKE_OBJECTS
do
gosub CONTROLS_AND_POSITION_CAMERA
gosub COLLIDE_WITH_CYLINDER
gosub PRINT_STUFF
sync
loop
end
MAKE_OBJECTS:
make matrix 1, 1000,1000,10,10 :`act as ground
`car
make object box 1, 50,10,70 :`make an object for "car"
position object 1, 500,5,200 :`starting position of "car"
`make sphere to collide with
radius# = 100 :`radius of sphere
x_cir# = 500 :`x position of sphere
y_cir# = 0 :`y position of sphere
z_cir# = 500 :`y position of sphere
make object sphere 2, radius#*2 :`make the sphere
color object 2, rgb(200,200,0) :`ghost the sphere
position object 2, x_cir#,y_cir#,z_cir# :`position the sphere
return
CONTROLS_AND_POSITION_CAMERA:
if upkey() = 1 then move object 1, 5 :`move foward
if downkey() = 1 then move object 1, -1 :`move backward
if rightkey() = 1 then f_car# = f_car# + 2 :`turn right
if leftkey() = 1 then f_car# = f_car# - 2 :`turn left
x_car# = object position x(1) :`get car's x position
y_car# = object position y(1) :`get car's y position
z_car# = object position z(1) :`get car's z position
yrotate object 1, f_car# :`rotate car
`set camera to follow x_car#,y_car#,z_car#,f_car#, 50,30,10, 0 :`position camera
position camera x_car#,500,z_car#
point camera x_car#,y_car#,z_car#
return
COLLIDE_WITH_CYLINDER:
make mesh from object 1,1 :`make a mesh from the car
make memblock from mesh 1,1 :`make a memblock from the mesh
num_verts = memblock dword(1,8) :`extract the number of vertices
vert = 0 :`set vert number to zero
hit = 0 :`set hit flag to zero (i.e. car has not hit sphere)
`loop for collision
repeat
`for each vertex extract position of vertex from memblock (local position relative to object position)
`then add objects position to get global position
x_vert# = memblock float(1,12+vert*32) + x_car# :`global x position of vertext
y_vert# = memblock float(1,16+vert*32) + y_car# :`global y position of vertext
z_vert# = memblock float(1,20+vert*32) + z_car# :`global z position of vertext
`calculate the distance between the vertex and the centre of the sphere
distance# = sqrt( (x_vert# - x_cir#)^2 + (y_vert# - y_cir#)^2 + (z_vert# - z_cir#)^2 )
`if the distance is less then the radius of the sphere then the car has hit the sphere
if distance# < radius#
hit = 1
color object 1, rgb(250,0,0)
else
hit = 0
color object 1, rgb(0,250,0)
endif
if hit = 1 then exit :`exit the loop (only need to know if one vertex is inside the sphere)
inc vert
until vert = num_verts
return
PRINT_STUFF:
set cursor 0,0
print "use cursor key to move the car (the green block)"
print "if a vertex of the car is inside the sphere the car will turn red"
return
The collision shown is very simple but, with a bit of mathematics, you can create much more complicated collision detection.
You can also use memblocks to pass data to dlls (which I believe is how things like sparky's collision dll work) and I've seen them used to pass information to other computers as part of multiplayer games.