Looking for Startup Example

Gatekeeper

24-05-2008 19:19:04

I have been looking at the forums to see if I can determine which physics engine to use.

Right now NxOgre+Physx seems the most interesting to me.

Can someone point me to sample code that uses NxOgre with Ogre?

Maybe a startup example for a simple app that will detect collisions and prevent camera from moving into objects?

Thx,
G

betajaen

24-05-2008 19:51:19

Cake usually to embed NxOgre into your application. But it takes only 2-3 lines to integrate NxOgre into your application, so it's upto you if you want to get Cake running.

And I've posted some code recently that makes the Camera collide with the Scene. Try searching for "camera actor" and posts made by me.

Gatekeeper

25-05-2008 13:45:40

Thanks.
I dont only want collision detection. Thats what I want initially, but certainly will be interested in other physics elements.

From this perspective do you still recommend opcode as the "defacto" collision detection library, or should I start right off with something like physx and nxogre, or newton and ogrenew?

Thanks again.

betajaen

25-05-2008 13:49:34

If you just want collision detection and you do your own response in your own application then Opcode.

If you want collision detection and a response, then you should use a physics library. I'm very bias towards PhysX, but Bullet is nice too.

Gatekeeper

25-05-2008 14:01:47

Thank you once again.
Physx+NxOgre it is!

Gatekeeper

27-05-2008 14:13:54


And I've posted some code recently that makes the Camera collide with the Scene. Try searching for "camera actor" and posts made by me.


I've searched for camera actor posts by you. I only found 4 posts, and none of these seem to be right.

betajaen

27-05-2008 14:17:01

It's the first one.

http://www.ogre3d.org/phpBB2addons/view ... 1773#41773

Gatekeeper

27-05-2008 14:23:55

I see. Thanks. This shows me how to create a "physics body", and I'll play with this immediately. Can you also point me to some sample code that "detects when a camera" bumps into an object, in order to prevent the camera from doing this?

Thanks in advance,
Gatekeeper

Gatekeeper

27-05-2008 17:25:03

Compiled, linked, running in a test program, but not yet seeing an object:

The following test code is what I've been using. This is part of the "createScene" method in a test program that is built off of one of the ogre demos. This test code also displays objects from a "dotscene" file exported from blender (that works just fine). Lastly it displays a couple of fixed meshes on top of the dotscene import.


//start of new crap
Ogre::Entity *e;
MeshPtr m = MeshManager::getSingleton().load("ogrehead.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
unsigned short src, dest;
if (!m->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
{
m->buildTangentVectors(VES_TANGENT, src, dest);
}

CDotScene ds;
SceneNode* sceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
ds.parseDotScene("Scene.xml", "General", mSceneMgr, sceneNode);

e = mSceneMgr->createEntity("head", "ogrehead.mesh");
e->setMaterialName("Ogre/Skin");
SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
headNode->attachObject(e);
headNode->setScale(3.7,3.7,3.7);
headNode->setPosition(0,200,300);
e->setNormaliseNormals(true);

e = mSceneMgr->createEntity("cube", "cube.mesh");
e->setMaterialName("Ogre/Skin");
SceneNode* cubeNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
cubeNode->attachObject(e);
cubeNode->setScale(1.7,1.7,1.7);
cubeNode->setPosition(0,200,500);
e->setNormaliseNormals(true);

NxOgre::World world;
NxOgre::Scene *scene = world.createScene("the world", mSceneMgr);

NxOgre::ActorParams actorParams;
actorParams.setToDefault();
actorParams.mMass = 1;
actorParams.mDensity = 0;
actorParams.mLinearDamping = 10;
actorParams.mAngularDamping = 10;
actorParams.mBodyFlags |= NX_BF_DISABLE_GRAVITY;
actorParams.mBodyFlags |= NX_BF_FROZEN_ROT;

NxOgre::Pose actorPose(
Vector3(1.5,-2,0)
);

NxOgre::Body *b = scene->createBody("CakeSmartCamera", new NxOgre::Sphere(10.25f), actorPose, actorParams);



The last few lines are the NxOgre code where I "create the world", "create a scene", and then create a "sphere within the scene". Right now I'm not seeing the sphere. What else do I need to do in order to see the sphere?

Gatekeeper

27-05-2008 18:23:44

I think the answer to my question is "nxogre is not a renderer so it wont render your sphere, it will simply apply physics to it". So assuming that this is the answer, let me rephrase the question, how can I associate the ogrehead created within this example (which is indeed being rendered) with the actor that I want to assign some physics to?

betajaen

27-05-2008 18:46:32

Very bad. Very bad.

NxOgre::World* mWorld;
NxOgre::Scene *mScene = mWorld->createScene("theScene", mSceneMgr);

mScene->createBody("mesh.mesh", new Cube(1.0f), Vector3(0, 10, 0), "mass: 10");



First. Make your variables; member variables. I'm surprised your application didn't crash after that function exited. Start simple, spawn a cube. Then fiddle with that.

And NxOgre will render your sphere or whatever, if you tell it too.

Gatekeeper

27-05-2008 19:02:30

Ya.. very sloppy code no doubt in my initial test setup. I actually went ahead and made the world a member variable as i was mucking around, and ended up seeing stuff rendering, (and then stumbled on your response). Once I get some basic functions working then I will certainly start my real application from scratch.

The end result is that I was indeed able to render a mesh instantiated as an NxOgre::Body, and I was able to see this alongside other Ogre entities being rendered within my app (for example those loaded from the dotscene file).

The two fundamental changes are represented in the following two lines:


NxOgre::Scene *scene = mWorld.createScene("Main", mSceneMgr, "gravity: yes, floor: yes, renderer: ogre");



Notice here that I specify the "gravity: yes, floor: yes, renderer: ogre" string. I did not have this in the initial code. Also I am using "mWorld" here .. a member of my test application class.

The second line is:


NxOgre::Body *b1 = scene->createBody("mycube;ogrehead.mesh", cube, NxOgre::Pose(Ogre::Vector3(10.0f,10.0f,10.0f)), actorParams);


I have run the code and I successfully see the "ogrehead" or any other mesh that i might specify in the first param of createBody. I found it very interesting that my "ogrehead" was textured by default. This seems odd since I didnt set a material on this entity.

I've also dropped the following line of code in my frame listener:


mWorld->simulate(evt.timeSinceLastEvent);



so far no observable physical behaviour for this ogrehead. I'm starting to play with the ActorParams specified for this Actor.

Two quick questions:
1] Why was there a default texture associated with the OgreHead? This texture was such that I was able to see the "ogre earrings, eyes, and head" as distinctly textured elements.

2] How can I apply an already instantiated (and materialed) Ogre::Entity to an Actor (or Body).


Thanks for all the responses.. I'm starting to make some headway.

betajaen

27-05-2008 19:12:06

1. Because this is a natural Ogre behaviour. You don't need to tell each mesh to use a material, the material name is in the mesh itself, which Ogre looks up and uses.

2. Off the top of my head.

mBody = mScene->createBody("body-name", new Cube(1), Vector3(0,1,0), "model: entity-name, model-type: reference", "mass: 10");


Also; I wouldn't use the Ogre Head as a mesh to use in NxOgre. It's a horrible mesh to physically calculate, and it's huge. Skyscraper huge.

Gatekeeper

27-05-2008 19:58:06

1. Because this is a natural Ogre behaviour. You don't need to tell each mesh to use a material, the material name is in the mesh itself, which Ogre looks up and uses.


Didnt realize that .. always created and applied my materials separately never counting on that.. very good to know.



2. Off the top of my head.

mBody = mScene->createBody("body-name", new Cube(1), Vector3(0,1,0), "model: entity-name, model-type: reference", "mass: 10");



That seems to work.



Also; I wouldn't use the Ogre Head as a mesh to use in NxOgre. It's a horrible mesh to physically calculate, and it's huge. Skyscraper huge.


Didnt know that either, though I would have thought that it was not much larger than a typical detailed character model (for example a WoW NPC).

I'm calling the world "render" and "simulate" methods within my framelistener. I also applied a force to the body I created. Not seeing any motion, what else am I missing?

Startup code:


NxOgre::Scene *scene = mWorld.createScene("Main", mSceneMgr, "gravity: yes, floor: yes, renderer: ogre, time-controller: ogre");

NxOgre::ActorParams actorParams;
actorParams.setToDefault();
actorParams.mMass = 1;
actorParams.mDensity = 0;
actorParams.mLinearDamping = 10;
actorParams.mAngularDamping = 10;
actorParams.mBodyFlags |= NX_BF_DISABLE_GRAVITY;
actorParams.mBodyFlags |= NX_BF_FROZEN_ROT;

NxOgre::Pose actorPose(Vector3(10,0,0));
NxOgre::Cube *cube = new NxOgre::Cube(NxVec3(10,1,1));
NxOgre::Body *b1 = scene->createBody("mycube;ogrehead.mesh", cube, NxOgre::Pose(Ogre::Vector3(1.0f,1.0f,1.0f)), actorParams);
NxOgre::Body *b2 = scene->createBody("cube-body", new NxOgre::Cube(1), Vector3(0,1,0), "model: cube, model-type: reference", "mass: 10");

b1->addForce(21.0, 20.0, 0.0);
b2->addForce(1,0,0);



Frame Listener Code:

bool frameStarted(const FrameEvent& evt)
{

mWorld->simulate(evt.timeSinceLastEvent);
mWorld->render(evt.timeSinceLastEvent);
// Rotate fountains
// mFountainNode->yaw(evt.timeSinceLastFrame * 30);

// Call default
return ExampleFrameListener::frameStarted(evt);

}

betajaen

27-05-2008 20:02:37

These questions are getting very tedious, all of this can be either found out via the search. Or reading the shortguide. I don't like repeating myself.

First. Make World a pointer.

Second you don't simulate/render the world yourself, NxOgre does, provide these params to world "time-controller: ogre"

Third; Drop the Actor/Camera code for now. Your obviously new to this and have no idea what it means. Just play with cubes and spheres until you understand it all.

Gatekeeper

27-05-2008 20:15:20

So Nice!! Thanks I'll do that.