Example #1
0
  /**
   * Update Frustum
   *
   * @param gm GameResources
   */
  public void calculateFrustum(Matrix4f projectionMatrix, Camera camera) {
    float[] clip = new float[16];

    Matrix4f.mul(projectionMatrix, Maths.createViewMatrix(camera), clip_);
    clip_b.rewind();
    clip_.store(clip_b);
    clip_b.rewind();
    clip_b.get(clip);

    m_Frustum[RIGHT][A] = clip[3] - clip[0];
    m_Frustum[RIGHT][B] = clip[7] - clip[4];
    m_Frustum[RIGHT][C] = clip[11] - clip[8];
    m_Frustum[RIGHT][D] = clip[15] - clip[12];
    normalizePlane(m_Frustum, RIGHT);
    m_Frustum[LEFT][A] = clip[3] + clip[0];
    m_Frustum[LEFT][B] = clip[7] + clip[4];
    m_Frustum[LEFT][C] = clip[11] + clip[8];
    m_Frustum[LEFT][D] = clip[15] + clip[12];
    normalizePlane(m_Frustum, LEFT);
    m_Frustum[BOTTOM][A] = clip[3] + clip[1];
    m_Frustum[BOTTOM][B] = clip[7] + clip[5];
    m_Frustum[BOTTOM][C] = clip[11] + clip[9];
    m_Frustum[BOTTOM][D] = clip[15] + clip[13];
    normalizePlane(m_Frustum, BOTTOM);
    m_Frustum[TOP][A] = clip[3] - clip[1];
    m_Frustum[TOP][B] = clip[7] - clip[5];
    m_Frustum[TOP][C] = clip[11] - clip[9];
    m_Frustum[TOP][D] = clip[15] - clip[13];
    normalizePlane(m_Frustum, TOP);
    m_Frustum[BACK][A] = clip[3] - clip[2];
    m_Frustum[BACK][B] = clip[7] - clip[6];
    m_Frustum[BACK][C] = clip[11] - clip[10];
    m_Frustum[BACK][D] = clip[15] - clip[14];
    normalizePlane(m_Frustum, BACK);
    m_Frustum[FRONT][A] = clip[3] + clip[2];
    m_Frustum[FRONT][B] = clip[7] + clip[6];
    m_Frustum[FRONT][C] = clip[11] + clip[10];
    m_Frustum[FRONT][D] = clip[15] + clip[14];

    normalizePlane(m_Frustum, FRONT);
  }
Example #2
0
  public Ray(Matrix4f proj, Matrix4f view, Vector2f mouse, int width, int height) {
    Vector3f v = new Vector3f();
    v.x = (((2.0f * mouse.x) / width) - 1) / proj.m00;
    v.y = -(((2.0f * mouse.y) / height) - 1) / proj.m11;
    v.z = 1.0f;

    Matrix4f invert_view = Matrix4f.invert(view, null);

    Vector3f ray_direction = new Vector3f();
    ray_direction.x = v.x * invert_view.m00 + v.y * invert_view.m10 + v.z * invert_view.m20;
    ray_direction.y = v.x * invert_view.m01 + v.y * invert_view.m11 + v.z * invert_view.m21;
    ray_direction.z = v.x * invert_view.m02 + v.y * invert_view.m12 + v.z * invert_view.m22;

    Vector3f ray_origin = new Vector3f(invert_view.m30, invert_view.m31, invert_view.m32);

    init(ray_origin, ray_direction);
  }