/**
  * <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();
 }
  public void updateRotationMatrix() {

    if (oldEmit.equals(worldEmit)) return;

    float upDotEmit = upVector.dot(worldEmit);
    if (FastMath.abs(upDotEmit) > 1.0d - FastMath.DBL_EPSILON) {
      absUpVector.x = upVector.x <= 0.0f ? -upVector.x : upVector.x;
      absUpVector.y = upVector.y <= 0.0f ? -upVector.y : upVector.y;
      absUpVector.z = upVector.z <= 0.0f ? -upVector.z : upVector.z;
      if (absUpVector.x < absUpVector.y) {
        if (absUpVector.x < absUpVector.z) {
          absUpVector.x = 1.0f;
          absUpVector.y = absUpVector.z = 0.0f;
        } else {
          absUpVector.z = 1.0f;
          absUpVector.x = absUpVector.y = 0.0f;
        }
      } else if (absUpVector.y < absUpVector.z) {
        absUpVector.y = 1.0f;
        absUpVector.x = absUpVector.z = 0.0f;
      } else {
        absUpVector.z = 1.0f;
        absUpVector.x = absUpVector.y = 0.0f;
      }
      absUpVector.subtract(upVector, abUpMinUp);
      absUpVector.subtract(worldEmit, upXemit);
      float f4 = 2.0f / abUpMinUp.dot(abUpMinUp);
      float f6 = 2.0f / upXemit.dot(upXemit);
      float f8 = f4 * f6 * abUpMinUp.dot(upXemit);
      float af1[] = {abUpMinUp.x, abUpMinUp.y, abUpMinUp.z};
      float af2[] = {upXemit.x, upXemit.y, upXemit.z};
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          matData[i][j] = (-f4 * af1[i] * af1[j] - f6 * af2[i] * af2[j]) + f8 * af2[i] * af1[j];
        }
        matData[i][i]++;
      }

    } else {
      upVector.cross(worldEmit, upXemit);
      float f2 = 1.0f / (1.0f + upDotEmit);
      float f5 = f2 * upXemit.x;
      float f7 = f2 * upXemit.z;
      float f9 = f5 * upXemit.y;
      float f10 = f5 * upXemit.z;
      float f11 = f7 * upXemit.y;
      matData[0][0] = upDotEmit + f5 * upXemit.x;
      matData[0][1] = f9 - upXemit.z;
      matData[0][2] = f10 + upXemit.y;
      matData[1][0] = f9 + upXemit.z;
      matData[1][1] = upDotEmit + f2 * upXemit.y * upXemit.y;
      matData[1][2] = f11 - upXemit.x;
      matData[2][0] = f10 - upXemit.y;
      matData[2][1] = f11 + upXemit.x;
      matData[2][2] = upDotEmit + f7 * upXemit.z;
    }
    rotMatrix.set(matData);
    oldEmit.set(worldEmit);
  }
示例#3
0
 void readMe() {
   path = file.readString(64);
   readVecFloat(origin);
   float[] axisFs = new float[9];
   for (int i = 0; i < 9; i++) axisFs[i] = file.readFloat();
   axis = new Matrix3f();
   axis.set(axisFs);
 }
示例#4
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();
 }
示例#5
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);
 }
示例#6
0
 /**
  * Rotate a node around a lock axies
  *
  * @param node
  * @param lockAxis
  */
 public static void rotate(Spatial node, Vector3f lockAxis, float angle) {
   incr.fromAngleAxis(angle, lockAxis);
   rotateByIncr(node);
 }