Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,619 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Fixed point precision and terminal velocity/friction issues? #267087
05/21/09 20:53
05/21/09 20:53
Joined: Aug 2002
Posts: 681
Massachusetts, USA
Ichiro Offline OP
User
Ichiro  Offline OP
User

Joined: Aug 2002
Posts: 681
Massachusetts, USA
Hi. I'm using air friction to slow my player object, and seem to be running into a issue with fixed point precision:

> vec_scale(my._speed_x, pow(air_fric, time));

air_fric is something like 0.995, so at 99fps, the pow() will be 0.999, whereas at 10fps, the pow() will be 0.995. So far so good. The problem seems to be that at 20fps, the pow() also resolves to 0.995. It really needs to be something like 0.9955, which is beyond the resolution of a var.

I could cap the player's terminal velocity manually, but that seems crude. Any suggestions?

Thank you.


Dejobaan Games - Bringing you quality video games for over 75 years.
Re: Fixed point precision and terminal velocity/friction issues? [Re: Ichiro] #267089
05/21/09 21:28
05/21/09 21:28
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Code:
vec_scale(my._speed_x, pow(air_fric/2, time)*pow(2, time));

// or
vec_scale(my._speed_x, pow(2, time));
vec_scale(my._speed_x, pow(air_fric/2, time));


edit: or two vec_scales, rather...

Last edited by Joey; 05/22/09 17:09.
Re: Fixed point precision and terminal velocity/friction issues? [Re: Joey] #267400
05/23/09 16:47
05/23/09 16:47
Joined: Aug 2002
Posts: 681
Massachusetts, USA
Ichiro Offline OP
User
Ichiro  Offline OP
User

Joined: Aug 2002
Posts: 681
Massachusetts, USA
Hmm! Thanks; the math is tight, and now I feel embarassed for not realizing that I could separate that out. smile I *think* I want to do this...
Code:
vec_scale(my._speed_x, pow(air_fric*2, time)*pow(0.5, time));

...so as to retain resolution (just off the top of my head, 0.996/2 is identical to either 0.995/2 or 0.997/2 due to the fixed point math). However, either way, I'm still (essentially) hitting different speeds on different systems.

Anything obvious jump out, here?


Dejobaan Games - Bringing you quality video games for over 75 years.
Re: Fixed point precision and terminal velocity/friction issues? [Re: Ichiro] #267434
05/23/09 23:04
05/23/09 23:04
Joined: Apr 2009
Posts: 298
Southern Oceans
KiwiBoy Offline
Member
KiwiBoy  Offline
Member

Joined: Apr 2009
Posts: 298
Southern Oceans
How about time_step; ?


Use the 'manual' Luke, the manual is your friend. 'Self reminder' smile

My WebPage
Re: Fixed point precision and terminal velocity/friction issues? [Re: KiwiBoy] #267729
05/26/09 02:21
05/26/09 02:21
Joined: Oct 2006
Posts: 175
G
Gumby22don Offline
Member
Gumby22don  Offline
Member
G

Joined: Oct 2006
Posts: 175
why not

vec_scale(my._speed_x, pow(air_fric*1000, time)*pow(0.001, time));

Is the resolution problem hit at 3 decimals, or 3 units of precision?

Don
have a great day

Re: Fixed point precision and terminal velocity/friction issues? [Re: Gumby22don] #267979
05/27/09 04:54
05/27/09 04:54
Joined: Aug 2002
Posts: 681
Massachusetts, USA
Ichiro Offline OP
User
Ichiro  Offline OP
User

Joined: Aug 2002
Posts: 681
Massachusetts, USA
Thanks, guys. Ultimately, nothing I've tried has worked yet -- the oddest solution I've tried, based on all of the above, has had things working well at 15fps and 99fps, but not 35fps. wink My next attempt will be to store the velocities as doubles (C++), and update with acceleration and friction entirely there.


Dejobaan Games - Bringing you quality video games for over 75 years.
Re: Fixed point precision and terminal velocity/friction issues? [Re: Ichiro] #267982
05/27/09 05:25
05/27/09 05:25
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
slacer Offline
Expert
slacer  Offline
Expert

Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
Why don't you try to multiply the values by 1000 to preserve otherwise lost precision before calculation and divide the result by 1000 just before you need the value for use with an engine function?

Would this help for you?
If I understand you right, you don't have problems with very large numbers but with position after decimal point.
By the given multiplication you simply move the decimal point to the right. This results in a higher precision but also limits in a way that you can not process large numbers, because you might get an overflow if you multiply a large number by 1000.

Well from the lowtech side, this would not be a multiplication by 1000 but a simple right shift or left shift operation.
This was a common technique at a time where integer operation where way faster than floating point operations.

I hope this works for you in this situation, too.

[edit]
But as you said, sometimes an external dll can help.
I had to do this some years ago to get a smooth camera movement along a Catmull-Rom spline with gamestudio. Whithout dll the movement was not smooth at all.


Last edited by slacer; 05/27/09 05:35.
Re: Fixed point precision and terminal velocity/friction issues? [Re: slacer] #268970
06/01/09 05:17
06/01/09 05:17
Joined: Aug 2002
Posts: 681
Massachusetts, USA
Ichiro Offline OP
User
Ichiro  Offline OP
User

Joined: Aug 2002
Posts: 681
Massachusetts, USA
I'll be durned if I can figure it out, but the left/right shifts haven't been doing the trick. I do appreciate the suggestion -- I just hope the DLL solution will work out(!)


Dejobaan Games - Bringing you quality video games for over 75 years.

Moderated by  HeelX, Spirit 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1