glm::mat4 projection(0); glm::mat4 projectionInv(0); //the frustum in normalized coordinates vector<glm::vec4> NDCCube; NDCCube.push_back(glm::vec4(-1.0f, -1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, -1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, -1.0f, 1.0f, -0.0f)); NDCCube.push_back(glm::vec4(-1.0f, -1.0f, 1.0f, -0.0f)); NDCCube.push_back(glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, 1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, 1.0f, 1.0f, -0.0f)); NDCCube.push_back(glm::vec4(-1.0f, 1.0f, 1.0f, -0.0f)); /* Get the current PROJECTION from OpenGL */ glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)(glm::value_ptr(projection))); //calculate the inverse of projection matrix. Hopefully, this'll get us the frustum when multiplied //by coords of a cube. projectionInv = glm::inverse(projection); //push back vertices for(int i = 0; i < 8; i++) { glm::vec4 tempvec; tempvec = projectionInv * NDCCube.at(i); //multiply by projection matrix inverse to obtain frustum vertex frustumVertices.push_back(Vector3(tempvec.x, tempvec.y, tempvec.z)); }

### Show differencesHistory of post edits

### #ActualNaked Shooter

Posted 21 October 2012 - 04:16 PM

Hi. I'm trying to get the frustum vertices by using the perspective projection matrix's inverse. I'm trying to take a cube with the vertices { (-1,-1,-1), (1,-1,-1) ... } and multiply each vertex by the inverse of the perspective matrix, hoping to get the frustum. This isn't working, however. I am aware that there's a lighthouse3d tutorial, and I just might bite the bullet and go through it, but I'm just curious why this isn't working.

### #2Naked Shooter

Posted 21 October 2012 - 03:40 PM

Hi. I'm trying to get the frustum vertices by using the perspective projection matrix's inverse. I'm trying to take a cube with the vertices { (-1,-1,-1), (1,-1,-1) ... } and multiply each vertex by the inverse of the perspective matrix, hoping to get the frustum. This isn't working, however. Am I missing something?

glm::mat4 projection(0); glm::mat4 projectionInv(0); //the frustum in normalized coordinates vector<glm::vec4> NDCCube; NDCCube.push_back(glm::vec4(-1.0f, -1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, -1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, -1.0f, 1.0f, -0.0f)); NDCCube.push_back(glm::vec4(-1.0f, -1.0f, 1.0f, -0.0f)); NDCCube.push_back(glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, 1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, 1.0f, 1.0f, -0.0f)); NDCCube.push_back(glm::vec4(-1.0f, 1.0f, 1.0f, -0.0f)); /* Get the current PROJECTION from OpenGL */ glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)(glm::value_ptr(projection))); //calculate the inverse of projection matrix. Hopefully, this'll get us the frustum when multiplied //by coords of a cube. projectionInv = glm::inverse(projection); //push back vertices for(int i = 0; i < 8; i++) { glm::vec4 tempvec; tempvec = projectionInv * NDCCube.at(i); //multiply by projection matrix inverse to obtain frustum vertex frustumVertices.push_back(Vector3(tempvec.x, tempvec.y, tempvec.z)); }

### #1Naked Shooter

Posted 21 October 2012 - 03:39 PM

Hi. I'm trying to get the frustum vertices by using the perspective projection matrix's inverse. I'm trying to take a cube with the vertices { (-1,-1,-1), (1,-1,-1) ... } and multiply each vertex by the inverse of the perspective matrix, hoping to get the frustum. This isn't working, however. Am I missing something?

glm::mat4 projection(0); glm::mat4 projectionInv(0); //the frustum in normalized coordinates vector<glm::vec4> NDCCube; NDCCube.push_back(glm::vec4(-1.0f, -1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, -1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, -1.0f, 1.0f, -0.0f)); NDCCube.push_back(glm::vec4(-1.0f, -1.0f, 1.0f, -0.0f)); NDCCube.push_back(glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, 1.0f, -1.0f, 1.0f)); NDCCube.push_back(glm::vec4(1.0f, 1.0f, 1.0f, -0.0f)); NDCCube.push_back(glm::vec4(-1.0f, 1.0f, 1.0f, -0.0f)); /* Get the current PROJECTION and MODELVIEW matrices from OpenGL */ glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)(glm::value_ptr(projection))); //calculate the inverse of projection matrix. Hopefully, this'll get us the frustum when multiplied //by coords of a cube. projectionInv = glm::inverse(projection); //push back vertices for(int i = 0; i < 8; i++) { glm::vec4 tempvec; tempvec = projectionInv * NDCCube.at(i); //multiply by projection matrix inverse to obtain frustum vertex frustumVertices.push_back(Vector3(tempvec.x, tempvec.y, tempvec.z)); }