View Full Version : Collision Detection all in

hello all i'm still trying to get 'Collision Detection' working. i have stiched this code into my app. 1/2 ways there so far. i need to add 'z' and the rotaion test just dont seem to work...

my object is tracks the x, y, z of transformations and the x, y, z of rotaions.

any points how to fix this ??? would be cool

---- code

// Collision Detection. ///// dont seem

//to fully work 100 :(.

public void collisionDetection(shape obja, shape objb) {

if((obja.r + objb.r) < (Math.sqrt((obja.ty-objb.ty)*(obja.ty-objb.ty)+(obja.tx-objb.tx)*(obja.tx-objb.tx)))) {

output("trans not colliding");

} else {

if((obja.r + objb.r) < (Math.sqrt((obja.ry-objb.ry)*(obja.ry-objb.ry)+(obja.rx-objb.rx)*(obja.rx-objb.rx)))) {

ouput("rot not colliding");

} else {

output("rot colliding");

}

}

}

Relic

08-08-2000, 04:31 AM

From what I understood, the only transformations you apply are translations and rotations. And always in this order(!).

So you first check if the translations in modelspace(!) collide and if that's the case you check wether the rotation applied afterwards lies below some threshold (here the sum of the radii).

Assuming the objects are spheres and obj.r means the radius. The translation test is ok.

(I wouldn't calculate the differences twice though, but use a temporary variable.)

The rotational test is not working this way.

You cannot compare the angles with the radius.

The distance between the objects depends on the rotation AND the translation.

Having two angles which result in collision if the objects are in the same spot (e.g. if the objects are not translated) will have lightyears of distance if the translation before is some parsecs.

Completely transform the objects first and then calculate the distances in world space.

That's all.

[This message has been edited by Relic (edited 08-08-2000).]

obja.r is the radius of object 'a' :)

I think I'm understand this, if u can tell more it would be most helpful mind…

I've translated obja then rotated it 20' when I do a transformation check objb that's not moving but has been translated 20f in x says its being hit. obja is moving but is also set to 20f in x then rotated. Its not hitting the objb but its transformations match so its hit.

I cant seem to work out how I can add the rotations collision. Its not near obja but its a hit, I can see why its a hit, just cant seem to get my head around how I can do both the transform and rotate checks.

Helps :)

aNt

Relic

08-08-2000, 05:10 AM

As I said, don't do independent checks on the transformations, but apply all transformations to the objects (that is generate 4x4 matrices from your translation and rotation values, multiply all those matrices, and multiply with the objects' model positions), and check the position deltas in world space against your radii threshold. (This is for spheres, only.)

The matrices generated by OpenGL can be found in an appendix in the Redbook, which is available online here: http://heron.cc.ukans.edu/ebt-bin/nph-dw.../7109;cd=7;td=6 (http://heron.cc.ukans.edu/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/@Generic__BookTocView/7109;cd=7;td=6)

not simple then ? i have to make another matrix thats for me to check the locations of my objects ? nightmare. dont no where to start there :(

aNt

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.