making entities collidable in ogre and nxogre

bwyyoung

05-07-2008 09:20:38

Hello,

I am new to using NxOgre, and I have a very important question.

I have created entities and nodes in Ogre. Below is an example of the creation of an entity from a 3d model or mesh.

Entity* newEntity = SceneManager->createEntity(objectname, object);

Then, I attach the entity to the scene.
node=SceneManager->getRootSceneNode()->createChildSceneNode();
node->attachObject(newEntity);

Now that I have these 2 things, how is it that the entity or node get registered an part of an actor or body in NXOgre? If it becomes an actor or body, and is part of NXOgre's scene. Will the actor/body update itself with the node/entity's new position each frame? what is the overall procedure and way to make it become part of it? How does the actor/body find out about the coordinates of the bounding box of the entity/node? Please help.

Thank you.

betajaen

05-07-2008 09:58:11

Sometimes it is better for NxOgre to do that for you, but if you have to create the entity/scenenode before the body then you can associate with it, NxOgre will treat it as one as it's own and move and orientate it every time the Actor moves.

Roughly, it goes:

Entity* newEntity = SceneManager->createEntity(objectname, object);
node=SceneManager->getRootSceneNode()->createChildSceneNode();
node->attachObject(newEntity);

mBody = mScene->createBody("someName", new Cube(1), NxOgre::Pose(node->getPosition(), node->getOrientation()), "identifier: " + node->getName() + ", usage: use", "mass: 10");


You will have to set up a collision model based on the overall shape of the mesh; in this case I used a cube, but you can use a sphere if it's round, or mix and match with a ShapeGroup. Do not use a TriangleMesh it will not work.

bwyyoung

05-07-2008 17:16:17

Hey Betajaen,

Thanks for your reply. Is there a reference page to all possible parameters that can be passed to the body? I cant seem to find a comprehensive one.

Also, I have tried setting the global position of the body in my game update. However, my model starts spinning like crazy. Why is that so? I have set the mass to 0, and hoped that gravity would not affect it.

I set the position like so:

mBody->getNxActor()->setGlobalPosition(NxVec3(pos.x,pos.y,pos.z));

What is the difference between setting the orientation and position of the body, and that of the actor directly by getNxActor()?

bwyyoung

betajaen

05-07-2008 17:28:40

For ActorParams and NodeRenderableParams? No. But after a while you'll move over to the Class style param system and find everything much faster to work with.

ActorParams ap;
ap.setToDefault();
ap.mMass = 10.0f

mBody = mScene->createBody("a;test.mesh", new Cube(1), Vector3(0,1,0), ap);


Faster, and works with intellisense!

bwyyoung

05-07-2008 18:10:34

Also, I have tried setting the global position of the body in my game update. However, my model starts spinning like crazy. Why is that so? I have set the mass to 0, and hoped that gravity would not affect it.

I set the position like so:


mBody->getNxActor()->setGlobalPosition(NxVec3(pos.x,pos.y,pos.z));



What is the difference between setting the orientation and position of the body, and that of the actor directly by getNxActor()?

bwyyoung

betajaen

05-07-2008 18:25:01

Same thing, but my way is nicer.

PhysX doesn't really like you "teleporting" things around; If you need to move something relative to another then use addForce or setLinearVelocity. If you need to teleport something; make sure there is enough room so it doesn't clip another actor.

bwyyoung

06-07-2008 06:42:40

Hey Betajaen,

Thanks for your help! I really appreciate it. now I only need to find a quick solution to visualise the bounding box. Do you have any suggestions?

bwyyoung

Gohla

06-07-2008 09:07:13

Hey Betajaen,

Thanks for your help! I really appreciate it. now I only need to find a quick solution to visualise the bounding box. Do you have any suggestions?

bwyyoung
The Ogre or PhysX bounding box?

Physx: http://www.ogre3d.org/phpBB2addons/view ... ght=#43603 (the search function is your friend ;))

Ogre: mSceneNode->showBoundingBox(true);

bwyyoung

06-07-2008 09:31:32

Thanks Gohla,

But my problem is, I want to set the bounding box of physx to be of the same dimensions of my Entity bounding box. How do I ensure that?

Bwyyoung

betajaen

06-07-2008 09:59:22

Getting the BoundingBox is an Ogre thing, from that it's easy to work out the size of it and applying it to a Cube.

Ogre::AxisAlignedBox propAAB = node->getAttachedObject("entity" )->getBoundingBox();

mkandula

10-09-2008 13:20:25

Hi,

I am trying to attach my ogre entity with the NxOgre body.

When I do this,


NxOgre::Body *mBody = mScene->createBody(meshtouse, new NxOgre::Capsule(radius, 2*radius),
NxOgre::Pose(node->getPosition(), node->getOrientation()), "identifier: " + node->getName() + ", usage: use", "mass: 10");
[\code]


I am getting a crash saying:

OGRE_EXCEPTION(ITEM_IDENTITY_EXCEPTION) a scene node with the node's name is already existing in OctreeSceneManager::CreateSceneNode

How should I do what I am trying to do ??
In the above example is the node not attached to the SceneManager ??
Is the NxOgre::Body attached using the node's name ? Can it be not be done with a pointer ?

----------------
this has been answered here...
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=8132
---------------