1

I am trying to rotate multiple spheres around one object in the center and the challenge I am facing now is how to put different start points (maybe angle?) for the shapes so that they all don't start right from the same spot all at once.

This is my code :

    Sphere earth = new Sphere(2);
    earth.setTranslateZ(7);
    earth.setTranslateX(30);

    RotateTransition rt4 = new RotateTransition();
    rt4.setNode(earth);
    rt4.setDuration(Duration.millis(3000));
    rt4.setAxis(Rotate.Y_AXIS);
    rt4.setByAngle(360);
    rt4.setCycleCount(Animation.INDEFINITE);
    rt4.setInterpolator(Interpolator.LINEAR);
    rt4.play();

Edit (for clarification): earth is rotating around itself and around the center point with coordinates (0,0,0) at the same time. What I want to change the from where earth starts rotating around the center point and NOT around itself.

J. Doe
  • 103
  • 1
  • 6
  • Use [`setFromAngle`](https://docs.oracle.com/javase/9/docs/api/javafx/animation/RotateTransition.html#setFromAngle-double-) and specify a different starting angle for each? Or, equivalently, just specify different `setRotate()` for each object before starting the animation. – James_D Jan 25 '18 at 17:18
  • this only changed the angle the earth is rotation around itself. Earth is rotating around itself and around the center point with coordinates (0,0,0). What I want to change the from where earth starts rotating around the center point – J. Doe Jan 25 '18 at 17:25
  • Yeah, so I guess your clarification confuses me. There are two rotations applied to `earth`, is that the idea? The code you posted appears to be the code that "rotates `earth` around itself"? But you want to change the starting point for the other rotation? – James_D Jan 25 '18 at 17:27
  • yep true. I am sorry for the confusion, I am rotating the camera and thus the illusion that earth is rotating around the center (teaching myself JavaFX hehe). I tried to solve this with a wrong approach. In order to change the initial points of the earth, instead of translating it by X and then a translation angle (does that even exist). I had to calculate to start point using x=rsinθ, y=rcosθ. – J. Doe Jan 25 '18 at 17:43
  • 1
    You can add a rotation to an node about an arbitrary point by creating a [`Rotate`](https://docs.oracle.com/javase/9/docs/api/javafx/scene/transform/Rotate.html) and calling, e.g. `earth.getTransforms().add(rotate)`. You can "animate" the angle of that `Rotate` using a `Timeline`, if you need, but if you are rotating all objects with a rotation of the camera, it probably suffices just to add an initial fixed `Rotate` to each of them. Or, as you say, just set a translation using some basic trigonometry. – James_D Jan 25 '18 at 17:47
  • This is also a very nice idea, thank you. One question tho, If I used earth.getTransforms().add(rotate), how do I regulate the rotation speed or in other words how long it will take to finish one rotation? – J. Doe Jan 25 '18 at 17:55
  • 2
    The `Rotate` isn't itself an animation; it simply specifies an angle (plus pivot point and axis, etc). You can use a `Timeline` to "continuously" modify (i.e. animate) the angle; the `KeyFrame` you specify to the `Timeline` would control the time it takes for the angle to reach a particular value, so it would control the speed of rotation. – James_D Jan 25 '18 at 17:58
  • Alight, will do. Appreciate the help! – J. Doe Jan 25 '18 at 18:22

0 Answers0