carmenism
carmenism

Reputation: 1098

Create a 3D square frustum by applying a transformation to a cube?

I would like to know if it is possible to build a 3D square frustum by applying some kind of tranformation to glutSolidCube(GLDouble size). I am guessing some kind of shear matrix is involved, which - from what I can tell - is not a built-in transformation.

Note, I don't care at all about the viewing frustum (which, as you might imagine, is making any Google searches skewed). I'd simply like to have a 3D square frustum as part of my scene. Any ideas on how to produce one from a cube would be appreciated!

A Square Frustum

Upvotes: 2

Views: 2502

Answers (2)

linello
linello

Reputation: 8704

Yes it is possible to transform your cube into a frustum given a very projection matrix. First define a focal distance d that is the point where the edge of the frustum are converging. Then multiply all the corners of your volume by this matrix:

P = [ 1   0   0   0
      0   1   0   0
      0   1  1/d  0
      0   0   1   0 ]

Upvotes: 0

Viktor Latypov
Viktor Latypov

Reputation: 14467

It is not shear matrix, it is a projection matrix for perspective projection. You multiply the coordinates of unit cube's vertices by inverse projection matrix to get the coordinates of frustum vertices. To get the frustum's coords in world space you also need to multiple the vertices by the inverse Camera matrix (view matrix).

Look here for detailed formulae: http://www.songho.ca/opengl/gl_projectionmatrix.html

To deform the cube it is better to create the VBO with desired vertices or just render a number of deformed quads, if you want some quick'n'dirty implementation using the fixed-function pipeline.

P.S.

There's a code extract to calculate the corners of the frustum: http://www.gamedev.net/topic/606716-frustum-corners-from-view-projection/

Upvotes: 2

Related Questions