Pausing NxOgre Simulation and Render

frier

27-10-2007 09:52:57

Easy question hopefully, how do i pause and restart PhysX timestepping(i think thats how you word it).

Since i want to start introducing some code that pauses the game mid play and pull sup the main menu.

Thanks
-FrieR

betajaen

27-10-2007 10:06:45

mWorld->getPhysXDriver()->setTimeModifier(0);
// ...
mWorld->getPhysXDriver()->setTimeModifier(1);

frier

27-10-2007 12:03:33

Thanks Betajaen, it stops the simulation and everything fine... but then


mWorld->getPhysXDriver()->setTimeModifier(1);


Didn't resume it?

betajaen

27-10-2007 12:11:52

It should do. Otherwise you could disable the framelistener, and just control it by hand; World->PhysXDriver->Simulate/Render when not paused.

frier

06-11-2007 15:45:02

Hey Betajean it did end up pausing my code using the first method you told me, forgot about this thread.

Though i found it still runs the simulate and render callbacks when im paused, id assume ill have to do the next step where i have to disable the framelistener?

solaris1912

12-03-2008 14:05:42

I paused the simulation as you have mentioned. I set the time modified to 0, the physics stopped but the screen went black. Physics continued when I set time modifier to 1 and everything is rendered correctly again. Is there a way to continue rendering but stopping physics?

I have no intention to hijack this thread, I just think these are somehow connected.

Thanks!

EDIT: if there are no moving objects in the scene at that time, the screen does not go black.

solaris1912

13-03-2008 11:37:20

Here is more info; when I stop physics as suggested, I have to make the camera still. If the camera moves as the physics is stopped, then the screen goes black. If the camera stays still, the screen does not go black.

EDIT: so I cant have the "matrix" effect... :/

nargil

14-10-2008 19:00:19

How is it (pause simulation) done with 1.0.22 ?

mWorld->getPhysXDriver()->

doesn't have a setTimeModifier() method;

betajaen

14-10-2008 19:17:42

Usually it is best to create your own frameListener and tell NxOgre not to mWorld->new World("time-controller: none");

Then inject time events (mWorld->getPhysXDriver()->simulate()/render()) when you need to and how much.

Prophet

14-10-2008 19:30:34

Hm. Is it possible to freeze all/selected items? Say I have a number of boxes that are falling and the I want to freeze them in the air and then let another box tumble down between them?

betajaen

14-10-2008 19:40:12

Raise the NX_BF_FROZEN flag?

Prophet

14-10-2008 21:46:46

Simple as cake. Thanks!

NoodlesOnMyBack

15-10-2008 02:20:19

I update the simulation manually, and also limit the update rates to 100 FPS to reduce speed performance differences between different computers, and you can make some slow motion effects or fastforward...:
But i guess you already found the solution...



//Set the time step to our own
mWorld = new NxOgre::World("time-controller: ogre, framelistener: no");

static Ogre::Timer timer;
float ElapsedTime = float(timer.getMilliseconds());
int dwFPSLimit = 100; //Limit the FPS so the physics never reach an insane speed
float dwCurrentTime = 0;
static DWORD dwLastFrameTime = 0;

while (running) {

Ogre::WindowEventUtilities::messagePump();
captureInput();
updateStats();

if (keys->isKeyDown(OIS::KC_ESCAPE))
running = false;

handleCamera(ElapsedTime);

dwCurrentTime = timer.getMilliseconds();
ElapsedTime = (dwCurrentTime - dwLastFrameTime);

if (ElapsedTime > (1000 / dwFPSLimit)) //Limited to 100 FPS, to prevent super fast speeds
{
//Physics update
mPW->simulate(ElapsedTime);
mRoot->renderOneFrame();

dwLastFrameTime = dwCurrentTime;
}

}

betajaen

15-10-2008 09:31:58

If your going at 100 times a second and your using the accumulator (why wouldn't you? :P ). Make sure it's set at 1/100 rather than 1/60, else you'll have a slightly slower NxOgre, as it tends to ignore the timestep given.

NoodlesOnMyBack

15-10-2008 17:00:12

If your going at 100 times a second and your using the accumulator (why wouldn't you? :P ). Make sure it's set at 1/100 rather than 1/60, else you'll have a slightly slower NxOgre, as it tends to ignore the timestep given.


mWorld = new NxOgre::World("time-controller: ogre, framelistener: no");


I have it set like this, so it should follow my update rates...

betajaen

15-10-2008 17:40:43

Not really.

The accumulator has it's own timer; although you are injecting time events regularly, it will spread out the "60 simulations" across the 100 FPS you have injected in the second.

Prophet

15-10-2008 19:02:06

I've wondered how you manually control NxOgre, frame rate independently. And I reckon more have questions. Perhaps a tutorial is justified?

betajaen

15-10-2008 19:29:34

Yep, I agree.

NoodlesOnMyBack

16-10-2008 18:17:51

So my code was useless :lol: Well, not useless but the physics never reached the 100 FPS updates, just to solve it now, is there a way to tell NxOgre that i want total control over the timing?

betajaen

16-10-2008 18:39:26

You need to modify the accumulator to inject 0.01 updates instead of 0.01667, sounds difficult but it isn't really.

Prophet

18-10-2008 10:29:39

I tried some, and while it works, I'm not sure it's the right approach. So, this is how I do:
  1. Set the worlds time-controller to TC_NONE[/*:m]
  2. Set the scenes controller to CN_ACCUMULATOR and renderer to RN_OGRE[/*:m]
  3. Use this code to simulate and renderthis->nWorld->simulate (this->oRoot->getTimer()->getMilliseconds());
    this->nWorld->render (this->oRoot->getTimer()->getMilliseconds());
    this->oRoot->renderOneFrame();
    this->oRoot->getTimer()->reset();
    [/*:m][/list:o]
    So, how am I doing? Totally worthless or perhaps useful? I'm asking since I thought someone has to write that damn tutorial. (And betajaen is too busy)