how do i even out the camera speed with the fps?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
wREAKAILDRON
Posts: 38
Joined: Tue Aug 21, 2007 6:54 pm
Contact:

how do i even out the camera speed with the fps?

Post by wREAKAILDRON »

i want to know how to make the camera move at the same speed no matter what fps my game runs at.
________
Love advice dicussion
Last edited by wREAKAILDRON on Tue Feb 22, 2011 6:52 am, edited 1 time in total.
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post by Saturn »

Scale all movement with the time returned by Irrlicht's timer minus the time returned last frame. This way you know how long the frame needed to render and can scale movements accordingly.
wREAKAILDRON
Posts: 38
Joined: Tue Aug 21, 2007 6:54 pm
Contact:

Post by wREAKAILDRON »

i wanted to erase this and post another question now, i did it a different way too and got a smooth result. :? should i give the answer? :evil: :lol: :evil: ? :x
i did it by dividing the frame rate by 1 and multiplying it by either 100 or 1000, and now the camera moves at the same speed for different framerates. :evil:
________
UNIVERSAL HEALTH WAREHOUSE
Last edited by wREAKAILDRON on Tue Feb 22, 2011 6:52 am, edited 1 time in total.
agi_shi
Posts: 122
Joined: Mon Feb 26, 2007 12:46 am

Post by agi_shi »

wREAKAILDRON wrote:i wanted to erase this and post another question now, i did it a different way too and got a smooth result. :? should i give the answer? :evil: :lol: :evil: ? :x
i did it by dividing the frame rate by 1 and multiplying it by either 100 or 1000, and now the camera moves at the same speed for different framerates. :evil:
That's the same thing. All you did was get the delta from the frame rate instead of from the ... well, original delta.

For example, 60 fps:
1 / 60 = 0.016 seconds per frame (your delta)
You must've multiplied it by 1000 because it's kinda small and unnoticeable (move from seconds to kiloseconds or so).
TomiZ
Posts: 40
Joined: Wed Aug 29, 2007 6:02 am
Location: Poland
Contact:

Post by TomiZ »

This isn't good solution.

This is code from CFPSCounter.cpp:

Code: Select all

//! to be called every frame
void CFPSCounter::registerFrame(u32 now, u32 primitivesDrawn )
{
	++FramesCounted;
	PrimitiveTotal += primitivesDrawn;
	PrimitivesCounted += primitivesDrawn;
	Primitive = primitivesDrawn;

	const u32 milliseconds = now - StartTime;

	if (milliseconds >= 1500 )
	{
		const f32 invMilli = core::reciprocal ( (f32) milliseconds );
		
		FPS = core::ceil32 ( ( 1000 * FramesCounted ) * invMilli );
		PrimitiveAverage = core::ceil32 ( ( 1000 * PrimitivesCounted ) * invMilli );

		FramesCounted = 0;
		PrimitivesCounted = 0;
		StartTime = now;
	}
}
As you can see fps is update only one time in 1500ms. So you camera can "jump" if framerate will change for short time. For example you can get 30 fps when player is looking at fire for 10 second, and 60 when he tourn around, but for first 1500ms camera can move faster.

You should always check time each frame.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

TomiZ, you mean to do it like Saturn said?
Saturn wrote: Scale all movement with the time returned by Irrlicht's timer minus the time returned last frame. This way you know how long the frame needed to render and can scale movements accordingly.
Post Reply