Need Help. XPAL implementation for Odejava

If you can execute a call to collide2 it is :wink: … looking at it, now…
…there are copy paste bugs in the javadoc of getSpaceFromNativeAddr…
…you implemented nativeAddr correctly - but that cannot be used for collide2, as that expects the ID :stuck_out_tongue: . The ID is an address, but not the native address - the ID points to the native address. This confusing pointer stuff is caused by bad use of SWIG - all of this getNativeAdress and getCPtr stuff should be removed, but I didn’t take the time for it.

looks ok - only that you must not use the nativeAddress but the CPtr

Ah, Thanks.

I’ve changed that to use getCPtr() instead of getNativeAddress(). No crashes anymore :). But I also don’t receive any collisions. Do I have to do anything more than just collide2() and then iterate over collision.getContactCount()?

Marvin

You need to apply them to get contact joints. Or do you mean that there are no collisions reported to iterate over?

Yes. This is the code:


JavaCollision collision = new JavaCollision(world);
Contact contact = new Contact(collision.getContactIntBuffer(), collision.getContactFloatBuffer());

collision.collide2(c1, c2);

//collision.applyContacts(); <------ Is this necessaray somewhere? It doesn't have an effect for the problem.

for (int i = 0; i < collision.getContactCount(); i++)
{
    // This is never reached! (getContactCount() always seems to return 0)
}

The world passed to the JavaCollision constructor is a new World instance, that has nothing to do with the rest of the scene. Could this be a problem?

The collision.getContactCount() call always returns 0, no matter if I execute collision.applyContacts() before.

Marvin

:o of course! The geoms need to be in the same world and the JavaCollision needs to know that world.

You should not create more than one JavaCollision per world, btw - it uses many resources (esp. native contact buffer) and I’m not sure they are freed correctly (e.g. with garbage collection of the Java object).

And: you not invoke apply contacts before iterating through them but after you iterated through them and values were customized. Have a look at the demos - contacts are working fine in the old xith demos.

Note (maybe I did not express that string enough before) : by using collide2(geom,geom) for all the geoms you kind of ‘misuse’ the collision detection - you don’t use spaces, and spaces are the important stuff to make collision detection fast. So if you plan to do simulation where most things can collide with each other, use spaces and collide them!

What if the Geoms are NOT in any World? Do I have to put them into a World just to do collision detection even if I don’t need the simulation part?

Well, I only created one JavaCollision per check for testing reasons. I wanted to make it a singleton. So don’t worry ;).

Well, as I said. It’s not working with or without the applyContacts() call. Btw. What do I have to call to remove the joint contacts again (if there’s anything).

And none of these demos uses collide2(). They all use collide().

Well, everything should be possible. The very most used case is geom-space, which is where I need collide2(), too. But It should use the space for optimization, shouldn’t it?

If ONLY one geom is to be tested against one geom, it is certainly faster to just test that geom, but not all the others in the same space, too, right?

Marvin

Marvin

Ah, ok, that should be fine. Then you don’t need to apply contacts (which is the only thing that uses the world) either.

[quote]The very most used case is geom-space, which is where I need collide2(), too. But It should use the space for optimization, shouldn’t it?
[/quote]
sure

[quote]And none of these demos uses collide2(). They all use collide().
[/quote]
Uh, true. But it’s used in jME Physics 2…

Probably the geoms’ positions are wrong? Or you passed the geom and not the geomTranform?

ok.

Just to make sure: The collide2() call will traverse through all the whole space (if a space is passed), and maybe subspaces, but not just check the space itself, right?

This is a good point. I just use pass the geom’s/space’es IDs to the collide2() method like this:

collision.collide2( geom1.getID(), space2.getID() ); // getID() returns the result of getCPtr().

Where do I get the GeomTransform from?

Marvin

I have embedded the actual Geom within a GeomTransform and am using it for positioning and collision detection. But I still don’t get any collisions :(. Any hints? Could you maybe setup a small example using collide2()?

Marvin

OK, I found one bug. The internal call to spaceCollide2() returns the contact count as well as the spaceCollide() method does. But the value was not stored to the contactCount variable. Now I am getting contact counts.

Marvin

According to this doc: http://www.ode.org/ode-0.5-userguide.html#sec_10_5_2 the dSpaceCollide2() method should take a callback. How is this implemented in Odejava? Is there maybe a bug? If I pass a Geom’s ID as first argument, this Geom should always be the first one the callback and therefore be stored in contact.getGeom1(). And there should definitely never be a null Geom in a Contact.

Marvin

it the nearCallback in odejava.cpp