Skip to main content
gamedev.net
🔒 Locked

Simple data type question

Started by paulcoz 2 replies 500+ views
Original Post
paulcoz
paulcoz
I want to use a timer to calculate how many degrees each step an object should rotate in order to take 5 seconds for a 180 degree rotation like this: DWORD start; DWORD elapsed; (data-type) propyaw; double yaw; while (game running) if (player starts rotating) // run only when key is pressed start = GetTickCount(); if (player rotating) // run while key is down elapsed = GetTickCount() - start; propyaw = (elapsed / 5000) * 180; yaw = propyaw. yaw is then passed into a rotation matrix. You would obviously check to see when yaw is greater than 360 and then handle that when it happens. My question is what data types I should be using during the yaw calculation and whether or not I should be using any type-casts. As far as I know DWORD are integers so GetTickCount() - start should not be a problem. Elapsed / 5000 will probably be a float won't it? or will the conversion from DWORD to float work at all? figure * 180 will probably be a float if it works. Then I have to make yaw a double for use with sin and cos don't I? I know I have a limited knowledge of data types and what to use when etc.. but I have been able to get by until now. This code will just not work no matter what types I put where and believe me I have tried about 20 different combinations. Any help appreciated, Paulcoz. Edited by - paulcoz on 3/21/00 1:14:15 AM
SiCrane
SiCrane
Well, what are you using for your sin and cos? The library functions takes radians, so you need to pass a double. However, most lookup tables are in integral degrees.

If using the library functions, then I would suggest:
double propyaw = (M_PI * (double)elapsed) / 5000.0;

If using integral degrees, then I would suggest:
int propyaw = (180 * elapsed) / 5000;
paulcoz
paulcoz
Hi SiCrane,

I notice you specifically say that elapsed is a double like so:

(double)elapsed

Is there a reason for that?
Is the M_PI in your calculation something I am missing - or is it just your conversion to radians?

Thanks,
Paulcoz.

Edited by - paulcoz on 3/21/00 1:19:44 AM
SiCrane
SiCrane
The (double)elapsed is an explicit cast to double type, otherwise it may be case first to a float and then cast to a double in the course of computation.
M_PI is the value of pi (180 degrees) that is usally defined in math.h.

Edited by - SiCrane on 3/21/00 1:34:47 AM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.