}
//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_DETECTED:
//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(), MTApplication.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 = MTApplication.degrees(diff); //our rotation expects degrees (not radians)
comp.rotateZ(comp.getCenterPointRelativeToParent(), diff);