abolfoooud 109 Report post Posted May 9, 2007 Dear experts, I am working on a project where i need to do back-projection of points on screen to their 3D wolrd positions and i need your help in this regards. I have 4 fixed points that represent a square in 3D world parallel to the X-Z plane. After applying transformation effects (rotation and translation) these points get projected to arbitrary points on screen (2D). I need to project back these points from screen coordinates to their actual 3D points keeping in mind preserving the square shape they represent. For example: 3D World 2D Screen the square *-------* *---* | | could be projected to / \ | | (perpective) / | | *---------* *-------* or roughly to * (perspective and / rotation) / \ * * \ / \ / * can any one help please? cheers AF 0 Share this post Link to post Share on other sites
abolfoooud 109 Report post Posted May 9, 2007 Ops, the formating was not preserved? How can i reserve ot and keep the spacing? 0 Share this post Link to post Share on other sites
Ezbez 1164 Report post Posted May 9, 2007 use [ code ] and [ /code ] tags around your ASCII art to preserve formatting (though it might not be exactly what it is when you edit it. Eg: it uses a different font. 0 Share this post Link to post Share on other sites
abolfoooud 109 Report post Posted May 10, 2007 Hi again,this is the example i wanted to give in my post witht he proper formating (thanx Ezbez)For example:the square in 3D: o-------o | | | | | | o-------ocould be projected to in 2D(perpectivei applied): o------o / / / / / / o-----------oor roughly to (perspective and rotation) o / \ / \ o o \ / \ / o [Edited by - abolfoooud on May 10, 2007 6:38:08 AM] 0 Share this post Link to post Share on other sites
Todo 451 Report post Posted May 10, 2007 If what you need are the coordinates of the untransformed vertexes, then what you need to do is transform the screen-space coordinates using the inverse of the original transformation, which is:V_{s} = M . V_{w}where V_{s} is in screen space and V_{w} is in world space and M is a matrix representing the transformation from world to screen space (most likely a concatenation of a projection matrix and a view matrix).Given V_{s} = ( x_{s}, y_{s}, z_{s} ) (the 2D coordinates of each vertex on the screen and a screen space depth), compute the inverse of M, M^{-1} to get V_{w}:V_{w} = M^{-1} . V_{s}If you do not have a screen space depth, you can substitute for 0 and 1. What you then get is a line of sight starting from the camera (given M has a view matrix) to infinity, passing through V_{w} at some time t. 0 Share this post Link to post Share on other sites
abolfoooud 109 Report post Posted May 11, 2007 Thanks Todo for your replynow 2 ueastions:1) what do you mean by screen depth and how do i get it?2) how do i get the inverse of the transformation matrix?regardsAF 0 Share this post Link to post Share on other sites
Drigovas 509 Report post Posted May 11, 2007 It's good practice to know the general way to solve these problems, even though you could take short cuts in this particular case. Given all the information you know about the starting data, you can use different means to find your answer. The general solution to this problem though is to find the inverse matrix, which is done [for square matrices] by dividing every term in the matrix by the non-zero determinant. If the determinant is zero, then there is no inverse. You won't run into a zero-determinant in these cases, unless you're doing something amazingly wierd with your original transform matrix.By the way, thats a great site for just these kinds of problems. It's definately bookmark-worthy. 0 Share this post Link to post Share on other sites
abolfoooud 109 Report post Posted May 11, 2007 the site gives example of how apply the inverse of 3x3 matrix. but in the case of OGL we need 4x4. calculating this for 4x4 will be i am sure tooo ime costy and will affect performance. i read somewhere that there are shortcuts or work-arounds to get the inverse. also the site has theoratical explanation. is there a technical one showing opengl code to use? i know i am too lazy :Dcheers 0 Share this post Link to post Share on other sites