Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Time based movement question.

Author
Message
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 16th May 2008 20:13
Hi, im trying to do some Time based movement,in need to move a object 0.08641975437417443 units (or another small value)in 0.04330126610528065 seconds (or another small value).
Obviously this must be framerate independent.

thanks on advance
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 16th May 2008 20:58
[href]http://code.google.com/p/darkgdkoop/

there is a timer class and a clock class. In your case I think you should download this lib, and see how in the very end of the GUI demo... where I spen the cube, its using the dbTimer function to turn it. You'll from there, that the jgc_clock class is all you need.

enjoy

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 19th May 2008 20:32
Thanks for your reply
tobi453
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 19th May 2008 21:27
I do it this way:



FINAL VERSION RELEASED!!!!
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 19th May 2008 22:04 Edited at: 19th May 2008 22:13
hey tobi453.
Im using something like that ,but more simple.

I will try your code, thanks.

EDIT: ive tried it, everything moves really fast !
that " *60.0f+dt)/2; " bit, maybe be the culprit.


oh and i use the timefactor like this:

where METER is a value like 0.9 (is just in case if later i need scaling)

Cheers
tobi453
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 19th May 2008 22:35
hi FERSIS,

the (...+dt)/2 makes the movement more smoothly.

FINAL VERSION RELEASED!!!!
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 19th May 2008 23:09
Sure , i understand that.
But when i applyed that bit, the speed of the movement increased a lot.
Maybe i will look again later.
Cheers
tobi453
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 19th May 2008 23:35
hi fersis,

I think the problem is that I use speed/frame (60fps) and you use speed/second. Replace the 60 by a 1 and the speed should be normal.

FINAL VERSION RELEASED!!!!
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 20th May 2008 15:15
now is working fine.
thank you
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st May 2008 18:22
Ferris.... I figured you didn't want to DL a big library - and Tobi's code is perfect... I thought I'd post the class I was talking about so you can see how I copy the elapsed time into a float ONE TIME, and then code can use the float version over and over versus converting the int to float repeatedly in your main loop which eats clock cycles if done frequently etc.

jgc_clock.h


jgc_clock.cpp


You basically declare it in the top of your program:

JGC_CLOCK *Clock=new JGC_CLOCK();

then in your main loop you would call this:
Clock->Update();

Then you can use either the integer or float "TimeElapsed" value as many times as you need - recycling the math and the data type conversion to float - to your advantage.



If timefactor is something you use alot, you might add that to the JGC_CLOCK class so its in a contextual appropriate place - "available in the clock" LOL.

Then when your program is shutting down you would:

delete Clock;


Good Luck! Sounds like you're off and running anyways - but this is just another way to skin the proverbial... Cat.

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 21st May 2008 22:40 Edited at: 21st May 2008 22:41
Is not that i dont want to use your library
Is that i dont know that 'them' would allow me to use a 3rd party library. (i think that for legal stuff).
Thank you very much for showing your clock class , jason.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st May 2008 23:25
Sure - no problem - but note how I am trying to encourage you to do the math in one place, and convert to a float all the "math" calc'd values you may need later in code - so you can use them over and over rather than:

int timediff = iTimeNew - iTimeOld;

and then doing stuff like dbMoveObject(12.5 * timediff);

better to use a float version of timediff.

Login to post a reply

Server time is: 2024-11-20 11:31:41
Your offset time is: 2024-11-20 11:31:41