This is the code with the DX8 SDK:


// For our world matrix, we will just rotate the object about the y-axis.
D3DXMATRIX matWorld;
D3DXMatrixRotationY( &matWorld, timeGetTime()/150.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

I've looked at Scronty's example and it is the same. But with the DX9 SDK they use this code:


// Set up the rotation matrix to generate 1 full rotation (2*PI radians)
// every 1000 ms. To avoid the loss of precision inherent in very high
// floating point numbers, the system time is modulated by the rotation
// period before conversion to a radian angle.
UINT iTime = timeGetTime() % 1000;
FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f;
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

I'm not really sure which is better. I would like something that lets me lock the fps to 60 per second. I'm just beginning to learn the fp stuff, so I cant really even translate the DX9 one properly.

Any hints, tips?

Thanks.
Posted on 2003-04-04 03:23:44 by ThoughtCriminal
Use RDTSC :) it has enough resolution for any FPS

Find the frequency of the CPU first and then use a variable delay to fix your FPS to 60FPS

Or even better render the next frame geometry while waiting for next frame delay
Posted on 2003-04-09 11:16:10 by BogdanOntanu
Do this every frame update, will give one rotation per second regardless of framerate I'm pretty sure:

pi2=6.2831854;
angle+=pi2*deltaTime;
if(angle>=pi2)angle-=pi2;

where deltaTime is time since your last screen-update, divided by the frequency of the timer.

for timeGetTime, deltaTime=(double)TimeSinceLastFrame / 1000;
for highPerformanceCounter deltaTime=(double)TImeSinceLastFrame / freq (where freq is the value returned by QueryPerformanceFrequency-api.

( I use this deltaTime Method in an Asteroids game I'm making (in c++ though), works great, always same speed of game regardless fps. Every sprite has a speed variables which describes the nr of pixels they travel per second, and I move them each frame deltaTime*speed. In your case the speed per second must be pi*2 radians I'm guessing.)

Edit: Also if you can't use highPerformanceCounter and must use timeGetTime you can try an
invoke timeBeginPeriod, 1
to try set timeGetTime to have best performance.
Posted on 2003-04-10 09:03:08 by david

Use RDTSC :) it has enough resolution for any FPS

Find the frequency of the CPU first and then use a variable delay to fix your FPS to 60FPS

Or even better render the next frame geometry while waiting for next frame delay


Ya this is how I would do it if I weren't in my stupid mode...But I also would love to try david's method
Posted on 2003-04-15 18:22:59 by x86asm