Exemple #1
0
    public void keyPressed(KeyEvent e) {
      keyMove = new Matrix4f();
      keyMove.setIdentity();
      Vector3f keyMovement = new Vector3f();

      switch (e.getKeyChar()) {
        case 's':
          keyMovement.z = -1 * scale;
          keyMove.setTranslation(keyMovement);
          break;

        case 'w':
          keyMovement.z = 1 * scale;
          keyMove.setTranslation(keyMovement);
          break;

        case 'a':
          keyMovement.x = 1 * scale;
          keyMove.setTranslation(keyMovement);
          break;

        case 'd':
          keyMovement.x = -1 * scale;
          keyMove.setTranslation(keyMovement);
          break;
        default:
          System.out.println("invalid key");
          break;
      }
    }
Exemple #2
0
  public void getPropertyComponents(List comps, final ObjectListener listener) {
    visibleCbx = new JCheckBox(getName(), visible);
    float[] rgb = color.get().getRGBComponents(null);
    slider = new JSlider(0, 100, (int) (rgb[0] * 100));

    float[] xyz = new float[3];
    direction.get(xyz);
    directionXFld = makeField("" + xyz[0], listener, "X Direction");
    directionYFld = makeField("" + xyz[1], listener, "Y Direction");
    directionZFld = makeField("" + xyz[2], listener, "Z Direction");

    double[] pxyz = new double[3];
    location.get(pxyz);
    locationXFld = makeField("" + pxyz[0], listener, "");
    locationYFld = makeField("" + pxyz[1], listener, "");
    locationZFld = makeField("" + pxyz[2], listener, "");

    List fldComps =
        Misc.newList(GuiUtils.rLabel("Direction:"), directionXFld, directionYFld, directionZFld);
    //
    // fldComps.addAll(Misc.newList(GuiUtils.rLabel("Location:"),locationXFld,locationYFld,locationZFld));

    comps.add(visibleCbx);
    GuiUtils.tmpInsets = new Insets(0, 2, 0, 0);
    comps.add(
        GuiUtils.vbox(
            slider, GuiUtils.left(GuiUtils.doLayout(fldComps, 4, GuiUtils.WT_N, GuiUtils.WT_N))));

    if (listener != null) {
      visibleCbx.addActionListener(listener);
      slider.addChangeListener(listener);
    }
  }
Exemple #3
0
    public void mouseDragged(MouseEvent e) {

      oldMoveVector = new Vector3f(fixOldX, oldY, oldZ);
      oldWorldZMoveVector = new Vector3f(oldX, oldY, oldZ);

      // get x,y
      newX = e.getX() / (adjustToScreenSize / 2) - 1; // used to be (float)jframe.getWidth()
      newY = 1 - e.getY() / (adjustToScreenSize / 2); // used to be (float)jframe.getWidth()
      newZ = calculateZ(newX, newY);

      newMoveVector = new Vector3f(fixNewX, newY, newZ);
      newWorldZMoveVector = new Vector3f(newX, newY, newZ);

      // now calculate the Camera movement
      Vector3f moveAxis = new Vector3f(); // moving around this axis
      moveAxis.cross(
          oldMoveVector,
          newMoveVector); // TODO identify, if the axis points down or upwards => adjust the angle
      float moveAngle = oldMoveVector.angle(newMoveVector); // moving by this angle

      // special Vector including the angle
      AxisAngle4f moveAxisAngle = new AxisAngle4f();
      moveAxisAngle.set(moveAxis, moveAngle);

      // calculate turning axis
      mouseTurn = new Matrix4f();
      mouseTurn.setIdentity();
      mouseTurn.set(moveAxisAngle); // the new Multiplication-Matrix

      // now calculate the World movement
      Vector3f worldMoveAxis = new Vector3f(); // moving around this axis
      worldMoveAxis.x = 0;
      worldMoveAxis.y = 0;
      worldMoveAxis.z = 1;
      float worldMoveAngle = oldWorldZMoveVector.angle(newWorldZMoveVector); // moving by this angle

      // adjust world Angle for turning back
      Vector3f worldMoveAxisTemp = new Vector3f();
      worldMoveAxisTemp.cross(oldWorldZMoveVector, newWorldZMoveVector);
      if (worldMoveAxisTemp.z < 0) {
        worldMoveAngle = -worldMoveAngle;
      }

      // special Vector including the angle
      AxisAngle4f worldMoveAxisAngle = new AxisAngle4f();
      worldMoveAxisAngle.set(worldMoveAxis, worldMoveAngle);

      // calculate turning axis
      mouseWorldTurn = new Matrix4f();
      mouseWorldTurn.setIdentity();
      mouseWorldTurn.set(worldMoveAxisAngle); // the new Multiplication-Matrix

      // override the initial starting values
      fixOldX = fixNewX;
      oldX = newX;
      oldY = newY;
      oldZ = newZ;
    }