I was trying to determine if an object (sphere) is inside a view frustum. My strategy was first to get the view matrix:

glm::lookAt(cameraPosition, lookAtPosition, cameraUp);

Where cameraPosition is the position of the camera, lookAtPosition is calculate by cameraPosition + cameraDirection and cameraUp is pretty much self-explanatory.

After obtaining the view matrix, I calculate the 8 vertices of the frustum in the camera view, then multiply the inverse of the view matrix by each point to get the coordinate of them in the world space.

Using these 8 points in the world space, I can construct the 6 planes by using cross products (so their normals will point inward). Then I take the dot product of the object vector (I get the vector by subtracting the object position with an arbitrary point on that plane) with the normal vector of each plane, if it is positive for all 6, I know it's inside the frustum.

So my questions are:

  • Is the camera view is always set at (0,0,0) and looking at the positive z direction?
  • The view matrix transform the world view into the camera view, if I use the inverse of it to transform the camera view to the world view, is it correct?

My frustum is opposite with my cameraDirection which causes nothing to be seen on the screen (but it still drawing stuff in the back of my camera).


It is common that the camera is pointing towards negative Z, in order to satisfy right hand rule. So you need to know the convention.

As for theinverse matrix of the camera matrix. Sort of yes. You can do it. However the camera matrix is a homogeneous space. While generally our other matrixes are affine spaces. If you take care of the distinction and do the proper camera divide, if tge camera needs one. Then yes you could do that.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.