Пример #1
0
  /**
   * Transforms position of a block, so that it get's rendered at correct point. If you wish to draw
   * a block at a point, pass it to this method once you have called pushTransformMatrix() and draw
   * it at the result instead
   *
   * @param vec bottom-left corner of the place where you want to draw
   * @param result result is stored here: coordinates that you should use so the rotation matrix
   *     moves it to correct place. Use null to create new vector.
   * @return result
   */
  public Vector3f transform(Vector3f vec, Vector3f result) {
    if (result == null) result = new Vector3f();

    result.set(vec.x + .5f, vec.y + .5f, vec.z + .5f);
    MathUtils.multiplyPos(invertedRotation, result);
    result.set(result.x - .5f, result.y - .5f, result.z - .5f);
    return result;
  }
Пример #2
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();
  }
Пример #3
0
 /**
  * spins the camera clockwise, moving the rotUp vector towards the rotRight vector, but the world
  * before you seems to spin counter-clockwise, don't be fooled!
  *
  * @param angle rotation in radians
  */
 public void cameraSpin(float angle) {
   tmpMatrix.setIdentity();
   tmpMatrix.rotate(angle, rotForward);
   MathUtils.multiplyPos(tmpMatrix, rotUp);
   MathUtils.multiplyPos(tmpMatrix, rotRight);
 }