我想知道如何删除条件语句并用方法替换它。对于没有监听器的代码,我可以做到。但是这个有监听器事件(arg0),这让我很困惑。仅供参考,这段代码在主类中,我想把这些代码从主类中删除。
感谢您的帮助!!
@Override
public void onMotionSensingEvent( MotionSensingEvent arg0) {
double gradient = 1.38;
double speed;
float testpitch = 0;
testpitch = arg0.getOrientation().getPitch();
float testroll = 0;
testroll = arg0.getOrientation().getRoll();
if (testroll > 16 && flyingControl)
{
speed = gradient*testroll-22.1;
System.out.println("kanan = " + speed);
ardrone.goRight(speed);
}
else if (testroll < (-24) && flyingControl)
{
speed = gradient*testroll*-1 - 22.1;
System.out.println("kiri = " + speed);
ardrone.goLeft(speed);
}
else if (testpitch < (-20) && flyingControl)
{
System.out.println("go up");
ardrone.up();
}
else if (testpitch > 20 && flyingControl)
{
System.out.println("go down");
ardrone.down();
}
else
{
ardrone.stop();
}
}