Quote:
|
Originally Posted by Alan Anderson
This is using integer arithmetic. The division by 254 gives an intermediate result of zero, so the final answer is always 127.
You need to either a) force floating point arithmetic by dividing by 254.0, or b) scale the intermediate calculations up by multiplying by a constant (e.g. 256) first and dividing by the same constant just before adding the 127.
|
So would this be the same if I just added parenthesis and changed the formula to this:
if (p1_y >= 147)
p1_y = ((p1_wheel*(p1_y - 127))/254) + 127;
or is this what you were trying to say?
if (p1_y >= 147)
p1_y = ((p1_wheel*(p1_y - 127)*254)/(254*254)) + 127;
Thanks, I shall try these out!