Body Position problems

SFAOK

15-08-2006 19:09:15

I'm wondering if anyone can help me with this problem:

I'm currently developing a spider simulation for my PhD research. Each of the spider's legs has a target (entity and node), which you can partly see as the blue sphere in the image below. The spider attempts to touch that target at all times with the tip of its leg.

note : The Target Node is a child of the Leg node, which in turn is a child of the Spider node.



Now what I want to do is have a collision callback that tells me when the tip of the spider's leg has touched the surface of the landscape. So what I have is another node (attached to the target node, with a grey sphere as an entity). I've enlargened the sphere for the screenshot, but you can see it overlapping the blue target.

So the grey sphere is an ogreNewt object, usually invisible which inherits the position of the (blue) target node at all times.

The problem I'm having can be seen in the screenshot below :



So while the visual entity for the ogreNewt body is correctly placed where it should be, pressing F3 to get the debugging information shows that the actual body/collision object isn't (its way in the background on the right). I've tried every possible variation of setting the position of the body (getPosition, getWorldPosition, _getDerivedPosition, etc), but I simply can't get the collision body to overlap the actual visual entity. It always seems to be hovering around the origin of the landscape (i.e pos = 0,0,0).

Here is the relevant code :


// make the visual object (a sphere)

Entity* ent;
SceneNode* node;
Ogre::String name = "TargetCollision";

ent = mSceneMgr->createEntity(name, "sphere.mesh" );
node = mTargetNode->createChildSceneNode(name);

node->attachObject(ent);
ent->setNormaliseNormals(true);

// again, make the collision shape.
OgreNewt::Collision* col1 = new OgreNewt::CollisionPrimitives::Ellipsoid(mNewtonWorld, Vector3(10,10,10));

// then make the rigid body.
body1 = new OgreNewt::Body( mNewtonWorld, col1, BT_TARGET);
body1->setMaterialGroupID(mNewtonWorld->getDefaultMaterialID());

//no longer need the collision shape object
delete col1;

//Inertia
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcSphereSolid( 10.0, 1.0 );
body1->setMassMatrix( 10.0, inertia );

// attach to the scene node.
body1->attachToNode(node);
body1->setPositionOrientation(Vector3(0,0,0), Ogre::Quaternion(Ogre::Quaternion::IDENTITY));


I'm just wondering why the entity itself (i.e the grey sphere) inherits the position of the target node (being a child of it), yet the body doesn't.

One thing I have noticed is that if I throw something against the body, the entity which is in the correct position moves at a much slower pace than the collision object (i.e its moving at a different scale). Could this be the problem? Any help would be great.

lonwolf

15-08-2006 20:36:16

hello. The answer to your question lies here:
although the newton body may be "attached" to a node, its not the way a mesh/entity is attached. A normal movableObject has its dimensions and positions/rotations influenced on the node. If u scale/move/rotate the node the entity does the same. But the newton bodyes have a different reaction to this. If you move the attached node with setPosition or Translate you will se the body doesnt. BUT IF you move the body with forces/velocity you will see that the node is moving along. So the conlusions:
1. the body can move the node, but if the node is moved by a Vector3 translation in space, the body will stay fixed;
2. if u want to overlap the 2 spheres just use body->setPositionOrientation(pos, Quaternion::IDENTITY), where pos you will adjust untill they are perfectly overlaped. Its the only way. After they are overlaped, and you want to move the node to another position(and the ball and body along) dont use setPostion/or anything on the node, just add a local/global force to the sphere/elipsoid or velocity. That way you will move all 3 of your objects : node, entity/mesh, body.

Hope it helps :wink:

SFAOK

16-08-2006 15:55:07

Oh dear, that complicates things! :shock: Thanks for the reply.

I guess I'll have to convert my stepping function (i.e the one that moves the target in semi-circles each footstep) from tracing a line using setPosition() to Forces, and replace the Target Node with the OgreNewt::Body.

lonwolf

16-08-2006 18:45:13

yes, rather than setPosition, use a custom callback to add a force or just use setVeloctiy( Vector3 vec) and when u reached the target just set the velocity to 0, ex: target_body->setVelocity(Vector3(0,0,0));

SFAOK

28-08-2006 16:46:59

OK I've solved that problem. I've converted all my scene node translations into relevant phys body forces/velocities. Works perfectly.

I have another question I might as well ask here...

What would be the best way to create a collision hull for my spider? Its quite a complex object (with 48 joints). I've attempted creating a ragdoll (using auto-hull generation), but I ran into a lot of problems with the mesh colliding with itself and going beserk.

I've been attempting to create a function which goes through each (leg) bone in the creature's skeleton and creates a cylinder at the bone's position, with bone length and orientation. The phys bodies would ignore collisions with other parts of the skeleton, but not external objects. The position and orientation of each body would then be updated every frame. Is this a viable option?

I'm not really worried about a working ragdoll (although it would be nice to have that functionality), what I need is a simple collision hull that follows the configuration of the spider's bones as it moves around, knocking objects over and so on.

lonwolf

28-08-2006 19:53:53

now that is indeed tricky. You could try to do what you've been trying but im not sure if its really good for the simulation performance. Assuming you wont have a lot of complex meshes though it should work. But i didnt get why do you need that kind of body. *What do you expect that spider will react? Just like in real world?*

But another thing that ive remarked whilst using Onewt: If u update body pos and orientation manually the bodyes wont follow the "rule of coliding", that is for example: if you have lets say a human character. And you want to make him jump by updating this every frame:
human_body->getPositionOrientation(pos, orn);
pos.y+=0.05f;
human_body->setPositionOrientation(pos, orn);


your character will perform a nice climbing up neglecting gravity, and once youve stopped the "jump", grvaity will do the rest. However, if underneath the maximum height reached by the "jumper" is a body, the 2 wont collide, unless you throw the human body with a force or velocity UP, then if he hits something it will bounce off. But if you use setPosOrn it will pass though as if nothing was there.

Take a moment to understand this concept and then answer the first question i asked in this reply

SFAOK

29-08-2006 14:56:34

Take a moment to understand this concept and then answer the first question i asked in this reply
Hmmm yes the fact that changing the position/orientation of the body won't result in collisions indicates that my original idea won't work :( It is far more likely for the legs to strike an object in the environment than an object in the environment striking the legs, so most of the collisions would indeed be the leg pushing/hitting some external object.

The skeleton of the spider uses inverse kinematics to move around the environment, deforming the actual mesh (and therefore the legs) as it does so. What I would like is for the physics 'body' to move in the same manner, so that there is a rough approximation of where each leg is.

Is OgreNewt even capable of having a hull body deform to the same configuration as a (pre made) animation? For example, having the ninja mesh that comes with Ogre do the walk animation across a plane with a corresponding hull body underneath deforming with the skeleton/mesh? Although my simulation doesn't use any animations, it could be a place to start.

lonwolf

29-08-2006 18:58:05

That is a question walaber is most likely to know the answer. I once tryed the hull colision but the result wasnt what i needed and abandoned the ideea. So every body in our game moves with velocity and forces. From experience i learned that a body in newton cannot follow a mesh's animation, so you will have to deal with non-shape-changing bodyes :lol:
weird, but i cannot say i know the hull colision properly. Although you need to solve this problem using some joints to keep the bodyes toghether or use a compound colision. But the compound colision isnt mobile. Its fixed. So it kind of ragdoll/joints/forces problem but i do not think you can implement succesfully that solution. Simulating with accuracy a real spiders movement is something newton isnt capable of at the moment of speaking (thats my opinion). You shoul ask walaber though, he knows every aspect of this engine. Or just wait untill he replys to this topic :?

walaber

30-08-2006 05:32:54

I know I haven't posted in this topic yet, but I've been reading it. this project looks really interesting.

I have a few questions, I'm sorry if they've already been answered.

1. What do you want to "do" with the collision information? do you want the spider to interact dynamically with other physics objects? or do you just want the be informed when collision happens?

if you want a dynamic spider, you will need to make a separate rigid body for each "limb" or piece of the spider, and connect them with joints. These joints can then be "powered" to try and reach a goal orientation (which is from your IK solver). I have been working on something similar myself, and would be willing to explain the process if you are interested. It is not simple though, and requires creating custom joints to solve the problem.

let me know exactly what you want to accomplish as an end result, and I can try to help you to the best of my knowledge.

OvermindDL1

30-08-2006 23:11:56

I'd be interested to hear about your IK solver if no one else does.

SFAOK

15-02-2007 17:47:13

I put this part on hold whilst I did other things, but I've come back to it now. So *bump*


I have a few questions, I'm sorry if they've already been answered.

1. What do you want to "do" with the collision information? do you want the spider to interact dynamically with other physics objects? or do you just want the be informed when collision happens?

I need to have the limbs physically simulated in order to have them bump against other objects in the environment. This might be just a stack of boxes in an abstract simulation (i.e where a spider can actually knock boxes around with its legs), or a 'real' environment where objects are things like leaves and pebbles.

I also want to identify collisions - for example the spider can completely ignore things below a certain mass (in other words pushing them out of the way), but on other occasions I want the creature to realise its leg has collided with a heavy object and needs to stop moving and adjust.

Most of this code is already there, but as only the 'target node' is physically simulated, you get ugly situations where the leg goes straight through objects, even if the foot doesn't.


if you want a dynamic spider, you will need to make a separate rigid body for each "limb" or piece of the spider, and connect them with joints. These joints can then be "powered" to try and reach a goal orientation (which is from your IK solver). I have been working on something similar myself, and would be willing to explain the process if you are interested. It is not simple though, and requires creating custom joints to solve the problem.

If you haven't totally forgotten, I'd be very interested in this. Did you manage to get anywhere?

Here's how I planned doing it for each leg:


1. For each bone in the leg, create a rigid body (lets say a rectangle) which represents the leg segment's collision primitive, taking the position and orientation of the bone from the skeleton.

2. Join each segment together with a joint : X-Axis hinge for root joint, Z-axis hinge for all the child joints (keeping it simple).

3. Apply Inverse Kinematics algorithm, which rotate the joints by a small angle each update.

This is where I get stuck. How exactly would I translate the (float degree) angle into actual rotation of the joints? I made a test chain of bones and joints, but I couldn't for the life of me figure out how to rotate a specific joint and have all the parent joints remain still whilst the child ones inherit the rotation of the current joint.

4. Apply restrictions, springs etc.

5. Translate/Rotate the bones to the rigid body's updated positions.


I'd love to have this functionality - it would greatly aid the simulation.

walaber

15-02-2007 23:28:16

you have to use "custom joints" for this, but what you are describing is actually pretty simple, once you get your head around how custom joints work with Newton.

If I can find it, I will post a custom hinge joint that I made, that allows you to specify a goal angle, and it will try to maintain that angle always... I used this to take skeletal animation and plug it into a fully physics-based articulated model once, and it actually worked quite nicely.

SFAOK

16-02-2007 13:11:12

you have to use "custom joints" for this, but what you are describing is actually pretty simple, once you get your head around how custom joints work with Newton.

If I can find it, I will post a custom hinge joint that I made, that allows you to specify a goal angle, and it will try to maintain that angle always... I used this to take skeletal animation and plug it into a fully physics-based articulated model once, and it actually worked quite nicely.

This would be a fantastic starting point if you manage to find it!

I've been looking at the custom joints tutorial, but I just can't get one joint to rotate around another by an angle - once I've got that, converting the IK system should be relatively straightforward! :P

iversons

26-03-2007 04:59:44

Hi walaber,

As you mentioned, we can apply the custom joints to skeleton? How can we do so? quite funny!
Thanks!



you have to use "custom joints" for this, but what you are describing is actually pretty simple, once you get your head around how custom joints work with Newton.

If I can find it, I will post a custom hinge joint that I made, that allows you to specify a goal angle, and it will try to maintain that angle always... I used this to take skeletal animation and plug it into a fully physics-based articulated model once, and it actually worked quite nicely.

SFAOK

12-04-2007 13:17:09

Just bumping this! Any sign of the custom joint code walaber?
Cheers

walaber

12-04-2007 18:17:22

I keep forgetting about this one :)

I have the code, it's not for Ogre though... so I'll see what I can do to post it.