// Global input processor listener implementation (IMTInputEventListener) public boolean processInputEvent(MTInputEvent inEvt) { if (inEvt instanceof MTFiducialInputEvt) { MTFiducialInputEvt fEvt = (MTFiducialInputEvt) inEvt; int fID = fEvt.getFiducialId(); Vector3D position = fEvt.getPosition(); AbstractShape comp; switch (fEvt.getId()) { case MTFiducialInputEvt.INPUT_STARTED: // Create a new component for the fiducial AbstractShape newComp = createComponent(fID, position); fiducialIDToComp.put(fID, newComp); // Map id to component // Move component to fiducial position newComp.setPositionGlobal(position); // Save the absolute rotation angle in the component for late newComp.setUserData("angle", fEvt.getAngle()); // Rotate the component newComp.rotateZ( newComp.getCenterPointRelativeToParent(), AbstractMTApplication.degrees(fEvt.getAngle())); // Add the component to the canvas to draw it getCanvas().addChild(newComp); break; case MTFiducialInputEvt.INPUT_UPDATED: // Retrieve the corresponding component for the fiducial ID from the map comp = fiducialIDToComp.get(fID); if (comp != null) { // Set the new position comp.setPositionGlobal(position); // Set the rotation (we have to do a little more here because // mt4j does incremental rotations instead of specifying an absolute angle) float oldAngle = (Float) comp.getUserData("angle"); // retrieve the "old" angle float newAngle = fEvt.getAngle(); if (oldAngle != newAngle) { float diff = newAngle - oldAngle; comp.setUserData("angle", newAngle); diff = AbstractMTApplication.degrees(diff); // our rotation expects degrees (not radians) comp.rotateZ(comp.getCenterPointRelativeToParent(), diff); } } break; case MTFiducialInputEvt.INPUT_ENDED: comp = fiducialIDToComp.get(fID); if (comp != null) { comp.destroy(); fiducialIDToComp.remove(fID); } break; default: break; } } return false; }
/** Private method, fiducial has been updated */ private void updated() { AbstractShape component = FiducialRegistry.getInstance().getFiducialComponent(EventID); if (component != null) { component.setPositionGlobal(event.getPosition()); float oldAngle = (Float) component.getUserData("angle"); // retrieve the "old" angle float newAngle = event.getAngle(); if (oldAngle != newAngle) { float diff = newAngle + oldAngle; component.setUserData("angle", newAngle); diff = MTApplication.degrees(diff); // our rotation expects degrees (not radians) component.rotateZ(component.getCenterPointRelativeToParent(), diff); } } }