• Advertisement

Archived

This topic is now archived and is closed to further replies.

strange things in D3D8 when using timeGetTime() ....

This topic is 5563 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I face a stringe thing in D3D8 when using timeGetTime(). At first, when I just boot up the PC, my program run perfectly(whit a polygon rotating). (whit this code) D3DXMatrixRotationY(&matWorld, timeGetTime()/400.0f); mDirect3DDevice->SetTransform(D3DTS_WORLD, &matWorld); and then i try to run it later(about an hour) ... the ploygon does not rotate at all. and i try to change the code to: D3DXMatrixRotationY(&matWorld, timeGetTime()/1000.0f); it work again. ... I don''t know what is happened. can anyone explain it to me? or it is just a bug ? Thanks ^-^

Share this post


Link to post
Share on other sites
Advertisement
See the "tutorials" folder at the D3D samples in the DX8 SDK.

Kamikaze

Share this post


Link to post
Share on other sites
Your rotating value rise to high.
x/1 for x against infinity the result is infinity.
It means steps in radians are to high. Your primitive won''t stop to flutter =)

Share this post


Link to post
Share on other sites
It happened to my too, but if you cast to float your result it is done:

D3DXMatrixRotationY(&matWorld, (float)timeGetTime()/400.0f);

Share this post


Link to post
Share on other sites
Thanks all,

To NeonGE,
It seems that casting to float doesn''t solve the problem.

Is there any method to solve that problem ?

Share this post


Link to post
Share on other sites
Use a temporary var to store the time passed since the last frame. Use a second var to store your current angle, then add time passed (stored in your first var) / 400.0f to the angle.

This will keep the number small enough to be accurate.

Also, if you intend to have it spin for a long time, consider subtracting 2Pi from the angle every time it passes 2Pi. This should run forever.

Heres some sample code:

    
static long lastframe = 0.0f;
long currenttime = timeGetTime();
long step = currenttime - lastframe;
static float angle = 0.0f;
angle += (float)(step / 400.0f);
D3DXMatrixRotationY(&matWorld, angle);
mDirect3DDevice->SetTransform(D3DTS_WORLD, &matWorld);


*note: I forget if time is float or long. I used long -- if it's float be sure to correct it .

Hope I didn't mess up somewhere .



[edited by - sirob on December 3, 2002 11:32:46 AM]

Share this post


Link to post
Share on other sites
I had the same problem a few days ago.

I solved it by using the modulo operator on the timeGetTime() result and then transform the degrees to radians:


  
// x is a factor to scale rotation speed, 10 works fine for me

UINT uRotAngle = (timeGetTime() / x) % 360;
//...

D3DXMatrixRotationX(&matRotationX, D3DXToRadian(uRotAngle));


This way uRotAngle will always be between 0 and 359 (degrees)


[edited by - squonk on December 3, 2002 11:36:58 AM]

Share this post


Link to post
Share on other sites
Thanks ^^ ~~

the key point is that make the timeGetTime() to be small enough ^^

thank you very much.

Share this post


Link to post
Share on other sites

  • Advertisement