Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to rotate an object around a custom pivot in JavaFX?
    primarykey
    data
    text
    <p>I want to rotate an object round a custom pivot, which is its point, so I have such code:</p> <pre><code>private final EventHandler&lt;MouseEvent&gt; mouseEventHandler = new EventHandler&lt;MouseEvent&gt;() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getEventType() == MouseEvent.MOUSE_PRESSED) { dragStartX = mouseEvent.getSceneX(); dragStartY = mouseEvent.getSceneY(); mousePosX = mouseEvent.getSceneX(); mousePosY = mouseEvent.getSceneY(); mouseOldX = mouseEvent.getSceneX(); mouseOldY = mouseEvent.getSceneY(); if (mouseEvent.isMiddleButtonDown()) { pivot = mouseEvent.getPickResult().getIntersectedPoint(); camForm1.rx.setPivotX(pivot.getX()); camForm1.ry.setPivotY(pivot.getY()); camForm1.rz.setPivotZ(pivot.getZ()); System.out.println(pivot); } } else if (mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED) { double modifier = 1.0; double modifierFactor = 0.3; if (mouseEvent.isControlDown()) { modifier = 0.1; } if (mouseEvent.isShiftDown()) { modifier = 10.0; } mouseOldX = mousePosX; mouseOldY = mousePosY; mousePosX = mouseEvent.getSceneX(); mousePosY = mouseEvent.getSceneY(); mouseDeltaX = (mousePosX - mouseOldX); //*DELTA_MULTIPLIER; mouseDeltaY = (mousePosY - mouseOldY); //*DELTA_MULTIPLIER; double flip = -1.0; if (mouseEvent.isPrimaryButtonDown() &amp;&amp; mouseEvent.isSecondaryButtonDown()) { camForm2.t.setX(camForm2.t.getX() + flip * mouseDeltaX * modifierFactor * modifier * 0.3); // - camForm2.t.setY(camForm2.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3); // - yFlip* } else if (mouseEvent.isSecondaryButtonDown()) { camForm1.ry.setAngle(camForm1.ry.getAngle() - mouseDeltaX * modifierFactor * modifier * 2.0); // + yFlip* camForm1.rx.setAngle(camForm1.rx.getAngle() + flip * mouseDeltaY * modifierFactor * modifier * 2.0); // - } } } }; </code></pre> <p><code>camForm1</code> and <code>camForm2</code> are the examples of <code>XForm</code> class.</p> <pre><code> public class XForm extends Group { public enum RotateOrder { XYZ, XZY, YXZ, YZX, ZXY, ZYX } public Translate t = new Translate(); public Translate p = new Translate(); public Translate ip = new Translate(); public Rotate rx = new Rotate(0.0, 0.0, 0.0, 0.0, Rotate.X_AXIS); public Rotate ry = new Rotate(0.0, 0.0, 0.0, 0.0, Rotate.Y_AXIS); public Rotate rz = new Rotate(0.0, 0.0, 0.0, 0.0, Rotate.Z_AXIS); public Scale s = new Scale(); public XForm() { super(); getTransforms().addAll(t, rz, ry, rx, s); } ... } </code></pre> <p>But the rotation is around point O(0, 0, 0). What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload