Couple of questions about joints and collisions...

pekanino

10-04-2008 23:18:03

Hey all!

First of all I would like to thank betajaen for the wonderful work he is doing with NxOgre, everyday this keeps getting better!

Second I would like to apologize for the questions I am posting not being related to Bleeding edition... :?

Here they go...

I'm trying to make a ball stick to a wall when it collides with it by creating a fixed joint when some key is pressed and there is a collision. The thing I would like to do is to have the ball stuck as long as I keep the key pressed so I have a bool that tells if that key is still pressed and control the joint life cycle using that bool. This way when I release the key I delete the joint.

The first thing I tried was removing the joint through the scene using scene->releaseJoint() but when I close the game it crashes when deleting the world.

I went a little deeper and found out that the joint destructor calls the releasejoint method in the scene and so I tried simply deleting the joint reference. Same crash.

I then checked the world variable and to my surprise the scene joints vector had one entry (the joint I had created but all messed up). I searched for the releaseJoint code and my guess is that although the joint is deleted it isn't removed from the container which is causing the program to crash when deleting world. I changed the code to remove the entry from the container and then got the same crash on the world descructor but I really can't tell what's happening now... :?

Has anyone had similar problems? Will this go away if I start using bleeding? I believe I have the version that got released before it...

I ended up commenting the call to world's destructor and found out another strange behavior in the fixed joints. When i hit space if the ball is touching a cube I create a fixed joint between them. I have another ball attached to the ball stuck in the cube which I pull away to check if the ball stuck in the cube is really stuck or if it moves. The thing is the behavior is different if I change the call to the creation of the fixed joint.

If I call

scene->createFixedJoint(ball,cube)

I can see the ball is stuck to the cube but it can move a little bit which is quite annoying and not the effect I was looking for.

However if I call

scene->createFixedJoint(cube,ball)

It works like a charm!


Shouldn't both calls produce the exact same result?

Sorry for the size of the post and for not using the latest version of NxOgre yet :oops:

Any help would be appreciated... I thank you in advance :D

betajaen

10-04-2008 23:38:31

That's a strange little bug there, and even stranger with the order of the Actors given to the joints. If the reference to the joint isn't been freed from the container then that's probably one of the reasons for the crash; if you can point me in the direction of the code in question or even submit a patch.

The Joint system in Bleeding and 0.9 is almost the same so I can test it out, play with it,etc. But I must admit I haven't experienced a crash with joints and I assume other people haven't either (nobody has posted about it) so you may be in a unique situation or nobody uses joints.

pekanino

11-04-2008 01:31:55

Hi again!

I rechecked my project settings and noticed in the modules window the symbols for NxOgre weren't being loaded, therefore I couldn't debug any piece of NxOgre code. I found out I had my NxOgre dll mixed with an earlier version and I believe that was the cause of the crash because I can't make it happen again (which is nice :D). Sorry for pointing out something that ended up being my own mistake.

As for the problem with the fixed joints I believe it's really there as I tested it again and got the exact same result which is the behavior changing if I change the order of the actors passed.

First of all joints only work with dynamic bodies am I right? I tried it with a static cube but got no results.

Giving more concrete information on the situation I'm testing... my code is something like this:



ActorGroup *smallBallGroup = scene->createActorGroup("SmallBall");
ActorGroup *glueGroup = scene->createActorGroup("GlueObjects");

myCallback* mCallback = new myCallback();

smallBallGroup->setCallback(mCallback);
smallBallGroup->setCollisionCallback(glueGroup, NX_NOTIFY_ALL, true);

Body* smallBall = scene->createBody("sphere.2m.mesh", new SphereShape(0.5,"material: nx.lava"), Vector3(0,12.5f,0), "mass: 50");
smallBall->getNode()->setScale(0.5,0.5,0.5);
smallBall->setGroup(smallBallGroup);

Body* glueCube = scene->createBody("cube.1m.smooth.mesh", new CubeShape(20), Vector3(3.0f,4.5f,0), "mass: 10000");
glueCube->getNode()->setScale(20,20,20);
glueCube->setGroup(glueGroup);


The callback code only does this:



void myCallback::onStartTouch(Actor* actor1, Actor* actor2) {

if (!jointCreated && pressingKey) {
LogManager::getSingletonPtr()->logMessage("actor names:\n actor1:" + actor1->getName() + "\n actor2:" + actor2->getName());
myCallback::joint = (actor1->getScene()->createFixedJoint(actor2,actor1));
jointCreated = true;
}


}



The input manager deletes the joint if it exists and the key is up

The log says:
actor names:
actor1:sphere.2m.mesh
actor2:cube.1m.smooth.mesh

and the effect only works when the first actor passed to the fixed joint is the cube.

Can it be because of the mass difference? Or because the sphere shape has a material? I'm truly clueless about this one... Of course I could check the actor's name and make sure the ball is always the second actor but that solution doesn't please me much...

Any ideas of what's going on?

Btw... Thank for responding so quickly!
Tomorrow I will try to post a video showing the situation differences with the different calls.

Thanks in advance!

Impactus

17-04-2008 00:28:35

Hi there pekanino! (btw, nice nick!)
I share your pain!

>> First of all joints only work with dynamic bodies am I right? I tried it with a static cube but got no results.

Yeah I'd like to know if this really is true. Right now I am creating a dynamic body and setting the mass to 9999999 (shame on me :roll: ). I also create a static body at the bottom to prevent the dynamic body from falling forever :lol:
How can I do this in an elegant way???

>> and the effect only works when the first actor passed to the fixed joint is the cube.

I also have this doubt! Why is the order of the parameters of createFixedJoint(actor1, actor2) important??

Thanks in advance!

betajaen

17-04-2008 00:35:25

What about setting the actor to kinematic? It will be still dynamic and have some mass, but it won't react to forces and gravity, and I'm pretty sure joints will work with them.

I will be re-visiting joints soon, after I implement CompoundActors and serialisation in the next release and because I plan to add some sort of Ragdoll class/code using said CompoundActors, I would want some quick fast joint creation and destruction for maximum pwnage.