@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();
}
}
@Override
public void onExpansionEvent(ExpansionEvent e)
{
JoystickEvent joy = getJoystickEvent(e);
float gradient =64;
float speed;
float angle = 0;
angle = joy.getAngle();
float magnitude = joy.getMagnitude();
if ((angle > 340 || angle < 20) && magnitude > 0.49 && flyingControl)
{
speed = gradient*magnitude-19;
ardrone.forward(speed);
}
else if ((angle > 160 && angle < 200) && magnitude > 0.49 && flyingControl)
{
speed = gradient*magnitude-19;
ardrone.backward(speed);
}
else if ((angle > 70 && angle < 110) && magnitude > 0.7 && flyingControl)
{
System.out.println("turn right ");
ardrone.spinRight();
}
else if ((angle > 250 && angle < 290) && magnitude > 0.7 && flyingControl)
{
System.out.println("turnleft ");
ardrone.spinLeft();
}
}
我有这段代码,我需要帮助将所有这些 IF-ELSE 东西从主类中删除,使其进入 OOP,但我不知道一个好的开始方法。我的主管说了一些关于听众的事情,但我不明白。仅供参考,我有那些听众,但我不包括在这个问题中。
那么,谁能告诉我从主类中删除所有这些 IF ELSE 的步骤?多谢!!