Search code examples
openglmatrixprojection

Outside of projection matrix? (OpenGL)


Given a model-view-projection matrix, how would I determine if an object is displayed on the screen? Determining if it is within the clipping bounds is easy, but how do I use the numbers if the mvp matrix to determine if object is too far left/right/high/low given the object position and the screen width and height in pixels? (For simplicity, we can say that we only care about the object's center of mass)


Solution

  • simply apply the mvp matrixes to the center: centerInScreen = projMartix*viewMatrix*modelMatrix*center

    then see if centerInScreen is inside the -1,-1 to 1,1 box, (which opengl maps to the viewport)