Gah, i should realllllly check my posts before going off and waiting for an answer, i see my code tag messed up -_-
Lets try again:
Sync Rate 0
Sync On
Autocam Off
rem load object "TreeSml.x", 1
Make Object Cube 1, 5
Make Object Cube 2, 5
Position Object 1, 0, 0, 0
Position Object 2, 40, 0, 40
make mesh from object 200, 1
Do
ox# = object position x(1)
oy# = object position y(1)
oz# = object position z(1)
oxr# = object angle x(1)
oyr# = object angle y(1)
ozr# = object angle z(1)
If Upkey() then move object 1, 0.5
If Downkey() then move object 1, -0.5
If leftkey() then turn object left 1, 0.5
if rightkey() then turn object right 1, 0.5
set camera to follow Object Position X(1), Object Position Y(1), Object Position Z(1), Object Angle Y(1), 8, 5, 1, 0
Col = PolyCol(1, 2, Object Position X(2), Object Position Y(2), Object Position Z(2))
If Col = 1
Text 0, 0, "Collision"
position object 1, ox#, oy#, oz#
rotate object 1, oxr#, oyr#, ozr#
else
Text 0, 0, "No Collision"
endif
Text Screen Width() - 25, 0, Str$(Screen Fps())
Sync
Loop
Function PolyCol(Obj1, Obj2, x as float, y as float, z as float)
Make Mesh From Object 1, Obj1
Make Memblock From Mesh 1, 1
FVFS = Memblock Dword(1, 4)
NVTX = Memblock Dword(1, 8)
VDS = NVTX * FVFS
PCol = 0
For CurrentMem = 12 to (VDS - FVFS) Step FVFS
VTXX = Memblock Float (1, CurrentMem)
VTXY = Memblock Float (1, CurrentMem + 4)
VTXZ = Memblock Float (1, CurrentMem + 8)
IntS = Intersect Object (Obj2, VTXX + Object Position X(Obj1), VTXY + Object Position Y(Obj1), VTXZ + Object Position Z(Obj1), x, y, z)
If IntS =< 0
PCol = 1
Exit
Endif
Next CurrentMem
Delete Memblock 1
Delete Mesh 1
EndFunction PCol
I do a very simular thing to your pseudocode. Basically, i get the object into memory and then start running through the vertices of the object. I use intersect object to check the collision. If i understand it right, intersect object casts a line from x1, y1, z1 into x2, y2, z2 and returns the distance to the point where the line hits a poly beloning to the object set as the first parameter. So effectivly in my function im drawing a line from a poly in obj a (well, i suppose from a vertex) to object 2 with intersect object so hopfully getting the distance between two polys. However, as you can see if you test my code (supposing it works this time!) its far from perfect, i must be doing something stupid.
Still, it needs much more optimising. Yes first you do a distance check to make sure the object is worth checking against, but i leave that upto the engine and not the collision function (my engine doesnt bother doing anything to objects a certain distance away

). Im pretty sure that if i want this function to be usuable im going to have to seriously limit the amount of polygons that are actually being checked against, and the only way i can do that is what i said earlier (no scrap that, my post boogered didnt it, i said nothing earlier according to it -_-) about getting the angle of the object, its direction and checking only the relevent side of the object rather than all of it. I dont know the maths or trig for this though.. even if i managed to get all the info i needed i would have no idea which polys to read out (ie, where to start in the mem and where to stop)
p4 2.4ghz, 256ddr ram, Geforce4 MX 440
Innovate, redefine, recreate whats in your mind. It isnt fate, you decide, only you can cross that line.