Connecting a mesh to an Actor ?

fassihi

11-12-2007 07:51:10

I can create bodies and then attach an entity to the node of the body. In this way I can have a mesh with a physical representation. The physical representation might be a box but the actual mesh is a character.
Physical simulation will be applied on the mesh this way.

Now since I really don't need a visual representation for the bodies, should I be using Actors instead? How can I attach a mesh to an Actor in that case? Actors do not have a node contained.

What is the usual way for providing physical representations to normal meshes in a game?

betajaen

11-12-2007 09:45:24

If you want something physically simulated in the scene but don't want it shown in Ogre; use an Actor, otherwise use a Body.

Actors cannot be used visually, where as Bodies can.

athkast

11-12-2007 09:48:26

This is a great question actually. I am looking over the last few days over and over again and I can't find one clear example of how to do this.

In the shortguide it states that to visualize an actor my objects have to inherit it. But how does this add the visualization functionality? It means that I also have to inherit Ogre::SceneNode? Ogre::Entity?

Let's say I just want to use the NxOgre::Body class. How do you go about doing that? Something like this:
mNxActor1 = mNxScene->createActor("actor1", new NxOgre::CubeShape(1,1,1), NxOgre::Pose(0,50,0), ap );

NxOgre::Body * body1 = mNxScene->createBody("actor1;crateMedioum.mesh", new NxOgre::CubeShape(1,1,1), NxOgre::Pose(0,50,0), ap);


obviously doesn't produce the desired effect (it creates 2 separate actors).

How can I connect an Nx Actor with an Ogre::Entity or Ogre::SceneNode?
(so they update automatically with world->simulate(), I don't want to do this manually for many objects)

betajaen

11-12-2007 09:59:54

Body is an Actor, with a node and entity. It uses the render method inherited by Actor to move the scene node based on the position of the NxActor. Body is just an example, provided by me. But can be used seriously in projects if you want to.

However if you want to make your own Body say Frank. Then for Frank to work it should inherited Actor; Then you add your own SceneNode and Entity, and what ever Ogre or non-Ogre classes you want updated to Frank.

Within Frank's Render method then, you should move the SceneNode and your bits based on the NxActors position (getGlobalPosition(), getGlobalOrientation()).

Once you get over the initial learning hump, you'll find out easy and flexible it is. If you want some extra help, I made a massive comment underneath the Actor class in NxOgreActor.h (Search for "\page customactors"). I think it may be a touch out of date, but it will help.


Of course, I am describing NxOgre 0.9. "Bleeding" is far far different from this.

athkast

11-12-2007 10:09:05

thank you for you quick reply.

So in essence why do have to do this "manually", there is no "behind the scenes" updating.

And what is the code I have to call each frame?

world->simulate () is sufficient? Or should we call simulate to each individual actor each frame?

betajaen

11-12-2007 10:16:42

No you don't call the actors by hand. There is a specific order of how things are done:

mWorld->getPhysXDriver()->simulate(deltaTime);
mWorld->getPhysXDriver()->render(deltaTime);

mgoodman

21-05-2008 02:22:09

Hooray for reviving dead threads from beyond the grave!

OK, so let's say I have a MyEntity class that inherits from Ogre::Entity. I want to create a Body for an instance of MyEntity. Since Scene::createBody doesn't allow to specify the Entity, only the mesh, can I do something like this? (assume the first line correctly creates the entity):

MyEntity* myEntity = CreateMyEntity("EntityName");
Body *myBody = new Body("myBody01", physicsScene);
myBody->setEntity(myEntity);


Will this work, and if not, what is the best way to set the entity? I'd rather not have to create a new class that inherits from Actor, but if I have to I will.

I guess another way of seeing it is if you already have some SceneNodes and Entities created and you'd want to create Bodies for them.

betajaen

21-05-2008 11:24:43

Yes...I think it may. But you may have to create a node too, I can't remember 0.9 that well.