コード例 #1
0
  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);
  }
コード例 #2
0
ファイル: Md3ToJme.java プロジェクト: jmecn/learnJME3
 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);
 }