Quote:
Originally Posted by notmattlythgoe
You can also just place a - in front of it.
Code:
if (reversing) { //Put whatever code you use to detect if you're reversing here
myMotor.set(-joystick.getYAxis()); //Set a motor to the inverse of the Y axis.
}
|
Quote:
Originally Posted by Ether
Is this just a matter of aesthetics, or does it actually generate more efficient code?
|
I'm not sure about Java, but I do know that with traditional compilers, it is more efficient - changing the sign on a number is a much simpler operation, usually done in a single clock cycle. Unless the compiler is doing serious optimization, multiplying by -1 is a full floating-point multiply.