i ned help with reseting start=device->getTimer()->getTime();
it returns time in miliseconds and this is ko but when i want to reset smiulation
i cant because this call doesnt work when it's called in the rendering loop.
any ideas?
thanx
problems with time based movement
try using a timer class
i made one for use with fmorg, here's a link http://buhatkj.dyndns.org:4242/tempfiles/fmorgTimer.h
hope that helps!
-Ted
hope that helps!
-Ted
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
-
- Posts: 26
- Joined: Thu Feb 05, 2004 10:58 pm
-
- Posts: 26
- Joined: Thu Feb 05, 2004 10:58 pm
comments...
well in the comments it shows basically how to use it....
first you declare it thusly:
where your-irrlicht-device is your instance of the main irrlicht device.
then, it has two modes of operation. stopwatch, and alarm clock.
in stopwatch mode, you start the timer with:
and then when you want the elapsed time since the timer was started, you do this:
after which, that integer timeItTook will contain the elapsed time in milliseconds since the timer was started.
it is possible you really want to check the elapsed time again and again, until it reaches some limit. this is what the alarm clock mode is for.
would set the alarm for 5 seconds, and then during you main loop, you would put a condition on the alarm like this:
which will activate the contents of that if statement when the time has elapsed.
at the time i couldnt really think of another way i would want to use a timer, so that was all the methods i wrote for it. its a very simple and i would almost say self-explanatory class i thought, but perhaps there is some functionality i had not thought of to include. if you do write any extension of it, i would love to check out the code, perhaps there is something i missed!
-Ted
first you declare it thusly:
Code: Select all
fmorgTimer myTimer(your-irrlicht-device);
then, it has two modes of operation. stopwatch, and alarm clock.
in stopwatch mode, you start the timer with:
Code: Select all
myTimer.start();
Code: Select all
u32 timeItTook = myTimer.stop();
it is possible you really want to check the elapsed time again and again, until it reaches some limit. this is what the alarm clock mode is for.
Code: Select all
myTimer.set(5000);//this is five seconds
Code: Select all
if(myTimer.alarm())
{
//something you want to do only if 5 seconds have passed...
myTimer.reset();//if you wanna use it again
}
at the time i couldnt really think of another way i would want to use a timer, so that was all the methods i wrote for it. its a very simple and i would almost say self-explanatory class i thought, but perhaps there is some functionality i had not thought of to include. if you do write any extension of it, i would love to check out the code, perhaps there is something i missed!
-Ted
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
-
- Posts: 26
- Joined: Thu Feb 05, 2004 10:58 pm
-
- Posts: 26
- Joined: Thu Feb 05, 2004 10:58 pm
here is some pseudo code:
here is the code i am having trouble with:
//many nasty globals!
u32 timeItTook;
int main()
{
MyEventReceiver receiver;
device=createDevice(video::EDT_DIRECTX9, core::dimension2d<s32>(1024,768),16,true,true,&receiver);
driver = device->getVideoDriver();
guienv = device->getGUIEnvironment();
scene::ISceneManager* smgr = device->getSceneManager();
fmorgTimer myTimer(device);
/*
meshes,guies,cameras and lights
*/
myTimer.start(); //timer start-it works only if it is set here
while(device->run() && driver)
{
if(device->isWindowActive())
{
//myTimer.start(); this wouldnt work,why?
/* so when i want to reset time
and dislay simulation again i cant
*/
driver->beginScene(true, true, video::SColor(0,100,100,100));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
//update camera based on time
if(timeItTook>6000)
if(timeItTook<7000)
updateCamPositionR(u32(timeItTook)-6000);
}
}
device->drop();
return 0;
}
//update camera function definition
void updateCamPositionR(u32 time)
{
time=u32(time/1000);
camPosition.X+=ubrzanjeSkrol*faktorSkrol*3*(time)*(time);
if(camPosition.X>30)
camPosition.X=30;
}
//this is kinda pseudo code
any ideas?
i just cant get this right.
here is the code i am having trouble with:
//many nasty globals!
u32 timeItTook;
int main()
{
MyEventReceiver receiver;
device=createDevice(video::EDT_DIRECTX9, core::dimension2d<s32>(1024,768),16,true,true,&receiver);
driver = device->getVideoDriver();
guienv = device->getGUIEnvironment();
scene::ISceneManager* smgr = device->getSceneManager();
fmorgTimer myTimer(device);
/*
meshes,guies,cameras and lights
*/
myTimer.start(); //timer start-it works only if it is set here
while(device->run() && driver)
{
if(device->isWindowActive())
{
//myTimer.start(); this wouldnt work,why?
/* so when i want to reset time
and dislay simulation again i cant
*/
driver->beginScene(true, true, video::SColor(0,100,100,100));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
//update camera based on time
if(timeItTook>6000)
if(timeItTook<7000)
updateCamPositionR(u32(timeItTook)-6000);
}
}
device->drop();
return 0;
}
//update camera function definition
void updateCamPositionR(u32 time)
{
time=u32(time/1000);
camPosition.X+=ubrzanjeSkrol*faktorSkrol*3*(time)*(time);
if(camPosition.X>30)
camPosition.X=30;
}
//this is kinda pseudo code
any ideas?
i just cant get this right.