Beispiel #1
0
  /**
   * Creates rotation matrix accord to current rotation and pushes it into GlStateManager. Don't
   * forget to pop (remove) it once you are done rendering with this rotation.
   */
  public void pushTransformMatrix() {
    GlStateManager.pushMatrix();
    // add operations in reverse order

    // first, rotate forward vector to rotForward
    float angle1 = Vector3f.angle(forward, rotForward);
    MathUtils.cross(forward, rotForward, tmp1);
    tmp1.normalise();

    // rotate up and rotate up
    tmpMatrix.setIdentity();
    tmpMatrix.rotate(angle1, tmp1);
    MathUtils.multiplyVec(tmpMatrix, up, tmp2);

    // L.s("Diff1: " + MathUtils.distanceSquared(up, tmp2));
    // L.s("Diff2: " + MathUtils.distanceSquared(rotUp, tmp3));

    // second, rotate up to rotUp
    float angle2 = Vector3f.angle(tmp2, rotUp);
    // L.s("Angle2: " + angle2);
    if (Math.abs(angle2) < Math.PI) {
      MathUtils.cross(tmp2, rotUp, tmp2);
      tmp2.normalise();
    } else {
      // full 180 degree rotation, use rotForward instead
      tmp2.set(rotForward);
    }
    // L.s("Tmp2: " + tmp2 + ", atan: " + Math.atan2(tmp2.z, tmp2.x) * MathUtils.radToDeg);
    GlStateManager.rotate(angle2 * MathUtils.radToDegF, tmp2.x, tmp2.y, tmp2.z); // */

    GlStateManager.rotate(angle1 * MathUtils.radToDegF, tmp1.x, tmp1.y, tmp1.z); // */

    invertedRotation.setIdentity();
    invertedRotation.rotate(angle2, tmp2);
    invertedRotation.rotate(angle1, tmp1);
    invertedRotation.invert();
  }