|
Re: Looping a function
The problem is that you are doing a bunch of floating point calculations, then truncating them to integers.
This is the biggie:
tiltR = (tiltD * 3.14159265) / 180.0;
For tiltD values between 0 and 57, you're going to get a value of 0 in tiltR. For 58-114, you're going to get 1. All three of your main calculating lines will all round into integers. The combination of all that rounding will probably result in you seeing what you are.
Recomendation:
1) Use fixed-point math (multiply everything by 1000 and be careful with multiplications/divisions),
-or-
2) declare everything as a float and make sure you don't call this function often (floats are very expensive).
Last edited by Bongle : 19-02-2007 at 15:07.
|