Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Inverting an Orthographic Projection Matrix

This topic is 5435 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


Yes, "scaling down" orthographic projections have determinants close to zero. You didn''t state the problem you were having though.

An orthographic projection that drops a dimension can''t be inverted.

Share this post

Link to post
Share on other sites
I am trying to create an orthographic scene view (editor) and ''unproject'' my mouse pos from screen space to object space.

It isnt the end of the world if it isnt possible, there are other less elegant ways i can go about it.

Share this post

Link to post
Share on other sites
Of course you can inverse it (Don't drop the z component, GL will do it for you when needed) ! It's basic AFFINE (LINEAR) PROJECTIVE maths.

The inverse is simple :

For the 3x3 submatrix, if there is no scaling it's the transposed matrix. If there is uniform scaling. Well ... s/(s*s) = 1/s, so just transpose and multiply by 1/(s*s). If there is non uniform scaling .. well google search "matrix inversion", won't loose my time for that. For the translation :

P' = M*P+T
P = M-1*(P'-T)

So T'=-M-1*T
such that
P = M-1*P' + T'

The main issue concerning floating point precision is not small numers byt themselves, it is substracting numbers that result in much smaller numbers which may give you an erratic Det. If you use uniform scaling then you don't have to waste processor time computing the Det (s3), you don't need it.

[edited by - Charles B on November 29, 2003 8:01:48 AM]

Share this post

Link to post
Share on other sites
I might have gotten something wrong but:
When I have a camera facing any directions in the world there is quite a few 3D-points that will end up on the same 2D screen coordinate.
Assuming screen is isomorph to R² and not with a limited number of pixels it´s exactly a line in 3D that ends up as being projected on a single screenpos. This is clearly not an injective function hence it´s not invertible (<=> Det = 0).

So your mousepos will be a representation for a complete line in 3D not for a single 3D-pos (you can still cast a ray in the direction of the line and see what you hit).

Charles B:
Either you just revolutionized math by inverting non-invertible functions or one of us is on the wrong track. Anyways for me your post was like randomly reading phrases in an LA-book and with no connection to the question.

Share this post

Link to post
Share on other sites
In the context of GL or D3D a matrix is 4*4 not 4*2. I hope you realized it lately.

Yeah I realized this point may have been unclear (for a noob like you) and I was ready to reedit my post. But it was obvious to me that LowCal has some way to retrieve the z component from the z-buffer or with ray casting on the scene.

Anyway I suggested it mentionning :
Don't drop the z component, GL will do it for you when needed
... at the rasterization level. Have you ever coded software engines ? Well I did, and well before Quake1, thanks for your advises.

This means you need the z component in entry (thus the z-column) of the inverse transfo (mouse x,y,z). And thus you need the z row of the orthographic matrix. Of course inversible requires same dimensions both sides. Pls don't insult my math level it's much higher than what you imagine So if you were really bright, and have a portion of my 150 IQ you would have caught it between the lines.

No connection to the question ? GRRR who do you think you are ? I started coding games 24 years ago and followed some very high level studies in maths. My answer is exactly what is required in common isometric games. Uniform scaling is a very useful situation because you can simply u-scale/rotate/translate and THEN apply a x,y,z scaling of the screen coordinates (this means concatenating matrices) but this can be done in a more efficient way. Did you imagine this before rushing to insults ?

Now I advise you to read my other technical posts before emitting such hasted judgements.

[edited by - Charles B on November 29, 2003 1:21:06 PM]

Share this post

Link to post
Share on other sites
Yep ROFL. Another detail you certainly did not catch :

"determinate of very close to zero, if not zero".

If LCSD had dropped the z component in his matrix it would not have said close to zero but exactly zero. Because as you should know :

Det = ?*?*0 - ?*?*0 + ...

Makes exactly zero whenever you use floating point ( IEEE Standard 754) or fixed point. 0*x is always 0 exactly in any implementation.

So its seems only one did not get the context taking others as idiots, and it's you Atheist. Next time you'll do better ... don't worry.

[edited by - Charles B on November 29, 2003 2:04:52 PM]

Share this post

Link to post
Share on other sites
Exactly. In linear algebra the inverse of a rotation is the transposed matrix. Then you certainly to remap the 2D x,y (and maybe z if you get it from the zbuffer) coordinates to pixel coordinates. I mean know the inverse factors.

Mouse(x,y,z) -> Camera (x,y,z)
-- Multiply by transposed + inv translation ->
3DPoint in world coords(x,y,z).

That''s pretty simple. I am sure you can find sample codes on the web even here in the forums or pages dedicated to 3D or isometric games. I am too lazy to write it here.

Google "Inverse othogonal matrix"

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!