Posted on 2000-05-13
Hi there everyone. I've been using the C++ sin() and cos() functions to get the x and y coordinates from a direction and speed variable. Now, I have noticed that when I use these and the speed (float) variable is fairly low (0 to, maybe, 50 ish) the functions behave very strangely. First, here is the code I use:
car.x += (int)((speed * cos(direction * 3.1415926535 / 180)) / SCALE_FACTOR); //everything reduced
car.y += (int)((speed * sin(direction * 3.1415926535 / 180)) / SCALE_FACTOR); //by a factor of 15
car.x and .y are integers; I cannot change that. Direction is a float between 0 and 359.99... and speed is a float from 0 up. the SCALE_FACTOR is currently 15.
what happens is this. If the angle is far from pointing left,right,up, or down, at low speeds my car moves in a sort of zigzag pattern, going first left, then up, then left, then up, until it reaches a certain speed where it then goes normally. If the angle is close to those four angles, at low speeds the car simple goes straight left (or up, or down, or right) until it reaches a certain speed where it performs normally.
If i'm not being clear I can email you the program in question so you can look at the effects yourselves. Thanks in advance.