Ejemplo n.º 1
0
  private void setupProjectionMatrix() {
    projectionMatrix = new Matrix4f();
    float fieldOfView = (float) (Math.PI * 2 * 60 / 360);
    float aspectRatio = (float) WIDTH / (float) HEIGHT;
    float near_plane = 0.1f;
    float far_plane = 1000f;

    float y_scale = this.coTangent(fieldOfView / 2f);
    float x_scale = y_scale / aspectRatio;
    float frustum_length = far_plane - near_plane;

    projectionMatrix.m00 = x_scale;
    projectionMatrix.m11 = y_scale;
    projectionMatrix.m22 = -((far_plane + near_plane) / frustum_length);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2 * near_plane * far_plane) / frustum_length);
    projectionMatrix.m33 = 0;
  }