Extract corners of projection matrix...

Started by
10 comments, last by uglybdavis 10 years, 10 months ago

Vector worldSpace = debugCam.GetView().Inverse() * viewSpace;

It should work with this smile.png

You need the inverse of the view matrix to go from view space to world space

Good luck

Advertisement

Thats a tad misleading. I actually store the cameras GetView returns the cameras world position, not the inverse of its world.

In any case, said matrix only contains translation data in my scene, no scaling. Changing it changes nothing sad.png

I think the issue is with my perspective function....


void Camera::Perspective(float fov, float aspect, float zNear, float zFar) {
    float ymax = zNear * tanf(fov * 3.14f / 360.0f);
    float xmax = ymax * aspect;
    float ymin = -ymax;
    float xmin = -xmax;
    
    m_matProjection = Matrix();
    
    m_matProjection.mat16f[0] = (2.0f * zNear)/(xmax - xmin);
    m_matProjection.mat16f[5] = (2.0f * zNear)/(ymax - ymin);
    m_matProjection.mat16f[8] = (xmax + xmin) / (xmax - xmin);
    m_matProjection.mat16f[9] = (ymax + ymin) / (ymax - ymin);
    m_matProjection.mat16f[10] = -((zFar + zNear)/(zFar - zNear));
    m_matProjection.mat16f[11] = -1.0f;
    m_matProjection.mat16f[14] = -((2.0f * zFar * zNear)/(zFar - zNear));
    //m_matProjection.mat16f[15] = 0.0f; // This is currently 1
}

I tried copy / paste from a few other sources, but same results every time....

EDIT: found the solution at: http://www.opengl.org/discussion_boards/showthread.php/159434-draw-frustum-outlines

Apparently that cube i'm offsetting is supposed to be (-1, -1, near) (1, 1, far)

W00t!!!

Actually, one last thing, is the last element of the projection matrix supposed to be one or zero? If zero, why?

This topic is closed to new replies.

Advertisement