@Override public void onUpdate(FrameTime frameTime) { float speed = (degreesPerSecond * frameTime.getDeltaSeconds()); Quaternion deltaRot = Quaternion.axisAngle(Vector3.up(), speedMultiplier * speed); setLocalRotation(Quaternion.multiply(getLocalRotation(), deltaRot)); }
@Override public void onContinueTransformation(TwistGesture gesture) { float rotationAmount = -gesture.getDeltaRotationDegrees() * rotationRateDegrees; Quaternion rotationDelta = new Quaternion(Vector3.up(), rotationAmount); Quaternion localrotation = getTransformableNode().getLocalRotation(); localrotation = Quaternion.multiply(localrotation, rotationDelta); getTransformableNode().setLocalRotation(localrotation); }
/** * When translating, the up direction of the node must match the up direction of the plane from * the hit result. However, we also need to make sure that the original forward direction of the * node is respected. */ private Quaternion calculateFinalDesiredLocalRotation(Quaternion desiredLocalRotation) { // Get a rotation just to the up direction. // Otherwise, the node will spin around as you rotate. Vector3 rotatedUp = Quaternion.rotateVector(desiredLocalRotation, Vector3.up()); desiredLocalRotation = Quaternion.rotationBetweenVectors(Vector3.up(), rotatedUp); // Adjust the rotation to make sure the node maintains the same forward direction. Quaternion forwardInLocal = Quaternion.rotationBetweenVectors(Vector3.forward(), initialForwardInLocal); desiredLocalRotation = Quaternion.multiply(desiredLocalRotation, forwardInLocal); return desiredLocalRotation.normalized(); }
desiredLocalPosition = parent.worldToLocalPoint(desiredLocalPosition); desiredLocalRotation = Quaternion.multiply( parent.getWorldRotation().inverted(), Preconditions.checkNotNull(desiredLocalRotation));