www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Veko on January 27, 2009, 02:47:06 pm

Title: collision detection
Post by: Veko on January 27, 2009, 02:47:06 pm
Got a new problem :D.

If I understand checkForCollisionSpherical correct; when there is collision, checkForCollisionSpherical returns a vector different from the translation vector you entered with the check (the correct new translation)

I tried to apply this to my code :

m_ClientObjects is a Vector<Object3D>

all the Object3D in the vector have   
Code: [Select]
object.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
the object where I'm testing the collision for has
Code: [Select]
object.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS | Object3D.COLLISION_CHECK_SELF);
 
Code: [Select]
  for (int i=0;i<STATE.m_ClientObjects.size();++i)
            {
                SimpleVector temp= STATE.m_ClientObjects.elementAt(i).checkForCollisionSpherical(a, 128);

                if (temp != a)
                {
                    a = temp;
                    System.out.println("New translation: " + temp);
                }
            }

But this snippet of code doesn't work, the SimpleVectors a and temp are always the same... so there is always collision ?? (eventhough there isn't)

What am I doing wrong ?
Title: Re: collision detection
Post by: EgonOlsen on January 27, 2009, 02:58:46 pm
Use equals() instead, i.e.

Code: [Select]
if (!temp.equals(a)) {....}
Title: Re: collision detection
Post by: Veko on January 27, 2009, 06:32:54 pm
ok that helped :p

Now I got a dillema, I mainly got square objects like boxes etc. in my scene and I don't really know what to pick for the collision detection, ellipsoid or spherical. I'm worried about the corners of the square objects not being collided with.

Is there somekind of way that I could use similiar to the checkForCollisionSpherical, because the return vector is really handy
Title: Re: collision detection
Post by: EgonOlsen on January 27, 2009, 08:00:57 pm
Do you need that corrected translation vector or are you simply stopping the movement once the returned vector differs from the input one?
Title: Re: collision detection
Post by: Veko on January 27, 2009, 08:01:42 pm
I need the corrected translation vector
but that works fine with spheres and ellipses, but with boxes i'm not sure how to proceed,

I'm trying to mess around a bit with the boundingboxes, but so far I'm not succesfull
Title: Re: collision detection
Post by: EgonOlsen on January 27, 2009, 08:19:52 pm
Can you describe what those boxes do exactly? Do they move freely, do they move on a 2d plane, are they more like the boxes in Tetris...what are they?
Title: Re: collision detection
Post by: Veko on January 27, 2009, 08:28:12 pm
the boxes are static objects in the game and they're used for blocking access (so the player has to go around them)
they stand in a 3d plane

They're much like the boxes and walls in your game robombs
Title: Re: collision detection
Post by: EgonOlsen on January 27, 2009, 08:31:36 pm
If they are static and the player moves (and the player can be approximated by a sphere or an ellipsoid, i.e. it's not a box himself), there's no problem. Just go with ellipsoid collision detection (it's the most flexible one) and you should be fine. At least this is what Robombs does too.
Title: Re: collision detection
Post by: Veko on January 27, 2009, 08:32:33 pm
alright i'll give it a shot

* what should the SimpleVector ellipsoid be ? (i.e how do I determine the radius of the epplisoid in x,y and z direction for a box)
Title: Re: collision detection
Post by: EgonOlsen on January 27, 2009, 09:16:37 pm
* what should the SimpleVector ellipsoid be ? (i.e how do I determine the radius of the epplisoid in x,y and z direction for a box)
The approx. dimension of the player. The boxes doesn't matter. Collision detection in jPCT always is primitive (ray, sphere, ellipsoid) against actual geometry, not against another primitive. Therefor, the boxes don't need to be approximated by an ellipsoid.
Title: Re: collision detection
Post by: Veko on January 27, 2009, 09:54:47 pm
ow ok, cool I thought every object the partakes in the collision needs to be ellipsoid or sphererical