[QUOTE=Darwin226;22373339]Guys I have a math problem.
I have a variable that needs to decrease by 1 every second so I used
var -= FrameTime
That works fine because if the framerate is faster, it will decrease less and still decrease by 1 every second.
But then I have another variable that needs to devide by 2 every second and I have no idea how to do it.
I have tried something like
var /= 1.001F * FrameTime
That obviously doesn't work because if the FrameTime is bellow 1 it will actually increase the variable.
Help please.[/QUOTE]
Try [code]var /= (2 ^ FrameTime)[/code]
[QUOTE=TheBoff;22373454]Try [code]var /= (2 ^ FrameTime)[/code][/QUOTE]
Interesting, no idea how you worked that out, could you elaborate on the logic behind that?
I would have done some crazy shit like...
[code]
//pseudocode
if varNextSecondDelta <= 0
varNextSecondDelta = var-(var / 2)
var -= varNextSecondDelta/(1000/frameTime)
varNextSecondDelta -= varNextSecondDelta/(1000/frameTime)
[/code]
Probably works, just thought it up on the spot.
Assume varNextSecondDelta is first initialised as 0.
[QUOTE=Jallen;22374149]Interesting, no idea how you worked that out, could you elaborate on the logic behind that?
[/QUOTE]
Well, for every 1 second, we're dividing by 2. So, in 2 seconds, we've divided by 2 twice, which is the same thing as dividing by 2^2 once. Since x^a * x^b = x^(a+b), we can just divide by pow(2.0, deltaTime) every frame (or multiply by pow(0.5, deltaTime))
[QUOTE=Jallen;22374149]Interesting, no idea how you worked that out, could you elaborate on the logic behind that?
I would have done some crazy shit like...
[code]
//pseudocode
if varNextSecondDelta <= 0
varNextSecondDelta = var-(var / 2)
var -= varNextSecondDelta/(1000/frameTime)
varNextSecondDelta -= varNextSecondDelta/(1000/frameTime)
[/code]
Probably works, just thought it up on the spot.
Assume varNextSecondDelta is first initialised as 0.[/QUOTE]
A carefully grown mathematical intuition :P
Decreasing proportionally in a set time period is going to be an exponential pattern, and the only logical base for halving is a half ((1/2)^n=(1/2^n))
tl;dr "It just is."
That's incredibly clever.
[QUOTE=Jallen;22374149]Interesting, no idea how you worked that out, could you elaborate on the logic behind that?
I would have done some crazy shit like...
[code]
//pseudocode
if varNextSecondDelta <= 0
varNextSecondDelta = var-(var / 2)
var -= varNextSecondDelta/(1000/frameTime)
varNextSecondDelta -= varNextSecondDelta/(1000/frameTime)
[/code]
Probably works, just thought it up on the spot.
Assume varNextSecondDelta is first initialised as 0.[/QUOTE]
When it's multiplied by a constant every second, it's a simple geometric series
f(n) = f(n-1)*t
f(n) = f(0)*t^n
Just expanded into a continuous function
t is the constant, in this case 0.5 since it's being halved
Hmmm, it doesnt seem to work. It still decreases more at lower framerates
What am I doing wrong?
[cpp]
Position += Speed / Holder.FrameTime;
Speed *= (float)Math.Pow( 0.9F, Holder.FrameTime );[/cpp]
At 30k FPS it works well but when it drops the speed is decreased much quicker.
What units is FrameTime?
Seconds.
[QUOTE=Darwin226;22374638]What am I doing wrong?
[cpp]
Position += Speed / Holder.FrameTime;
Speed *= (float)Math.Pow( 0.9F, Holder.FrameTime );[/cpp]
At 30k FPS it works well but when it drops the speed is decreased much quicker.[/QUOTE]
Why are you moving slower with a higher FrameTime? Shouldn't it be the other way around?
[cpp]
Position += Speed * Holder.FrameTime;[/cpp]
Also 30000 FPS. :aaaaa:
Yeah if you're looking at the position, it won't display correctly. But the speed will still decrease correctly.
How am I moving slower?
If the framerate is 1, the game is running at 1 FPS and it will move the object 1 * Speed every second.
If the framerate is 0.016, the game is running at 60FPS and it will mode the object 0.016 * Speed every frame or 1 * Speed every second (60 frames)
[QUOTE]
Also 30000 FPS. :aaaaa:[/QUOTE]
While I do think that's very good remember that the difference between 30k FPS and 5k is 0.00016 seconds per frame while the difference between 1k FPS and 60 is 0.015 seconds per frame.
[QUOTE=Darwin226;22375127]How am I moving slower?
If the framerate is 1, the game is running at 1 FPS and it will move the object 1 * Speed every second.
If the framerate is 0.016, the game is running at 60FPS and it will mode the object 0.016 * Speed every frame or 1 * Speed every second (60 frames)[/QUOTE]
But you didn't write FrameTime*Speed, you wrote Speed/FrameTime.
[QUOTE=nullsquared;22374410]Well, for every 1 second, we're dividing by 2. So, in 2 seconds, we've divided by 2 twice, which is the same thing as dividing by 2^2 once. Since x^a * x^b = x^(a+b), we can just divide by pow(2.0, deltaTime) every frame (or multiply by pow(0.5, deltaTime))[/QUOTE]
Good explanation, thanks.
Oh, that makes sense *facepalm*.
Frickin' shit.
[QUOTE=Darwin226;22375127]How am I moving slower?
If the framerate is 1, the game is running at 1 FPS and it will move the object 1 * Speed every second.
If the framerate is 0.016, the game is running at 60FPS and it will mode the object 0.016 * Speed every frame or 1 * Speed every second (60 frames)
While I do think that's very good remember that the difference between 30k FPS and 5k is 0.00016 seconds per frame while the difference between 1k FPS and 60 is 0.015 seconds per frame.[/QUOTE]
You can't have frame independent time when dealing with acceleration (at least without advanced math); the orbit of an object with a timestep of x will be different than the orbit with a timestep of y. This is because how many times you update the speed will affect the displacement of the object.
It's too warm nowadays to program anything :saddowns:
I feel like I've achieved nothing in days
[QUOTE=ryandaniels;22375452]You can't have frame independent time when dealing with acceleration (at least without advanced math); the orbit of an object with a timestep of x will be different than the orbit with a timestep of y. This is because how many times you update the speed will affect the displacement of the object.[/QUOTE]
Should I just check if certain amount of time has passed and then update speeds?
Tho this method works just fine for what I'm doing.
[QUOTE=Darwin226;22375602]Should I just check if certain amount of time has passed and then update speeds?
Tho this method works just fine for what I'm doing.[/QUOTE]
Yes, and note that the more calculations per second, the more accurate the simulation is. If it doesn't matter, then don't worry about it, although obviously it wouldn't be difficult to implement.
[QUOTE=iPope;22366845]Does anyone else here find it awesome to code in really small fonts?
[img-]http://anyhub.net/file/screenie.png[/img-]
Doesn't that just look sexy?[/QUOTE]
What font is that?
There's nothing better than the 3px font :smug:
[IMG]http://typophile.com/files/roman_tr_5609.png[/IMG]
Wonder how my code will look like in that font
Is there a font like dina but in a better format? I tried downloading the converted dina but it looks like shit.
[cpp] spriteobj->Begin(D3DXSPRITE_ALPHABLEND);
float x = cursorPos.x;
test = sprintf(buffer,"X %d", x);
float y = cursorPos.y;
test1 = sprintf(buffer2, "X %d", y);
FontPrint(fontArial24, 10, 10, test, D3DCOLOR_XRGB(255, 0, 0));
FontPrint(fontArial24, 80, 10, test1.c_str(), D3DCOLOR_XRGB(255, 0, 0));
spriteobj->End();[/cpp]
Attempts at outputting mouse coordinates still fail. I get some random character.
%d is only for integers. Use %f
[QUOTE=thelinx;22368897]Wait, you _have_ to capitalize booleans in python? I feel sorry for all python dudes.[/QUOTE]
Well, you could always do this, although it seems pretty messy.
[code]true, false = True, False[/code]
[IMG]http://i155.photobucket.com/albums/s301/darkrei9n/BOYORGIRL.png[/IMG][IMG]http://s155.photobucket.com/albums/s301/darkrei9n/?action=view¤t=BOYORGIRL.png[/IMG]
Well, it works better than before, depending on where you place the mouse the point is either according to the mouse coordinates, a boy, a girl, or both.
[QUOTE=tobias104;22377843]Well, you could always do this, although it seems pretty messy.
[code]true, false = True, False[/code][/QUOTE]
Yeah, it always confuses me. I just use 0 and 1 instead, that way I don't forget to capitalize my booleans.
[img]http://i48.tinypic.com/2r4r1us.png[/img]
Decided to go with the charm variable affecting flirting, if you can defeat the girl's heart in a very pokemon-esqe battle you can date her etc
Sorry, you need to Log In to post a reply to this thread.