6 Replies Latest reply: Feb 26, 2013 4:46 PM by KonradZuse RSS

    How to rotate at any angle?

    KonradZuse
      So I see normally for the rotation it's based on X, Y, and Z, by choosing one of them.. I also saw somewhere where you can specify the angle for the cam, but that's about it.. I want to be able to manipulate a 3d object at any angle :)
        • 1. Re: How to rotate at any angle?
          jsmith
          Use the Rotate(angle, point3D) method to define your rotation.

          http://docs.oracle.com/javafx/2/api/javafx/scene/transform/Rotate.html#Rotate(double,%20javafx.geometry.Point3D)
          // rotate about 30 degrees around the axis defined by the vector x=1, y=0, z=-1
          Rectangle rect = new Rectangle(50,50, Color.RED);
          rect.getTransforms().add(new Rotate(30, new Point(1, 0, -1)));
          Or (probably easier to visualize and work with), concatenate your transforms about the 3 standard axes.
          // rotate about 45 degrees about the z axis to make a diamond, turn the diamond side on the user 20 degrees and tilt it back 5 degrees.
          Rectangle rect = new Rectangle(50,50, Color.RED);
          rect.getTransforms().add(
            new Rotate(45, Rotate.Z_AXIS)
            new Rotate(20, Rotate.Y_AXIS)
            new Rotate(-5, Rotate.X_AXIS)
          );
          • 2. Re: How to rotate at any angle?
            KonradZuse
            So the vector is basically from (0,0,0) to (1,0,-1)?

            Also is there a way to get the mouse position relative to the origin to rotate? I want to essentially rotate around a fixed object like a box, or a group of boxes!

            Edited by: KonradZuse on Feb 23, 2013 2:41 PM
            • 3. Re: How to rotate at any angle?
              KonradZuse
              So the vector is basically from (0,0,0) to (1,0,-1)?

              Also is there a way to get the mouse position relative to the origin to rotate? I want to essentially rotate around a fixed object like a box, or a group of boxes!
              • 4. Re: How to rotate at any angle?
                KonradZuse
                Sorry for the double post above, and sorry for thisd next post, but I couldn't edit....

                I realized I was a bit unclear. I basically was to use mouseDragged and by using the location from the origin and where I drag it will simulate how to rotate around a group or object?
                • 5. Re: How to rotate at any angle?
                  jsmith
                  For that you need to rotate the camera rather than the object.
                  You will need to use a recent build of Java8 (b77+) for that and a machine that can run the 3D stuff in it (currently only a Windows machine).

                  From: https://wikis.oracle.com/display/OpenJDK/3D+Features
                  There is some code for specifying a movable camera:
                  // Create a camera and add it to the Scene
                  Camera camera = new PerspectiveCamera();
                  scene.setCamera(camera);
                   
                  // Add camera to scene graph (so it can move)
                  Group cameraGroup = new Group();
                  cameraGroup.getChildren().add(camera);
                  root.getChildren().add(cameraGroup);
                   
                  // Rotate the camera
                  camera.rotate(45);
                   
                  // Move the cameraGroup (camera moves with it)
                  cameraGroup.setTranslateZ(-75);
                  I haven't tried it, but in JavaFX 8 the camera is just another node.
                  I think if you apply a RotateTransition to the camera you could animate rotating it around (like turning your head to see change your field of view).
                  Similarly, if you instead applied a PathTransition to the group containing the camera, then that would simulate you walking in a circle, but looking in a constant direction.

                  If you applied an appropriate RotateTransition to both the camera and a PathTransition to the group containing the camera and you did it at the right proportional values, then you could ensure that the as the camera was rotating around the object, it was always facing inward tangentally to the path the group is following so that it is always looking at the object being walked around.
                  http://docs.oracle.com/javafx/2/api/javafx/animation/RotateTransition.html

                  For some inspiration look at Uluk's answer here which demonstrate animation around a circular path.
                  http://stackoverflow.com/questions/14171856/javafx-2-circle-path-for-animation
                  http://stackoverflow.com/questions/14182704/javafx-2-animation-scale-node-depending-pathtransition-duration/14182917#14182917
                  But in the second example, you put it in 3D and rotate the camera instead of scaling the node.
                  • 6. Re: How to rotate at any angle?
                    KonradZuse
                    Thanks, I figured I might have to use both.... I will have to be able to rotate at any point around the object, or set of objects. up down, left, right, or any angel I need, at any point. I'm also going to have a part where if you click on an item it will zoom in, and you will be able to rotate around that single item, instead of the whole.