problems with time based movement

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
jugurdzija
Posts: 26
Joined: Thu Feb 05, 2004 10:58 pm

problems with time based movement

Post by jugurdzija »

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
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

try using a timer class

Post by buhatkj »

i made one for use with fmorg, here's a link http://buhatkj.dyndns.org:4242/tempfiles/fmorgTimer.h
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
jugurdzija
Posts: 26
Joined: Thu Feb 05, 2004 10:58 pm

Post by jugurdzija »

well,i tried to use this class but i have bunch of errors like device-undeclared identifier....

i dont know how to organize it.
jugurdzija
Posts: 26
Joined: Thu Feb 05, 2004 10:58 pm

Post by jugurdzija »

i manage to use it but i have a few functions that require elapsed time so i have to add few more methods :(

actually i dnot know how to that
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

comments...

Post by buhatkj »

well in the comments it shows basically how to use it....
first you declare it thusly:

Code: Select all

fmorgTimer myTimer(your-irrlicht-device);
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:

Code: Select all

myTimer.start();
and then when you want the elapsed time since the timer was started, you do this:

Code: Select all

u32 timeItTook = myTimer.stop();
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.

Code: Select all

myTimer.set(5000);//this is five seconds
would set the alarm for 5 seconds, and then during you main loop, you would put a condition on the alarm like this:

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
}
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
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
jugurdzija
Posts: 26
Joined: Thu Feb 05, 2004 10:58 pm

Post by jugurdzija »

thanx for clearing this,it shouldnt be so hard to use this class.
if i encounter any problem i will let you know
anyway i will post some code to make some thing clearer.

thanks again.
jugurdzija
Posts: 26
Joined: Thu Feb 05, 2004 10:58 pm

Post by jugurdzija »

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.
Post Reply