Resizing a collision object.

HexDump

26-12-2007 14:48:21

Hi all,

I have a little problem. In my game entites can be resized, so I need to resize collision objects too (the one added to the bodies). I can´t see any method in the collision object to acomplish this, am I suposed to delete/new anytime I resize a gameobject and by extesion its collision object? I think this will produce low performance.

By the way I have found another problem in the mean time. I have a box collision that have created with an offset. If I place my gameobject at 0,0,0 mesh + collision are at same place, but when I put the game object at for example 0,0,10, only the collision goes there not the mesh (Set position is just a Node->SetPosition(), and I have done a pBody->AttachToNode()). Do anybody know what coud be happening?

Thanks in advance,
HexDump.

walaber

27-12-2007 07:32:04

attachToNode is a bit misleading... it won't update the physics object if you call setPosition() on the Ogre node, but the opposite works, so if you call setPositionOrientation on the body, the Ogre node will also be updated.

hopefully that answers your question...

pra

27-12-2007 14:38:43

i guess you have to create a new collision, with the new size, and then set it to the body.


btw walaber, why have you called it "attachToNode" in the first place?^^

HexDump

27-12-2007 22:43:53

pra: Thnx for the answer but this is pretty inapropiate if size is changing a lot :(. Don´t want to do lota new/deletes.

walaber: Thnx for the answer, it clarified things a lot but I have a little problem again. I have a gameobject that holds a scenenode, from with I take position, rotation, etc... When I init the gameobject I pass the position, rotation and scale. Later when I want to init the physics component (yes my entities use component paradigm), I find myself with the problem to clean the scene node first and call later setPositionOrientation to let the physics take care of the node position/rotation, but it doesn´t work, the code I´m using is:

SceneNode* sn=p->GetSceneNode();
Vector3 pos=sn->getPosition();
Quaternion q=sn->getOrientation();

sn->setPosition(Vector3::ZERO);
sn->setOrientation(Quaternion::IDENTITY);
sn->setScale(Vector3::UNIT_SCALE);
m_pBody->setPositionOrientation(pos,q);

As you can see, I try to clean the Node to its creation state, to let the physics move, and rotate the object using the position/rotation I first pased to the entity. With this I get strange results, rigid body not rotating but the mesh does, etc...

If I use setPositionOrientation on a node that has not been manipulated previously it does the job.

Is there any way to use setPositionOrientation on a node that has been touched before?. How can I clean it?

Thanks in advance,
HexDump.

pra

29-12-2007 14:12:47

pra: Thnx for the answer but this is pretty inapropiate if size is changing a lot :(. Don´t want to do lota new/deletes.
maybe you can store all the collisions, and then just swap them?

and for the other part, i don't really understand it :(

banal

13-01-2008 15:49:06

pra: Thnx for the answer but this is pretty inapropiate if size is changing a lot :(. Don´t want to do lota new/deletes.

walaber: Thnx for the answer, it clarified things a lot but I have a little problem again. I have a gameobject that holds a scenenode, from with I take position, rotation, etc... When I init the gameobject I pass the position, rotation and scale. Later when I want to init the physics component (yes my entities use component paradigm), I find myself with the problem to clean the scene node first and call later setPositionOrientation to let the physics take care of the node position/rotation, but it doesn´t work, the code I´m using is:

SceneNode* sn=p->GetSceneNode();
Vector3 pos=sn->getPosition();
Quaternion q=sn->getOrientation();

sn->setPosition(Vector3::ZERO);
sn->setOrientation(Quaternion::IDENTITY);
sn->setScale(Vector3::UNIT_SCALE);
m_pBody->setPositionOrientation(pos,q);

As you can see, I try to clean the Node to its creation state, to let the physics move, and rotate the object using the position/rotation I first pased to the entity. With this I get strange results, rigid body not rotating but the mesh does, etc...

If I use setPositionOrientation on a node that has not been manipulated previously it does the job.

Is there any way to use setPositionOrientation on a node that has been touched before?. How can I clean it?

Thanks in advance,
HexDump.

Hi HexDump

You should not alter the Position, Scale and Orientation of the SceneNode. This will bring it out of "sync" with the Body Object.
Here is how i alter a already rotated Body:

Vector3 vec;

Quaternion quat;

Vector3 pos = Vector3(10, 0, 0); // move body 10 in x axis

Quaternion orient = Quaternion::IDENTITY; // do not change orientation

// get original pos and orientation (body is the OgreNewt::Body object)
body->getPositionOrientation(vec, quat);

// apply the new vector and orientation to the existing one
// we do this, to not break any previous position and orientation changes
body->setPositionOrientation(vec + pos, quat * orient);


I would be interested in an answer regarding the scaling issue as well. It's really annoying if you have to re-create the Bounding Objects every time you want to resize a SceneNode in your simulation.

Edit: changed code snippet for readability