Beispiel #1
0
  /** converts to quaternion */
  public Quaternion quaternion() {
    if (a.x + b.y + c.z >= 0) {
      final float s = GMath.sqrt(1 + a.x + b.y + c.z) * 2;
      return new Quaternion(s / 4, (c.y - b.z) / s, (a.z - c.x) / s, (b.x - a.y) / s);
    }
    if (a.x >= b.y && a.x >= c.z) {
      final float s = GMath.sqrt(1 + a.x - b.y - c.z) * 2;
      return new Quaternion((c.y - b.z) / s, s / 4, (a.y + b.x) / s, (c.x + a.z) / s);
    }
    if (b.y >= c.z) {
      final float s = GMath.sqrt(1 - a.x + b.y - c.z) * 2;
      return new Quaternion((a.z - c.x) / s, (a.y + b.x) / s, s / 4, (b.z + c.y) / s);
    }

    final float s = GMath.sqrt(1 - a.x - b.y + c.z) * 2;
    return new Quaternion((b.x - a.y) / s, (c.x + a.z) / s, (b.z + c.y) / s, s / 4);
  }
Beispiel #2
0
 public float normalizeIfNot() {
   float magSq = magnitudeSquared();
   if (magSq != 1) {
     float mag = GMath.sqrt(magSq);
     this.w = w / mag;
     this.x = x / mag;
     this.y = y / mag;
     this.z = z / mag;
     return mag;
   } else {
     return 1;
   }
 }
Beispiel #3
0
 public float magnitude() {
   return GMath.sqrt(magnitudeSquared());
 }