Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Perspective projection matrix


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 HenriH   Members   -  Reputation: 122

Like
0Likes
Like

Posted 03 January 2008 - 03:29 AM

I have a perspective projection matrix which is calculated thus: (Taken from OpenGL Reference Manual, 3rd edition)
  f = cotangent(fovy/2)
  dp = near - far

  f/aspect   0        0                0
     0       f        0                0
     0       0  (far+near)/dp   (2*far*near)/dp
     0       0       -1                0
Can you instruct me how to calculate inverse of this matrix? I need this in order to transform coordinates back and forth between object space and window space. It is more convenient to use matrix of my own rather than gluProject/glUnProject. Thanks

Sponsor:

#2 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 03 January 2008 - 03:36 AM

Quote:
Original post by HenriH
I have a perspective projection matrix which is calculated thus:
(Taken from OpenGL Reference Manual, 3rd edition)


f = cotangent(fovy/2)
dp = near - far

f/aspect 0 0 0
0 f 0 0
0 0 (far+near)/dp (2*far*near)/dp
0 0 -1 0


Can you instruct me how to calculate inverse of this matrix? I need this in order to transform coordinates back and forth between object space and window space. It is more convenient to use matrix of my own rather than gluProject/glUnProject.

Thanks
You can special-case matrix inversion for matrices of this sort, but I wouldn't bother if I were you - just use a generic inversion function (if you don't have such a function available and aren't sure how to implement it, post back).

#3 Zipster   Crossbones+   -  Reputation: 763

Like
0Likes
Like

Posted 03 January 2008 - 08:20 AM

This type of perspective matrix is actually quite easy to invert analytically given its relative sparsity. Since the upper-right and lower-left 2x2 sub-matrices are all 0's, you can invert the upper-left and lower-right sub-matrices independently. The upper-left sub-matrix only has elements along the diagonal so it's trivial to invert, while the lower-right sub-matrix requires some more mental math. But since you can treat it as a 2x2, inversion is still easy (lots of cancellations as well). From some quick back-of-the-envelope math I get:
aspect/f      0           0                    0
0 1/f 0 0
0 0 0 -1
0 0 dp/(2*far*near) (far+near)/(2*far*near)


#4 TheAdmiral   Members   -  Reputation: 1118

Like
0Likes
Like

Posted 03 January 2008 - 08:28 AM

That's a block-matrix. Behold the power of recursive inversion:

aspect/f            0                 0                 0

0 1/f 0 0

0 0 0 -1

0 0 dp/(2*far*near) (far+near)/(2*far*near)


Edit: Damn you, Zipster. I'll take consolation in the fact that this provides some level of verification [rolleyes].

#5 HenriH   Members   -  Reputation: 122

Like
0Likes
Like

Posted 03 January 2008 - 08:59 AM

Wow, amazing! Thanks, I will check if this works.

#6 HenriH   Members   -  Reputation: 122

Like
0Likes
Like

Posted 03 January 2008 - 09:20 AM

Yea it does! You saved a lot of hazzle-dazzle from me. Thanks to you all!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS