I figured this example might help some people learn how to do this. I found that using objects as bullets in shooter games was slow when I had a bunch on the screen, and I hated having to use standard collision checks(which were also slow) so I turned to Sparkys Collision DLL and his DBCIntersectObject. I made a quick media-free example of how to use it in a FPS type game. It's all commented out, you just need to download the DLL and put it in the same folder as this code.
DLL:
http://forum.thegamecreators.com/?m=forum_view&b=5&t=31051&p=0
And the code:
sync on : sync rate 0 : hide mouse : autocam off
`Load in sparkys collision DLL.
if dll exist(1)=0 then load dll "DBCcollision.dll",1
make matrix 1, 250, 250, 50, 50
position camera 125, 5, 125
make object sphere 1, 5
color object 1, rgb(255,0,255)
`This sets up our object. It tells the DLL that it's object 1, group 1, and type 1(sphere) Refer to the file included with the DLL for more detailed explanations.
setupObjectDBC(1,1,1)
rndX = rnd(250)
rndZ = rnd(250)
position object 1, rndX, 2.5, rndZ
`This updates the object in the DLL
updateObjectDBC(1)
do
`Print the screen FPS.
set cursor 0,0
print "FPS: "; screen fps()
`These store the previous cam angle values.
oldcAY# = cAY#
oldcAX# = cAX#
`These store the current cam angle values.
cAY# = WrapValue(cAY#+MousemoveX()*0.2)
cAX# = WrapValue(cAX#+MousemoveY()*0.2)
cAZ# = Camera angle Z()
`Rotate camera
cTestX#=WrapValue(cAX#-180)
if cTestX# > 225 then cAX#=45
if cTestX# < 100 then cAX#=280
YRotate camera CurveAngle(cAY#,oldcAY#,24)
XRotate camera CurveAngle(cAX#,oldcAX#,24)
`Control input for camera. We don't let the player leave the matrix.
If Upkey()=1
XTest# = Newxvalue(X#,cAY#,1)
ZTest# = Newzvalue(Z#,cAY#,1)
`The XTest and ZTest are checked for out of bounds seperately to allow for smooth sliding collision.
If XTest#>0 and XTest#<250
X#=XTest#
endif
if ZTest#>0 and ZTest#<250
Z#=ZTest#
Endif
Endif
If Downkey()=1
XTest# = Newxvalue(X#,Wrapvalue(cAY#-180),1)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#-180),1)
If XTest#>0 and XTest#<250
X#=XTest#
endif
if ZTest#>0 and ZTest#<250
Z#=ZTest#
Endif
Endif
If Leftkey()=1
XTest# = Newxvalue(X#,Wrapvalue(cAY#-90),1)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#-90),1)
If XTest#>0 and XTest#<250
X#=XTest#
endif
if ZTest#>0 and ZTest#<250
Z#=ZTest#
Endif
Endif
If Rightkey()=1
XTest# = Newxvalue(X#,Wrapvalue(cAY#+90),1)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#+90),1)
If XTest#>0 and XTest#<250
X#=XTest#
endif
if ZTest#>0 and ZTest#<250
Z#=ZTest#
Endif
Endif
`Position the camera
Position Camera X#,2.5,Z#
if mouseclick() = 1
`Store the current camera position
toldx#=camera position x()
toldy#=camera position y()
toldz#=camera position z()
`Move the camera forward 500
move camera 500
`Store the new position
tx#=camera position x()
ty#=camera position y()
tz#=camera position z()
`Move it back to its original location.
move camera -500
`Now we check if there's an object on the line between the old position and the new position
collide=intersectObjectDBC(1,1,toldx#,toldy#,toldz#,tx#,ty#,tz#,0)
`If there is
if collide<>0
`We reposition the sphere.
rndX = rnd(250)
rndZ = rnd(250)
position object 1, rndX, 2.5, rndZ
`Position the sphere and update it in Sparkys DLL.
updateObjectDBC(1)
endif
endif
Rem Draw cross-hair (Change the RGB values to whatever you want)
ink rgb(255,255,255),0
line screen width()/2-6, screen height()/2, screen width()/2+7 , screen height()/2
line screen width()/2, screen height()/2-6, screen width()/2, screen height()/2+7
Rem This sets the ink to black
ink rgb(255,0,0),0
circle screen width()/2,screen height()/2,3
circle screen width()/2,screen height()/2,1
ink rgb(255,255,255),0
sync
loop
`These are functions from Sparkys DLL
function setupObjectDBC(objNum,groupNum,objectType)
commonSetup(objNum)
vertData = get memblock ptr(254)
objectData = get memblock ptr(255)
call dll 1,"setupObject",objNum,groupNum,objectType,vertData,objectData
delete memblock 254
endfunction
function setupComplexObjectDBC(objNum,groupNum,facesPerNode)
commonSetup(objNum)
vertData = get memblock ptr(254)
objectData = get memblock ptr(255)
call dll 1,"setupComplexObject",objNum,groupNum,facesPerNode,vertData,objectData
delete memblock 254
endfunction
function commonSetup(objNum)
if dll exist(1)=0 then load dll "DBCcollision.dll",1
if memblock exist(255)=0 then make memblock 255,24
x#=object position x(objNum)
y#=object position y(objNum)
z#=object position z(objNum)
angx#=object angle x(objNum)
angy#=object angle y(objNum)
angz#=object angle z(objNum)
write memblock float 255,0,x#
write memblock float 255,4,y#
write memblock float 255,8,z#
write memblock float 255,12,angx#
write memblock float 255,16,angy#
write memblock float 255,20,angz#
position object objNum,0,0,0
rotate object objNum,0,0,0
make mesh from object 255,objNum
make memblock from mesh 254,255
delete mesh 255
position object objNum,x#,y#,z#
rotate object objNum,angx#,angy#,angz#
endfunction
function updateObjectDBC(objNum)
if memblock exist(255)=0 then make memblock 255,24
write memblock float 255,0,object position x(objNum)
write memblock float 255,4,object position y(objNum)
write memblock float 255,8,object position z(objNum)
write memblock float 255,12,object angle x(objNum)
write memblock float 255,16,object angle y(objNum)
write memblock float 255,20,object angle z(objNum)
objectData = get memblock ptr(255)
call dll 1,"updateObject",objNum,objectData
endfunction
function intersectObjectDBC(objNum,groupFlag,oldx#,oldy#,oldz#,x#,y#,z#,excludeObj)
collide=call dll(1,"intersectObject",objNum,groupFlag,oldx#,oldy#,oldz#,x#,y#,z#,excludeObj)
endfunction collide
function setObjectCollisionOnDBC(objNum)
call dll 1,"set_object_collision_on",objNum
endfunction
function setObjectCollisionOffDBC(objNum)
call dll 1,"set_object_collision_off",objNum
endfunction
function collisionStatusDBC(objNum)
result=call dll(1,"collisionstatus",objNum)
endfunction result
function getStaticCollisionX()
result#=call dll(1,"getStaticCollisionX")
endfunction result#
function getStaticCollisionY()
result#=call dll(1,"getStaticCollisionY")
endfunction result#
function getStaticCollisionZ()
result#=call dll(1,"getStaticCollisionZ")
endfunction result#
function getCollisionNormalX()
result#=call dll(1,"getCollisionNormalX")
endfunction result#
function getCollisionNormalY()
result#=call dll(1,"getCollisionNormalY")
endfunction result#
function getCollisionNormalZ()
result#=call dll(1,"getCollisionNormalZ")
endfunction result#
I hope that this is helpful, and if anyone needs more help, then ask away and I'll help as best I can.