title: Implementing a 3D transform gizmo using JavaFX
body: <p>My goal is to create a simple translation and rotation gizmo in JavaFX.</p>
  <p>There are plenty of examples of how this can be implemented in C++ (e.g. <a href="https://nelari.us/post/gizmos/" rel="nofollow noreferrer">https://nelari.us/post/gizmos/</a>). But I am having trouble translating this code into JavaFX. Mainly because the underlying Math is not easily accessible using JavaFX (e.g. getting a camera matrix from the PerspectiveCamera). I am having a hard time figuring out how to get the right ingredients from the available JavaFX components.</p>
  <p>My plan is to implement MouseEvent handlers for pressing and dragging, and then project the drag motion in the respective transform space (translation, rotation). But I am really clueless on where to start.</p>
  <p>I tried searching online for any implementations of this in JavaFX and I couldn't find anything.</p>
  <p>I am hoping someone in this community can either help me out translating the C++ tutorial I linked at the beginning of this post or help me add the right drag handlers for the Gizmo components in the code linked below.</p>
  <p>Below follows a gist containing a test application of a simple 3D scene containing the gizmo and with a simple camera implementation (thanks to the <a href="https://github.com/FXyz/FXyzLib" rel="nofollow noreferrer">https://github.com/FXyz/FXyzLib</a> library for this). It's a lot of lines but most are due to the classes used to create the visual elements, the really important class is the Gizmo class.</p>
  <p><a href="https://gist.github.com/dosier/f075259da0d87f431a361fd300b7e133" rel="nofollow noreferrer">https://gist.github.com/dosier/f075259da0d87f431a361fd300b7e133</a> (code is too long to include in here)</p>
  <p><strong>Edit #1 - 8th of October:</strong></p>
  <p>I have tried setting a drag detected handler for each of the drag cones, and then set a drag handler in the scene. I don't want the returned coordinates of the drag event be dependent on whether a node has been intersected. I tried the code linked below, but it's not giving the correct results. I think if I have this figured out I can get the translate part of the gizmo functional, then only rotation is left:</p>
  <pre><code>final PickResult currentPickResult = me.getPickResult();
  final Node currentNode = currentPickResult.getIntersectedNode();
  final Point3D currentPoint;
  if(currentNode != null)
      currentPoint = currentNode.localToParent(currentPickResult.getIntersectedPoint());
  else
      currentPoint = currentPickResult.getIntersectedPoint();
  </code></pre>
  <p><strong>Edit #2 - 8th of October:</strong></p>
  <p>So I made some strives towards porting the code in the tutorial I linked to JavaFX, I managed to find some (experimental) code in the com.sun.javafx package that seems to provide all the ingredients I need to work out the math. But I don't quite understand all parts of the math in the tutorial. Anyways, here is a gist with my current progress:
  <a href="https://gist.github.com/dosier/3481e18dfaaf38a36f4e91b525917642" rel="nofollow noreferrer">https://gist.github.com/dosier/3481e18dfaaf38a36f4e91b525917642</a></p>