1
\$\begingroup\$

I have a simple orthographic projection that is rotated at an arbitrary angle on any combination of the three axes. I am trying to use these matrices to calculate the viewable area of the screen for clipping purposes.

All of the examples I can find are old, use one game engine or another, mostly deal with perspective projection (and seem more complex than they need to be for orthographic projection), just plain don't work, or I am not understanding the calculations enough to plug in my own values and get the answer I am looking for.

I aim not only to get a functional (and relatively fast) way to achieve my goal, but hopefully understand the why and how in the process.

Does anyone here know how to calculate these values given the projection/view/model matrices?

I work with OpenGL, in C++, using glm for matrix calculations.

Update #1

I realize my original post might not be clear enough so I will try and clarify a bit.

Imagine I had an ortho projection like: glm::ortho(0.0f, 2.0f, 0.0f , 1.0f, -10.0f, 10.0f);

Given no rotation or other translation of any kind, then the information I am looking for would coincide exactly with the values I put into the ortho. Taking the X axis as an example, I want to know that the first visible X coordinate is 0.0 and the last visible X coordinate is 2.0. If I were to translate this by 0.5 on the X axis, then the values would be 0.5 and 2.5 respectively.

Now if I rotated the view by 90 degrees, then the first visible X would be 0.0 and the last visible X would be 1.0 (obviously depending on the rotation origin), because it can now only display what it can fit on the vertical screen area.

Given any arbitrary rotation, scaling or translation (on any axis) how would I get that information (and the same for Y and Z)?

\$\endgroup\$
5
  • \$\begingroup\$ You're looking for the rectangular prism of world space that will be within the camera's clipping bounds? \$\endgroup\$
    – DMGregory
    Nov 28, 2017 at 4:28
  • \$\begingroup\$ @DMGregory yes, exactly. \$\endgroup\$
    – latreides
    Nov 28, 2017 at 4:31
  • \$\begingroup\$ How would you describe such prism? With coordinates of corners? \$\endgroup\$ Nov 29, 2017 at 15:58
  • \$\begingroup\$ @HolyBlackCat I am looking for the smallest and largest X, Y and Z value that can be seen within the viewport. This could be represented as a range for each axis, or (maybe) as a single vec3 point in the middle of a cube that represents the min/max visible values for each axis. Currently I have this as a pre-calculated range for each axis, with a set rotation and locked camera. It is my goal to be able to calculate this based on the current projection and view models so that I can allow for free camera movement and rotation. \$\endgroup\$
    – latreides
    Nov 29, 2017 at 21:52
  • \$\begingroup\$ See my updated answer. \$\endgroup\$ Nov 29, 2017 at 22:36

1 Answer 1

1
\$\begingroup\$

Since perspective division is not performed, it seems you could simply multiply inverse(projection * view) by vec4(±1,±1,±1,1) (each one of the 8 corners of unit cube) to get 8 corners of the cuboid.

You seem to want AABB (axis-aligned bounding box) of that cuboid. If so, you need to compute component-wise min and max of those transformed 8 points. Those will be the opposite corners of the AABB.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you for your answer, I am not ignoring it, I am simply taking awhile to respond because I am trying to figure out how I can use it to extract the information I need (or if it can even be used for that purpose). I made an update Update #1 that hopefully clarifies my end goal a little better. \$\endgroup\$
    – latreides
    Nov 29, 2017 at 3:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .