/**
  * <code>performAction</code> rotates the camera about it's up vector or lock axis at a speed of
  * movement speed * time. Where time is the time between frames and 1 corresponds to 1 second.
  *
  * @see com.jme.input.action.KeyInputAction#performAction(InputActionEvent)
  */
 public void performAction(InputActionEvent evt) {
   incr.loadIdentity();
   if (lockAxis == null) {
     node.getLocalRotation().getRotationColumn(1, tempVa);
     tempVa.normalizeLocal();
     incr.fromAngleNormalAxis(-speed * evt.getTime(), tempVa);
   } else {
     incr.fromAngleNormalAxis(-speed * evt.getTime(), lockAxis);
   }
   node.getLocalRotation()
       .fromRotationMatrix(incr.mult(node.getLocalRotation().toRotationMatrix(tempMa), tempMb));
   node.getLocalRotation().normalize();
 }
 /**
  * <code>performAction</code> moves the camera along the negative left vector for a given distance
  * of speed * time.
  *
  * @see com.jme.input.action.KeyInputAction#performAction(InputActionEvent)
  */
 public void performAction(InputActionEvent evt) {
   Vector3f loc = node.getLocalTranslation();
   loc =
       loc.addLocal(
           node.getLocalRotation().getRotationColumn(0, tempVa).multLocal(-speed * evt.getTime()));
   node.setLocalTranslation(loc);
 }
 /**
  * Sets an object to animate. The object's index is <code>index</code> and it's parent index is
  * <code>parentIndex</code>. A parent index of -1 indicates it has no parent.
  *
  * @param objChange The spatial that will be updated by this SpatialTransformer.
  * @param index The index of that spatial in this transformer's array
  * @param parentIndex The parentIndex in this transformer's array for this Spatial
  */
 public void setObject(Spatial objChange, int index, int parentIndex) {
   toChange[index] = objChange;
   pivots[index].setTranslation(objChange.getLocalTranslation());
   pivots[index].setScale(objChange.getLocalScale());
   pivots[index].setRotationQuaternion(objChange.getLocalRotation());
   parentIndexes[index] = parentIndex;
 }
  public static void deepRotate(Spatial s, int x, int y, int z) {
    Quaternion q = s.getLocalRotation();
    //  only transform objects with non-zero rotation
    if (q.x != 0 || q.y != 0 || q.z != 0 || q.w != 1) {
      s.setLocalRotation(q.addLocal(Rotator.fromThreeAngles(x, y, z)));
    }

    if (s instanceof Node) {
      if (((Node) s).getChildren() != null) {
        for (Spatial child : ((Node) s).getChildren()) {
          deepRotate(child, x, y, z);
        }
      }
    }
  }
  /**
   * Configurable method to print information about an object.
   *
   * @param toUse
   * @param s
   * @param recursive
   * @param translation
   * @param rotation
   * @param scale
   */
  public static void printInformation(
      Logger toUse,
      Spatial s,
      boolean recursive,
      boolean translation,
      boolean rotation,
      boolean scale) {
    logger.info(s.getClass().getSimpleName() + ": " + s.getName());
    if (translation)
      toUse.info(
          s.getName()
              + " Translation: "
              + s.getLocalTranslation().x
              + ","
              + s.getLocalTranslation().y
              + ","
              + s.getLocalTranslation().z);
    if (rotation) {
      float[] angles = s.getLocalRotation().toAngles(null);
      toUse.info(s.getName() + " Rotation: " + angles[0] + "," + angles[1] + "," + angles[2]);
    }
    if (scale)
      toUse.info(
          s.getName()
              + " Scale: "
              + s.getLocalScale().x
              + ","
              + s.getLocalScale().y
              + ","
              + s.getLocalScale().z);

    if (recursive) {
      if (s instanceof Node) {
        if (((Node) s).getQuantity() > 0) {
          for (Spatial child : ((Node) s).getChildren()) {
            printInformation(toUse, child, recursive, translation, rotation, scale);
          }
        }
      }
    }
  }
 public void update(float time) {
   // //TODO: We only take care of walking at the moment
   // 2 events ?? why ?
   super.update(time);
   // TODO: Take this out and register individual actions !
   Vector3f location = player.getLocalTranslation();
   Quaternion rotation = player.getLocalRotation();
   boolean forward = KeyBindingManager.getKeyBindingManager().isValidCommand(PROP_KEY_FORWARD);
   boolean backward = KeyBindingManager.getKeyBindingManager().isValidCommand(PROP_KEY_BACKWARD);
   int moveStatus = ClientPlayerData.getInstance().getPlayer().getMoveStatus();
   // TODO: Refactor !
   if (!(forward && backward)) {
     if (!forward && (moveStatus == Globals.WALKING || moveStatus == Globals.RUNNING)) {
       sendMovementEvent(Globals.STANDING, EventTypes.MOVEMENT_STOP_WALK, location, rotation);
     } else if (forward && moveStatus != Globals.WALKING) {
       sendMovementEvent(Globals.WALKING, EventTypes.MOVEMENT_START_WALK, location, rotation);
     } else if (!backward && moveStatus == Globals.WALKING_BACKWARD) {
       sendMovementEvent(Globals.STANDING, EventTypes.MOVEMENT_STOP_WALK, location, rotation);
     } else if (backward && moveStatus != Globals.WALKING_BACKWARD) {
       sendMovementEvent(
           Globals.WALKING_BACKWARD, EventTypes.MOVEMENT_START_WALK_BACKWARDS, location, rotation);
     }
   }
   boolean turnLeft = KeyBindingManager.getKeyBindingManager().isValidCommand(PROP_KEY_LEFT);
   boolean turnRight = KeyBindingManager.getKeyBindingManager().isValidCommand(PROP_KEY_RIGHT);
   if (!(turnRight && turnLeft)) {
     int turnStatus = ClientPlayerData.getInstance().getPlayer().getTurnStatus();
     if (turnLeft && turnStatus != Globals.TURN_LEFT) {
       sendTurnMovementEvent(
           Globals.TURN_LEFT, EventTypes.MOVEMENT_START_TURN_LEFT, location, rotation);
     } else if (!turnLeft && turnStatus == Globals.TURN_LEFT) {
       sendTurnMovementEvent(Globals.NO_TURN, EventTypes.MOVEMENT_STOP_TURN, location, rotation);
     } else if (turnRight && turnStatus != Globals.TURN_RIGHT) {
       sendTurnMovementEvent(
           Globals.TURN_RIGHT, EventTypes.MOVEMENT_START_TURN_RIGHT, location, rotation);
     } else if (!turnRight && turnStatus == Globals.TURN_RIGHT) {
       sendTurnMovementEvent(Globals.NO_TURN, EventTypes.MOVEMENT_STOP_TURN, location, rotation);
     }
   }
 }
Example #7
0
 /**
  * Rotate a node by the current setting of incr matrix
  *
  * @param node The node to rotate
  */
 private static void rotateByIncr(Spatial node) {
   node.getLocalRotation()
       .fromRotationMatrix(incr.mult(node.getLocalRotation().toRotationMatrix(tempMa), tempMb));
   node.getLocalRotation().normalize();
 }
Example #8
0
 /**
  * Rotate a node around one of its axes
  *
  * @param node The node to rotate
  * @param localAxisIndex The index of the local axis around which to rotate
  */
 public static void rotate(Spatial node, int localAxisIndex, float angle) {
   incr.fromAngleNormalAxis(
       angle, node.getLocalRotation().getRotationColumn(localAxisIndex, tempVa).normalizeLocal());
   rotateByIncr(node);
 }