/** * 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(); }
@Override public void onUpdate(FrameTime frameTime) { float speed = (degreesPerSecond * frameTime.getDeltaSeconds()); Quaternion deltaRot = Quaternion.axisAngle(Vector3.up(), speedMultiplier * speed); setLocalRotation(Quaternion.multiply(getLocalRotation(), deltaRot)); }
ArrayList<Integer> triangleIndices = new ArrayList<>(); ArrayList<Quaternion> rotations = new ArrayList<>(); Vector3 desiredUp = Vector3.up();
@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); }
Vector3 rightDirection = Quaternion.rotateVector(averagedRotation, Vector3.right()).normalized(); Vector3 upDirection = Quaternion.rotateVector(averagedRotation, Vector3.up()).normalized();
@Override public void onUpdate(FrameTime frameTime) { if (infoCard == null) { return; } // Typically, getScene() will never return null because onUpdate() is only called when the node // is in the scene. // However, if onUpdate is called explicitly or if the node is removed from the scene on a // different thread during onUpdate, then getScene may be null. if (getScene() == null) { return; } Vector3 cameraPosition = getScene().getCamera().getWorldPosition(); Vector3 cardPosition = infoCard.getWorldPosition(); Vector3 direction = Vector3.subtract(cameraPosition, cardPosition); Quaternion lookRotation = Quaternion.lookRotation(direction, Vector3.up()); infoCard.setWorldRotation(lookRotation); } }
Vector3 rightDirection = Quaternion.rotateVector(rotationFromAToB, Vector3.right()).normalized(); Vector3 upDirection = Quaternion.rotateVector(rotationFromAToB, Vector3.up()).normalized(); desiredUp.set(upDirection);