Quote:
Originally Posted by Tanis
We've found the problem to lie in-
Code:
velocity = (p1_y - 127);
rotation = (p1_x - 127);
strafe = (p2_x - 127);
We've put some printf statements before and after these 3 lines, but the p1 and p2 variables are correct. For some reason the code is adding 129 to p1_x and p2_y and storing that into rotation and strafe instead of subtracting 127.
We can't figure out where this is coming from. Any ideas?
Sorry we couldn't try the last poster's suggestion today- our lab lost its internet connection, and we forgot what it was. We'll try that tomorrow.
|
p1_x, p1_y, and p2_x are of type unsigned char. If they are less than 127, your subtraction will wrap around (since negatives aren't allowed) - i'm guessing your input is 126 (126 - 127 = -1, which is 255)
To fix it, you just need to typecast the inputs to ints:
Code:
velocity = (((int)p1_y) - 127);
rotation = (((int)p1_x) - 127);
strafe = (((int)p2_x) - 127);