Good day,
I need to retrive the conversion matrix that allow me to transform points from 3D world space to local 2D window space ([-1;1]).
I have seen the way to convert the points:
http://www.ogre3d.org/tikiwiki/tiki-ind ... e=Cookbook
but i also need the conversion matrix.
Anyone could help me?
Thank you all.
Best Regards.
Riccardo.
[SOLVED] Get transf matrix from 3D World space to 2D window
- RiccardoTurati
- Halfling
- Posts: 67
- Joined: Thu Apr 19, 2012 4:59 pm
- Location: Milano, Italy
[SOLVED] Get transf matrix from 3D World space to 2D window
Last edited by RiccardoTurati on Thu Oct 18, 2012 3:19 pm, edited 1 time in total.
- cose
- Halfling
- Posts: 46
- Joined: Thu Jul 24, 2008 5:48 pm
- Location: Marseille
- Contact:
Re: Get transform matrix from 3D World space to 2D window sp
you can check the conversion matrix here :
http://stackoverflow.com/questions/7242 ... projection
http://stackoverflow.com/questions/7242 ... projection
- RiccardoTurati
- Halfling
- Posts: 67
- Joined: Thu Apr 19, 2012 4:59 pm
- Location: Milano, Italy
Re: Get transform matrix from 3D World space to 2D window sp
Hi all,
thank you cose for your hint, I have read the topic, but sadly is not strictly what i need.
To achieve my goal, even if the result will be the same, i need that the Screen Projection should be inside the matrix, and not calculated outside.
Anyone could help me?
Thank you.
Best Regards.
Riccardo.
thank you cose for your hint, I have read the topic, but sadly is not strictly what i need.
To achieve my goal, even if the result will be the same, i need that the Screen Projection should be inside the matrix, and not calculated outside.
Anyone could help me?
Thank you.
Best Regards.
Riccardo.
- RiccardoTurati
- Halfling
- Posts: 67
- Joined: Thu Apr 19, 2012 4:59 pm
- Location: Milano, Italy
Re: Get transform matrix from 3D World space to 2D window sp
Hi all,
I have found this documentation, that it seems quite usefull, but i'm still making an error that i couldn,t find.
http://robertokoci.com/world-view-proje ... -unveiled/
Basically I have read that we need this matrix:
Anyone could help me find where the error is?
Thank you.
Best Regards.
Riccardo.
I have found this documentation, that it seems quite usefull, but i'm still making an error that i couldn,t find.
http://robertokoci.com/world-view-proje ... -unveiled/
Basically I have read that we need this matrix:
I try to achieve this with this code:matrix4x4 World_View_Projection_Matrix = World x View x Projection
Code: Select all
Ogre::Matrix4 l_Projection = mCamera->getProjectionMatrix();
Ogre::Matrix4 l_View = mCamera->getViewMatrix();
Ogre::Matrix4 l_Mat1_1 = mCamera->getProjectionMatrixWithRSDepth();
Ogre::Matrix4 l_Wt;
l_Wt = Ogre::Matrix4::IDENTITY;
mCamera->getWorldTransforms(&l_Wt);
Ogre::Matrix4 l_World_View_Projection_Matrix = l_Wt * l_View * l_Mat1_1;
Thank you.
Best Regards.
Riccardo.
- Wolfmanfx
- OGRE Team Member
- Posts: 1525
- Joined: Fri Feb 03, 2006 10:37 pm
- Location: Austria - Leoben
- x 99
- Contact:
Re: Get transform matrix from 3D World space to 2D window sp
Here is how you get the prj matrix
The world matrix must retrieved by your target scenenode with getFullTransform (be sure the scenenode is updated).
The view matrix is also easy to get from the camera (but only if you do not use a custom view mat)
Code: Select all
Ogre::Matrix4 projMatrix = pCam->getProjectionMatrix(); // This only works if you do not use a custom projection matrix!
Ogre::Matrix4 deviceProjMatrix;
Ogre::Root::getSingleton().getRenderSystem()->_convertProjectionMatrix(projMatrix, deviceProjMatrix, true);
The view matrix is also easy to get from the camera (but only if you do not use a custom view mat)
- RiccardoTurati
- Halfling
- Posts: 67
- Joined: Thu Apr 19, 2012 4:59 pm
- Location: Milano, Italy
Re: Get transform matrix from 3D World space to 2D window sp
I have modified the code as following:
The result is still wrong.
I have 3 points A = upper left corner, B = bottom right corner, C = upper right corner.
I expect that appling matrix to that point will transform them in A (-1;1) , B (1;-1) , C (1;1) and this is not true.
Am I doing something wrong?
Thank you.
Best Regards.
Riccardo
Code: Select all
Ogre::Matrix4 projMatrix = mCamera->getProjectionMatrix(); // This only works if you do not use a custom projection matrix!
Ogre::Matrix4 deviceProjMatrix;
Ogre::Root::getSingleton().getRenderSystem()->_convertProjectionMatrix(projMatrix, deviceProjMatrix, true);
Ogre::Matrix4 l_FullMove = mCameraNode->_getFullTransform();
Ogre::Matrix4 l_View = mCamera->getViewMatrix();
Ogre::Matrix4 l_World_View_Projection_Matrix = l_FullMove.concatenate(l_View);
l_World_View_Projection_Matrix = l_World_View_Projection_Matrix.concatenate(deviceProjMatrix);
return l_World_View_Projection_Matrix;
I have 3 points A = upper left corner, B = bottom right corner, C = upper right corner.
I expect that appling matrix to that point will transform them in A (-1;1) , B (1;-1) , C (1;1) and this is not true.
Am I doing something wrong?
Thank you.
Best Regards.
Riccardo
- Kojack
- OGRE Moderator
- Posts: 7153
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 520
Re: Get transform matrix from 3D World space to 2D window sp
getViewMatrix already takes the camera's parent node into account. You don't need l_FullMove.
The short version to get the matrix to convert from 3d space to 2d screen space is:
You might need to use getProjectionMatrixRS() instead, depending on how you are going to use the screen space points.
The short version to get the matrix to convert from 3d space to 2d screen space is:
Code: Select all
Matrix4 convert = mCamera->getProjectionMatrix() * mCamera->getViewMatrix();
- RiccardoTurati
- Halfling
- Posts: 67
- Joined: Thu Apr 19, 2012 4:59 pm
- Location: Milano, Italy
Re: Get transform matrix from 3D World space to 2D window sp
Thanks all for the help.
If someone else need this information i have used Kojack solution and it works perfectly.
Thanks again.
Best Regards.
Riccardo.
If someone else need this information i have used Kojack solution and it works perfectly.
Thanks again.
Best Regards.
Riccardo.