示例#1
0
  public void prepareCorak(
      String projectPath, CorakLSystem cor, CorakDataObject obj, boolean encloseOBJ) {

    this.projectPath = projectPath;

    // initiate our "turtle" -> Canting
    canting = new Canting(cor, obj);

    // start creating shapes based on Cor
    timer = System.currentTimeMillis();
    canting.generate(encloseOBJ);

    BoundingSphere lightingBounds = new BoundingSphere(new Point3d(0, 0, 0), FARTHEST);
    camLamp = new PointLight();
    camLamp.setCapability(PointLight.ALLOW_POSITION_READ);
    camLamp.setCapability(PointLight.ALLOW_POSITION_WRITE);
    camLamp.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    camLamp.setInfluencingBounds(lightingBounds);

    ambient = new AmbientLight();
    ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    ambient.setInfluencingBounds(lightingBounds);

    canting.getBatikBG().addChild(camLamp);
    canting.getBatikBG().addChild(ambient);

    // attach generated shapes to root TransformGroup
    Enumeration kaintgchildren = kainTG.getAllChildren();
    while (kaintgchildren.hasMoreElements()) {
      Node child = (Node) kaintgchildren.nextElement();
      if (child instanceof Measurer) {
        ((Measurer) child).removeAllChildren();
      } else {
        kainTG.removeChild(child);
      }
    }
    //        canting.getBatikBG().compile();
    kainTG.addChild(canting.getBatikBG());

    timer = System.currentTimeMillis() - timer;
    // System.out.println("Timer= " + timer);

    bs = (BoundingSphere) canting.getBatikBG().getBounds();
  }
示例#2
0
  @Override
  public void mouseWheelMoved(MouseWheelEvent e) {
    if ((canting.getCor() != null) && !pressed) {
      // (canting.getCor() != null) -> make sure object exists
      // !pressed -> zooming while dragging can mess up savedCameraPos

      int amount = e.getWheelRotation();

      if (isADown || isWDown || isEDown) { // mod structure

        CorakLSystem cor = getCanting().getCor();

        if (isADown) {
          cor.setAngle(cor.getAngle() - amount);
        }

        if (isWDown) {
          if (amount < 0 || cor.getWidth() > 1) {
            cor.setWidth(cor.getWidth() - amount);
          }
        }

        if (isEDown) {
          if (amount < 0 || cor.getLength() > 1) {
            cor.setLength(cor.getLength() - amount);
          }
        }

        this.prepareCorak(projectPath, cor, getCanting().getCorDataObject(), false);

        justModAppearance = true;

      } else { // zoom
        // get mouse pos in 3d
        this.getPixelLocationInImagePlate(e.getX(), e.getY(), mousePos3D);
        Transform3D mouseTransform = new Transform3D();
        this.getImagePlateToVworld(mouseTransform);
        mouseTransform.transform(mousePos3D);

        // movement vector from camera to mouse, zoom in
        Vector3d moveV = new Vector3d();
        moveV.sub(cameraPos, mousePos3D);
        moveV.normalize();
        double factor = camDist / 10;

        // if scroll down, movement from mouse to camera, zoom out
        moveV.scale(factor * amount);

        Transform3D zoom = new Transform3D();
        zoom.setTranslation(moveV);
        zoom.transform(cameraPos);
        zoom.transform(cameraFocus);

        if (currentProjectionMode == Scene3DObserverCookie.Projection.PARALLEL) {
          // if parallel projection
          // zoom don't make any difference, so, scale the view

          if (e.getWheelRotation() < 0) {
            view.setScreenScale(view.getScreenScale() * 1.109);
          } else {
            view.setScreenScale(view.getScreenScale() / 1.109);
          }
        }

        moveCamera();
      }
    }
  }
示例#3
0
  @Override
  public void mouseDragged(MouseEvent e) {

    if (e.getX() > 0
        && e.getX() < this.getWidth()
        && e.getY() > 0
        && e.getY() < this.getHeight()
        && (canting.getCor() != null)) {
      // left/right click drag: move camera left/right/up/down
      if (lastClicked == 1 || lastClicked == 3) {

        Transform3D shift = new Transform3D();

        // distance of mouse movement
        double distH = -distanceConvert((double) e.getX() - lastMousePos1.x);
        double distV = distanceConvert((double) e.getY() - lastMousePos1.y);

        Vector3d shiftHVec = getCameraLeftDir();
        Vector3d shiftVVec = new Vector3d(up);

        shiftHVec.normalize();
        shiftHVec.scale(distH);
        shiftVVec.normalize();
        shiftVVec.scale(distV);

        shift.setTranslation(shiftHVec);
        shift.transform(cameraPos);
        shift.transform(cameraFocus);
        shift.setTranslation(shiftVVec);
        shift.transform(cameraPos);
        shift.transform(cameraFocus);

        lastMousePos1.set(e.getX(), e.getY());
      } else // middle click drag: rotate
      if (lastClicked == 2) {

        // distance of mouse movement
        double distH = -((double) e.getX() - lastMousePos2.x);
        double distV = (double) e.getY() - lastMousePos2.y;

        // distance to angle
        distH = distH / this.getWidth() * 180.0;
        distV = distV / this.getHeight() * 180.0;

        if (!e.isControlDown()) {
          // rotate
          pitchCamera(Math.toRadians(-distV));
          yawCamera(Math.toRadians(distH));
        } else {
          // roll
          if (e.getX() > this.getWidth() / 2) {
            distV = -distV;
          }
          if (e.getY() > this.getHeight() / 2) {
            distH = -distH;
          }
          rollCamera(Math.toRadians(distH * 2));
          rollCamera(Math.toRadians(distV * 2));
        }

        lastMousePos2.set(e.getX(), e.getY());
      }
      moveCamera();
    }
  }
示例#4
0
  @Override
  public void mouseMoved(MouseEvent e) {
    if (e.getX() > 0
        && e.getX() < this.getWidth()
        && e.getY() > 0
        && e.getY() < this.getHeight()
        && (canting.getCor() != null)
        && measuring
        && measurementVisible) {
      MyPickResult result = getMouseIntersection(e, true);
      Point3d pos = result.getPoint();
      if (pos != null) {
        if (measurer == null) {
          measurer = new Measurer(pos);
          kainTG.addChild(measurer);
          initSnapList();
        } else {
          measurer.getMarker().updatePos(pos);
          measurer.getMarker().setVisible(true);
        }
        hoveredNode = result.getNode();
      } else {
        hoveredNode = null;
      }

      // if hovers any mark, highlight it
      if (hoveredNode != null && hoveredNode.getParent().getParent().getParent() instanceof Mark) {

        // before highlight, unhighlight previous mark
        if (lastHoveredNode != null) {
          if (selectedNode != null
              && lastHoveredNode.getParent().getParent().getParent()
                  == selectedNode.getParent().getParent().getParent()) // if it is selected
          {
            ((Mark) selectedNode.getParent().getParent().getParent()).select();
          } else {
            ((Mark) lastHoveredNode.getParent().getParent().getParent()).unHighlight();
          }
          lastHoveredNode = null;
        }

        // highlight
        ((Mark) hoveredNode.getParent().getParent().getParent()).highlight();
        lastHoveredNode = hoveredNode;

      } else {
        // unhighlight previous mark
        if (lastHoveredNode != null) {
          if (selectedNode != null
              && lastHoveredNode.getParent().getParent().getParent()
                  == selectedNode.getParent().getParent().getParent()) // if it is selected
          {
            ((Mark) selectedNode.getParent().getParent().getParent()).select();
          } else {
            ((Mark) lastHoveredNode.getParent().getParent().getParent()).unHighlight();
          }
          lastHoveredNode = null;
        }
      }
    }

    if (e.getX() > 0
        && e.getX() < this.getWidth()
        && e.getY() > 0
        && e.getY() < this.getHeight()
        && (canting.getCor() != null)
        && choosingPivotPoint) {
      MyPickResult result = getMouseIntersection2(e);
      Point3d pos = result.getPoint();
      if (pos != null) {
        if (pivotPointAdjustor == null) {
          pivotPointAdjustor = new PivotPointAdjustor(pos);
          kainTG.addChild(pivotPointAdjustor);
        } else {
          pivotPointAdjustor.getPlacer().updatePos(pos);
        }
      }
    }
  }
示例#5
0
 public void refreshAppearance() {
   canting.setAppearance(currentAppearance, lightState);
 }
示例#6
0
 private void initSnapList() {
   LinkedList<Point3d> allVertexes = canting.getAllVertex();
   snapList = allVertexes;
 }