I'm using Sparky's Collision DLL and got my code working pretty good with "normal" sized objects, but when I added a very small (18x70mm) object I got no collision reaction.
Is there a minimum object size for Sparky's collision? I wouldnt think there is, but I could be wrong.
I've included the code for inspection but its uncommented for now.
randomize timer()
type DataWord
Zero as boolean
One as boolean
Two as boolean
Three as boolean
Four as boolean
Five as boolean
Six as boolean
Seven as boolean
Eight as boolean
Nine as boolean
Ten as boolean
Eleven as boolean
Twelve as boolean
Thirteen as boolean
Fourteen as boolean
Fifteen as boolean
endtype
type Coord
X as float
Y as float
Z as float
endtype
type DispMode
HRes as word
VRes as word
Depth as byte
endtype
FirstRun as boolean
global FirstRun
FirstRun = 1
global ObjectPosition
dim ObjectPosition(1000) as Coord
global ObjectBounds
dim ObjectBounds(1000) as float
global ObjectCollisionFlags
dim ObjectCollisionFlags(1000) as DataWord
global ObjectType
dim ObjectType(1000) as byte
global CollDist as float
make memblock 1, 1
null = make vector3(1)
null = make vector3(2)
InitDisplay()
load object "c:k96modelsterrainsplain.x", 1
color object 1, rgb(150, 50, 40)
load object "C:K96Modelstanksnxs-1b temp.x", 10
set object cull 10, 1
position object 10, 0, 0, 0
color object 10, rgb(255, 255, 255)
sc_setupcomplexobject 10, 0, 2
sc_updateobject 10
rem SetMeshCollision()
SetObjectType(10, "Vehicle")
UpdateObjectPosition(10)
MakeBoundingSphere(10)
MakeBoundingBox(10)
load object "C:K96ModelsWeaponsVehiclemissileslrm.x", 11
set object cull 11, 0
position object 11, RandomWithSign(1000), 5.8, RandomWithSign(1000)
point object 11, 0, 0, 0
SetObjectType(11, "Missile")
sc_setupcomplexobject 11, 0, 2
UpdateObjectPosition(11)
MakeBoundingSphere(11)
MakeBoundingBox(11)
for a = 12 to 21
clone object a, 11
position object a, RandomWithSign(5280), rnd(5280), RandomWithSign(5280)
point object a, 0, 0, 0
SetObjectType(11, "Missile")
sc_setupcomplexobject a, 0, 2
UpdateObjectPosition(a)
MakeBoundingSphere(a)
MakeBoundingBox(a)
next a
load object "C:K96ModelsWeaponsVehicleprojectiles18 x 70.x", 22
set object cull 22, 0
position object 22, RandomWithSign(1000), 5.8, RandomWithSign(1000)
point object 22, 0, 0, 0
SetObjectType(22, "Projectile")
sc_setupcomplexobject 22, 0, 2
UpdateObjectPosition(22)
MakeBoundingSphere(22)
MakeBoundingBox(22)
for a = 23 to 100
clone object a, 22
position object a, RandomWithSign(5280), rnd(5280), RandomWithSign(5280)
point object a, 0, 0, 0
SetObjectType(22, "Projectile")
sc_setupcomplexobject a, 0, 2
UpdateObjectPosition(a)
MakeBoundingSphere(a)
MakeBoundingBox(a)
next a
position camera 0, 5.8, 0
set camera range .0001, 1000000
do
control camera using arrowkeys 0, 1, 1
for a = 11 to 100
Collision = 0
Temp = CheckBoundingSphere(a, 0)
if Temp <> 0
if CheckBoundingBox(a, Temp)
if CheckPolyCollision(a, Temp)
Collision = 1
endif
endif
endif
if Collision = 0
move object a, 1
sc_updateobject a
UpdateObjectPosition(a)
MoveBoundingSphere(a)
MoveBoundingBox(a)
endif
text object screen x(a), object screen y(a), "Missile " + str$(a - 10)
next a
text 10, 10, str$(screen fps())
text 10, 20, str$(statistic(1))
loop
wait key
end
function CheckBoundingBox(ObjNumA, ObjNumB)
if ObjNumB = 0
for a = 1010 to 1100
if a <> ObjNumA
if sc_objectcollision(ObjNumA, a) = 1
exitfunction a
endif
endif
next a
else
if sc_objectcollision(ObjNumA + 1000, ObjNumB + 1000) = 1
exitfunction 1
endif
endif
endfunction 0
function CheckBoundingSphere(ObjNumA, ObjNumB)
if ObjNumB = 0
for a = 10 to 100
if a <> ObjNumA
set vector3 1, ObjectPosition(ObjNumA).X - ObjectPosition(a).X, ObjectPosition(ObjNumA).Y - ObjectPosition(a).Y, ObjectPosition(ObjNumA).Z - ObjectPosition(a).Z
CollDist = length vector3(1)
if ObjectBounds(ObjNumA) + ObjectBounds(a) >= CollDist
exitfunction a
endif
endif
next a
else
set vector3 1, ObjectPosition(ObjNumA).X - ObjectPosition(ObjNumB).X, ObjectPosition(ObjNumA).Y - ObjectPosition(ObjNumB).Y, ObjectPosition(ObjNumA).Z - ObjectPosition(ObjNumB).Z
CollDist = length vector3(1)
if ObjectBounds(ObjNumA) + ObjectBounds(ObjNumB) >= CollDist
exitfunction a
endif
endif
endfunction 0
function CheckPolyCollision(ObjNumA, ObjNumB)
if ObjNumB = 0
else
if sc_objectcollision(ObjNumA, ObjNumB) = 1
exitfunction 1
endif
endif
endfunction 0
function MakeBoundingBox(ObjNum)
if object exist(ObjNum)
make object box ObjNum + 1000, object size x(ObjNum), object size y(ObjNum), object size z(ObjNum)
ghost object on ObjNum + 1000
position object ObjNum + 1000, object position x(ObjNum), object position y(ObjNum), object position z(ObjNum)
point object ObjNum + 1000, 0, 0, 0
sc_setupcomplexobject ObjNum + 1000, 0, 2
endif
endfunction 0
function MakeBoundingSphere(ObjNum)
XSize# = object size x(ObjNum)
YSize# = object size y(ObjNum)
ZSize# = object size z(ObjNum)
set vector3 1, 0, 0, 0
set vector3 2, XSize#, YSize#, ZSize#
subtract vector3 1, 1, 2
BoundRadius# = length vector3(1)
make object sphere ObjNum + 2000, BoundRadius#
ghost object on ObjNum + 2000
position object ObjNum + 2000, object position x(ObjNum), object position y(ObjNum), object position z(ObjNum)
ObjectBounds(ObjNum) = BoundRadius# / 2
endfunction 0
function MoveBoundingBox(ObjNum)
position object ObjNum + 1000, ObjectPosition(ObjNum).X, ObjectPosition(ObjNum).Y, ObjectPosition(ObjNum).Z
sc_updateobject ObjNum + 1000
endfunction
function MoveBoundingSphere(ObjNum)
position object ObjNum + 2000, ObjectPosition(ObjNum).X, ObjectPosition(ObjNum).Y, ObjectPosition(ObjNum).Z
endfunction
function RandomWithSign(Number#)
Number# = rnd(Number#)
if rnd(10) > 5
Number# = 0 - Number#
endif
endfunction Number#
function SetMeshCollision(ObjNum, Terrain, Projectile, Missile, Flora, Fauna, Structure, Vehicle)
ObjectCollisionFlags(ObjNum).Zero = Terrain
ObjectCollisionFlags(ObjNum).One = Projectile
ObjectCollisionFlags(ObjNum).Two = Missile
ObjectCollisionFlags(ObjNum).Three = Flora
ObjectCollisionFlags(ObjNum).Four = Fauna
ObjectCollisionFlags(ObjNum).Five = Structure
ObjectCollisionFlags(ObjNum).Six = Vehicle
endfunction
function UpdateObjectPosition(ObjNum)
ObjectPosition(ObjNum).X = object position x(ObjNum)
ObjectPosition(ObjNum).Y = object position y(ObjNum)
ObjectPosition(ObjNum).Z = object position z(ObjNum)
endfunction
function SetObjectType(ObjNum, Type$)
select Type$
case "Terrain"
ObjectType(ObjNum) = 1
endcase
case "Projectile"
ObjectType(ObjNum) = 2
endcase
case "Missile"
ObjectType(ObjNum) = 3
endcase
case "Flora"
ObjectType(ObjNum) = 4
endcase
case "Fauna"
ObjectType(ObjNum) = 5
endcase
case "Structure"
ObjectType(ObjNum) = 6
endcase
case "Vehicle"
ObjectType(ObjNum) = 7
endcase
endselect
endfunction
Smaller government, fewer social programs, no illegal wars...Ron Paul in 2008!