use of com.neuronrobotics.sdk.addons.kinematics.math.TransformNR in project BowlerStudio by CommonWealthRobotics.
the class BowlerStudio3dEngine method handleMouse.
/**
* Handle mouse.
*
* @param scene the scene
*/
private void handleMouse(SubScene scene) {
scene.setOnMouseClicked(new EventHandler<MouseEvent>() {
long lastClickedTimeLocal = 0;
long offset = 500;
@Override
public void handle(MouseEvent event) {
resetMouseTime();
long lastClickedDifference = (System.currentTimeMillis() - lastClickedTimeLocal);
FxTimer.runLater(Duration.ofMillis(100), new Runnable() {
@Override
public void run() {
long differenceIntime = System.currentTimeMillis() - lastSelectedTime;
if (differenceIntime > 2000) {
// reset only if an object is not being selected
if (lastClickedDifference < offset) {
cancelSelection();
// System.err.println("Cancel event detected");
}
} else {
// System.err.println("too soon after a select
// "+differenceIntime+" from "+lastSelectedTime);
}
}
});
lastClickedTimeLocal = System.currentTimeMillis();
}
});
scene.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent me) {
mousePosX = me.getSceneX();
mousePosY = me.getSceneY();
mouseOldX = me.getSceneX();
mouseOldY = me.getSceneY();
if (me.isPrimaryButtonDown())
captureMouse = true;
else
captureMouse = false;
resetMouseTime();
}
});
scene.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent me) {
resetMouseTime();
mouseOldX = mousePosX;
mouseOldY = mousePosY;
mousePosX = me.getSceneX();
mousePosY = me.getSceneY();
mouseDeltaX = (mousePosX - mouseOldX);
mouseDeltaY = (mousePosY - mouseOldY);
double modifier = 1.0;
double modifierFactor = 0.1;
if (me.isControlDown()) {
modifier = 0.1;
}
if (me.isShiftDown()) {
modifier = 10.0;
}
if (me.isPrimaryButtonDown()) {
// cameraXform.ry.setAngle(cameraXform.ry.getAngle()
// - mouseDeltaX * modifierFactor * modifier * 2.0); // +
// cameraXform.rx.setAngle(cameraXform.rx.getAngle()
// + mouseDeltaY * modifierFactor * modifier * 2.0); // -
// RotationNR roz = RotationNR.getRotationZ(-mouseDeltaX *
// modifierFactor * modifier * 2.0);
// RotationNR roy = RotationNR.getRotationY(mouseDeltaY *
// modifierFactor * modifier * 2.);
TransformNR trans = new TransformNR(0, 0, 0, new RotationNR(mouseDeltaY * modifierFactor * modifier * 2.0, mouseDeltaX * modifierFactor * modifier * 2.0, 0));
if (me.isPrimaryButtonDown()) {
moveCamera(trans);
}
} else if (me.isMiddleButtonDown()) {
} else if (me.isSecondaryButtonDown()) {
double depth = -100 / getVirtualcam().getZoomDepth();
moveCamera(new TransformNR(mouseDeltaX * modifierFactor * modifier * 1 / depth, mouseDeltaY * modifierFactor * modifier * 1 / depth, 0, new RotationNR()));
}
}
});
scene.addEventHandler(ScrollEvent.ANY, new EventHandler<ScrollEvent>() {
@Override
public void handle(ScrollEvent t) {
if (ScrollEvent.SCROLL == t.getEventType()) {
double zoomFactor = -(t.getDeltaY()) * getVirtualcam().getZoomDepth() / 500;
//
// double z = camera.getTranslateY();
// double newZ = z + zoomFactor;
// camera.setTranslateY(newZ);
// System.out.println("Z = "+zoomFactor);
getVirtualcam().setZoomDepth(getVirtualcam().getZoomDepth() + zoomFactor);
}
t.consume();
}
});
}
use of com.neuronrobotics.sdk.addons.kinematics.math.TransformNR in project BowlerStudio by CommonWealthRobotics.
the class BowlerStudio3dEngine method setSelectedCsg.
public void setSelectedCsg(CSG scg) {
if (scg == this.selectedCsg || focusing)
return;
this.selectedCsg = scg;
for (CSG key : getCsgMap().keySet()) {
Platform.runLater(() -> {
try {
getCsgMap().get(key).setMaterial(new PhongMaterial(key.getColor()));
} catch (Throwable ex) {
}
});
}
lastSelectedTime = System.currentTimeMillis();
// System.err.println("Selecting a CSG");
// System.err.println("Selecting one");
FxTimer.runLater(java.time.Duration.ofMillis(1), new Runnable() {
@Override
public void run() {
Platform.runLater(() -> {
try {
getCsgMap().get(selectedCsg).setMaterial(new PhongMaterial(Color.GOLD));
} catch (Exception e) {
}
});
}
});
// System.out.println("Selecting "+selectedCsg);
double xcenter = selectedCsg.getMaxX() / 2 + selectedCsg.getMinX() / 2;
double ycenter = selectedCsg.getMaxY() / 2 + selectedCsg.getMinY() / 2;
double zcenter = selectedCsg.getMaxZ() / 2 + selectedCsg.getMinZ() / 2;
TransformNR poseToMove = new TransformNR();
CSG finalCSG = selectedCsg;
if (selectedCsg.getMaxX() < 1 || selectedCsg.getMinX() > -1) {
finalCSG = finalCSG.movex(-xcenter);
poseToMove.translateX(xcenter);
}
if (selectedCsg.getMaxY() < 1 || selectedCsg.getMinY() > -1) {
finalCSG = finalCSG.movey(-ycenter);
poseToMove.translateY(ycenter);
}
if (selectedCsg.getMaxZ() < 1 || selectedCsg.getMinZ() > -1) {
finalCSG = finalCSG.movez(-zcenter);
poseToMove.translateZ(zcenter);
}
Affine manipulator2 = selectedCsg.getManipulator();
focusToAffine(poseToMove, manipulator2);
resetMouseTime();
}
use of com.neuronrobotics.sdk.addons.kinematics.math.TransformNR in project BowlerStudio by CommonWealthRobotics.
the class VirtualCameraMobileBase method DriveArc.
public void DriveArc(TransformNR newPose) {
// TODO Auto-generated method stub
pureTrans.setX(newPose.getX());
pureTrans.setY(newPose.getY());
pureTrans.setZ(newPose.getZ());
TransformNR global = getFiducialToGlobalTransform().times(pureTrans);
global.setRotation(new RotationNR(tlOffset + (Math.toDegrees(newPose.getRotation().getRotationTilt() + global.getRotation().getRotationTilt()) % 360), azOffset + (Math.toDegrees(newPose.getRotation().getRotationAzimuth() + global.getRotation().getRotationAzimuth()) % 360), elOffset + Math.toDegrees(newPose.getRotation().getRotationElevation() + global.getRotation().getRotationElevation())));
// global.getRotation().setStorage(nr);
// System.err.println("Camera tilt="+global);
// New target calculated appliaed to global offset
setGlobalToFiducialTransform(global);
}
use of com.neuronrobotics.sdk.addons.kinematics.math.TransformNR in project BowlerStudio by CommonWealthRobotics.
the class VirtualCameraMobileBase method getCamerFrame.
public TransformNR getCamerFrame() {
TransformNR offset = TransformFactory.affineToNr(getOffset());
TransformNR fiducialToGlobalTransform = getFiducialToGlobalTransform();
return offset.times(fiducialToGlobalTransform);
}
use of com.neuronrobotics.sdk.addons.kinematics.math.TransformNR in project BowlerStudio by CommonWealthRobotics.
the class JogWidget method controllerLoop.
private void controllerLoop() {
new Thread(() -> {
// System.out.println("controllerLoop");
double seconds = .1;
if (getGameController() != null || stop == false) {
try {
seconds = Double.parseDouble(sec.getText());
if (!stop) {
double inc;
try {
// convert to mm
inc = Double.parseDouble(increment.getText()) * 1000 * seconds;
} catch (Exception e) {
inc = defauletSpeed;
Platform.runLater(() -> {
try {
increment.setText(Double.toString(defauletSpeed));
} catch (Exception ex) {
ex.printStackTrace();
}
});
}
// double rxl=0;
double ryl = inc / 20 * slider;
double rzl = inc / 2 * rz;
TransformNR current = new TransformNR(0, 0, 0, new RotationNR(0, rzl, 0));
current.translateX(inc * x);
current.translateY(inc * y);
current.translateZ(inc * slider);
try {
current = getKin().getCurrentPoseTarget().copy();
current.translateX(inc * x);
current.translateY(inc * y);
current.translateZ(inc * slider);
// current.setRotation(new RotationNR());
double toSeconds = seconds;
if (!JogThread.setTarget(getKin(), current, toSeconds)) {
current.translateX(-inc * x);
current.translateY(-inc * y);
current.translateZ(-inc * slider);
}
// Log.enableDebugPrint();
// System.out.println("Loop Jogging to: "+toSet);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (seconds < .01) {
seconds = .01;
sec.setText(".01");
}
FxTimer.runLater(Duration.ofMillis((int) (seconds * 1000.0)), new Runnable() {
@Override
public void run() {
controllerLoop();
}
});
}
}).start();
}
Aggregations