I’ve gotten myself into a bit of a corner with quaternions, and I could use some input.
What I want:
I want a 3D transform widget for moving entities by dragging them. For now that’s just 3 arrows, each along one of the cardinal axes. A click and drag on one of the arrows should move the entity along that arrow’s axis.
How I’m approaching it:
The widget should be centered at the model’s center, but it needs to be visible and clickable at all times (can’t have it intersecting the model) - that means the widget needs to go in the GUI node and track the screen space projected position/orientation of the model it controls.
What I have:
Node entityModelRoot = ...; // get entity model node from entity system
setLocalTranslation(cam.getScreenCoordinates(entityModelRoot.getWorldTranslation()));
setLocalRotation(...); // Got nothing for this one here
What works:
The position of the widget tracks the entity perfectly.
What doesn’t work:
I’ve tried about a dozen approaches for transforming the rotation into screen space (including multiplying the model’s world rotation by the ViewProjection
matrix) but I haven’t figured out how to get it quite right.