NxOgre + simulate() + fetchResults()

al2950

01-10-2009 19:31:08

I have been stepping through the NxOgre code line by line and i have come across something that i not seem quite right or atleast i dont understand why it is the way it is!!

When you call update in NxOgre it seems to do the following;
1) call the PhysX simulate method
2) call the PhysX fetchResults method
3) update the objects in Ogre/Glut with the new data

When looking at this and looking at the PhysX examples it does not seem right to me, as should you not call simulate() at the end so the PhysX threads have a whole Ogre frame to crunch numbers before you call fetchResults()? (The reason i say this is becuase that is how it is in the PhysX examples

I relise that in doing this then everyone has to be aware of this;
Every time we hit “t”, we call NxActor::setGlobalPosition(NxVec3(0,5,0)) on our box actor. This places the actor at a position 5 units above the origin.

As with adding forces, we need to do this in between the NxScene::fetchResults() call in GetPhysicsResults() and the NxScene::simulate() call in StartPhysics()). It is an input to the physics scene which we need to perform while the scene is not being calculated by the hardware.


but it would alteast be nice to have the option to call NxOgre::simulate() and NxOgre::fetchResults() seperately from our render loop?

I appologise if i have once again got things completely wrong, i dont mean to pick holes in this great library/plugin, just curious!! :D

betajaen

01-10-2009 21:05:49

I prefer simulate/fetch myself, but you can do it both ways.

NxOgre has a whole timer listener system based on priorities. They are called when you call TimeController::advance().

If you are a timer listener, you need to give out a priority of when you will be called first over others. Scene is a TimerListener and subscribes to the timer controller twice; one for simulating and a second for fetching.

Normally; Simulating is at High and fetching is at MediumHigh. So the order is Simulate then Fetch, but there is no reason why you can't swap them around.

SceneDescription desc;
desc.mProcessingPriority = Enums::Priority_MediumHigh;
desc.mFetchingPriority = Enums::Priority_High;

mWorld->createScene(desc);


I'm almost positive I've tried it out this way when I first designed it, and it worked. But go ahead and see how it well it works with you.

al2950

01-10-2009 21:44:18

ok, thats what i thought. I will give it a try!!

The only probelm is that the PhysX SDK states that you should not move or add forces to any actors between the Simulate() and fetchResults() methods. ie you must update the positions and forces on your objects after you call fetchResults() and before you call simulate(). So in my view switching the priority might cause probelms.

What i would like do is call fetchResults() at the begining of my main Ogre loop and then call simulate() just before I render the scene. Would this be difficult to do!!??

Cheers

Gus

betajaen

01-10-2009 21:52:54

A bit; I would have to modify the TimeController to allow you fire off specific TimeListeners based of priorities.

I do have an idea though; You can make your own timing code a time listener, and nudge it between the fetch/simulate code.

al2950

01-10-2009 22:26:15

Thats not a bad plan, i might try and give that a go tomorrow. I might also try and add an extra layer so that when a user calls a setPosition, addForce ...etc command, it stores the command and only actually executes those commands when NxOgre says (ie between fetchResults and simulate). Or am i just over complicating things!