@Override
public void onSwipe(GVRTouchPadGestureListener.Action action, float velocityX) {
if (gameStopped() || (mController.getControllerType() == GVRControllerType.CONTROLLER)) {
return;
}
int normal = MathUtils.calculateForce(velocityX);
float[] forward = MathUtils.calculateRotation( mCamera.getHeadTransform().getRotationPitch(), mCamera.getHeadTransform().getRotationYaw());
float[] force = {normal * forward[0], normal * forward[1], normal * forward[2]};
try {
GVRTransform trans = mCamera.getTransform();
GVRSceneObject ball = MainHelper.createBall(mBallProto,
5 * forward[0] + trans.getPositionX(),
5 * forward[1] + trans.getPositionY(),
5 * forward[2] + trans.getPositionZ(), force);
mScene.addSceneObject(ball);
mNumBalls++;
mBallsLabel.setText("Balls: " + (MAX_BALLS - mNumBalls));
} catch (IOException ioe) {
ioe.printStackTrace();
}
}