Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: How exactly is projection matrix derived?

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Sep 2001
    Posts
    40

    How exactly is projection matrix derived?

    Hi all,

    Whilst there is brief mention of the elements that make up the projection matrix in both the red and blue books, there never was any attempt at explaining *how* these were derived. (it appears to be an amalgamate of shearing, scaling & translation transformations...but this insight by itself isn't particularly helpful)
    Can somebody kindly point me to relevant resources, references, websites etc?


    A thousand thanks!

  2. #2
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: How exactly is projection matrix derived?

    Code :
    inline mat4<T>&amp; mat4<T>::CreateFrustum(	T left, T right,
    					T bottom, T top,
    					T nearval, T farval)
    {
    	T x, y, a, b, c, d;
     
    	x = (2*nearval) / (right-left);
    	y = (2*nearval) / (top-bottom);
    	a = (right+left) / (right-left);
    	b = (top+bottom) / (top-bottom);
    	c = -(farval+nearval) / ( farval-nearval);
    	d = -(2*farval*nearval) / (farval-nearval);
     
    	_11 = x;	_21 = 0;	_31 = a;	_41 = 0;
    	_12 = 0;	_22 = y;	_32 = b;	_42 = 0;
    	_13 = 0;	_23 = 0;	_33 = c;	_43 = d;
    	_14 = 0;	_24 = 0;	_34 = -1;	_44 = 0;
     
    	return *this;
    }
     
    inline mat4<T>&amp; mat4<T>::CreatePerspectiveFrustum(T fovy, T aspect, T zNear, T zFar)
    {
    	T xmin, xmax, ymin, ymax;
     
    	ymax = zNear * (T)tan((double)(fovy * M_PI / 360));
    	ymin = -ymax;
    	xmin = ymin * aspect;
    	xmax = ymax * aspect;
     
    	return CreateFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
    }
    This any help?
    Knackered

  3. #3
    Intern Newbie
    Join Date
    Sep 2001
    Posts
    40

    Re: How exactly is projection matrix derived?

    Uh, afraid not...I already know from the red and blue books exactly what the elements of the projection matrix are.
    What I don't know is *how* they came to be...ie. why are there scaling, shearing, translation transformations incorporated into it? what are the motivations behind these transformation operations? how are they derived? what formulas/principles/concepts used?


    Very puzzled.

  4. #4
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: How exactly is projection matrix derived?

    I remember in the days before I knew anything about matrices, linear algebra etc., I had to figure out how 3D worked in a kind of common sense way. These 3 lines is what I came up with to project a world transformed vertex to the screen:-
    Code :
    scale = halfscreenheight/vertex_z;
    screenx = (vertex_x*scale) + halfscreenwidth;
    screeny = (vertex_y*scale) + halfscreenheight;
    This any help?
    Knackered

  5. #5
    Intern Newbie
    Join Date
    Sep 2001
    Posts
    40

    Re: How exactly is projection matrix derived?

    Those equations describe basic perspective division using the similar triangles principle. (I'm familiar with that too ;-)
    However, it seems the projection matrix that OpenGL implements is a lot more complex. Problem is, I don't know *exactly* what it does. And while I know the "-1" in the 4th row/3rd column is in effect responsible for implementing the perspective transformation, I just don't know what the rest of the elements do...
    Isn't there some official documentation on this? SGI's website for instance? (given that they were responsible for OGL's genesis in the early days)

  6. #6
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: How exactly is projection matrix derived?

    I've just done a quick search on google, and come up with this link - I haven't had time to read it, so it probably doesn't answer your question, but give it a go:-
    http://www.cs.kuleuven.ac.be/cwis/re...-3d/node8.html
    Knackered

  7. #7
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: How exactly is projection matrix derived?

    BTW, here's the google query...have a browse!
    http://www.google.com/search?hl=en&l...tion+matrix%22
    Knackered

  8. #8
    Intern Newbie
    Join Date
    Sep 2001
    Posts
    40

    Re: How exactly is projection matrix derived?

    Gee, that link you gave answered my question exactly!
    (the Google search I tried didn't turn up anything near as useful as this...)

    Thanks a lot man!

  9. #9
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: How exactly is projection matrix derived?

    No problem.
    I tend to put things in quotes when using google, to get the 'exact phrase'.

    Such as:-
    "projection matrix"
    Knackered

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •