Example #1
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;
    }
Example #2
0
  protected void moveOrientation() {
    if (Camera.host != owner || !PerfIO.holdMouse) return;

    AxisAngle4f tmp = new AxisAngle4f(Camera.right, -PerfIO.dy * 0.001f);

    Quat4f rot = new Quat4f();
    rot.set(tmp);
    owner.getOrientWritable().mul(rot, owner.getOrientation());
    owner.getOrientWritable().normalize();

    tmp.set(0, Camera.up.y > 0 ? 1 : -1, 0, PerfIO.dx * 0.001f);
    rot.set(tmp);
    owner.getOrientWritable().mul(rot, owner.getOrientWritable());

    owner.flushChanges();
  }