Search in sources :

Example 1 with TransformNR

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();
        }
    });
}
Also used : MouseEvent(javafx.scene.input.MouseEvent) ScrollEvent(javafx.scene.input.ScrollEvent) RotationNR(com.neuronrobotics.sdk.addons.kinematics.math.RotationNR) TransformNR(com.neuronrobotics.sdk.addons.kinematics.math.TransformNR)

Example 2 with TransformNR

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();
}
Also used : CSG(eu.mihosoft.vrl.v3d.CSG) Affine(javafx.scene.transform.Affine) TransformNR(com.neuronrobotics.sdk.addons.kinematics.math.TransformNR) IOException(java.io.IOException)

Example 3 with TransformNR

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);
}
Also used : RotationNR(com.neuronrobotics.sdk.addons.kinematics.math.RotationNR) TransformNR(com.neuronrobotics.sdk.addons.kinematics.math.TransformNR)

Example 4 with TransformNR

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);
}
Also used : TransformNR(com.neuronrobotics.sdk.addons.kinematics.math.TransformNR)

Example 5 with TransformNR

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();
}
Also used : RotationNR(com.neuronrobotics.sdk.addons.kinematics.math.RotationNR) TransformNR(com.neuronrobotics.sdk.addons.kinematics.math.TransformNR)

Aggregations

TransformNR (com.neuronrobotics.sdk.addons.kinematics.math.TransformNR)43 RotationNR (com.neuronrobotics.sdk.addons.kinematics.math.RotationNR)13 Matrix (Jama.Matrix)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 Affine (javafx.scene.transform.Affine)4 RuntimeErrorException (javax.management.RuntimeErrorException)4 InvalidConnectionException (com.neuronrobotics.sdk.common.InvalidConnectionException)3 CSG (eu.mihosoft.vrl.v3d.CSG)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 ParallelGroup (com.neuronrobotics.sdk.addons.kinematics.parallel.ParallelGroup)2 File (java.io.File)2 Group (javafx.scene.Group)2 Quat4f (javax.vecmath.Quat4f)2 Vector3f (javax.vecmath.Vector3f)2 InvalidRemoteException (org.eclipse.jgit.api.errors.InvalidRemoteException)2 TransportException (org.eclipse.jgit.api.errors.TransportException)2 Transform (com.bulletphysics.linearmath.Transform)1 IssueReportingExceptionHandler (com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler)1 CodeHandler (com.neuronrobotics.replicator.driver.interpreter.CodeHandler)1