Hi Harold,

OSG uses standard C arrays to store matrices. Which means these are row major 
matrices. This changes order of operands. You should multiply point by matrix 
not matrix by point. In your code you should rather preMultiply the matrices. 

example: 

osg::Matrix viewMatrix = camera->getViewMatrix();

osg::Vec3d viewSpacePoint = worldSpacePoint * viewMatrix;

Cheers,
Wojtek Lewandowski

  ----- Original Message ----- 
  From: Harold Comere 
  To: [email protected] 
  Sent: Friday, September 04, 2009 1:30 PM
  Subject: [osg-users] world space to screen space & matrices understanding


  Hi all,

  I'm trying to simply project any 3D point ,which is already in world space, 
into screen space.

  I know how to do it without osg :
  screen space coords = bias matrix * camera projection matrix * camera view 
matrix * world space coordinates
  Those coordinates are in [0, 1] range, so multiply by viewport dimensions to 
get window coordinates.

  but i do not succeed doing it with osg because i m still not familiar with 
it...
  My current code is 

     osg::Camera * cam = _view->getCamera();
     osg::Matrix viewMatrix = cam->getViewMatrix();
     osg::Matrix projectionMatrix = cam->getProjectionMatrix();
     osg::Matrix windowMatrix = cam->getViewport()->computeWindowMatrix();

     osg::Vec4d screenCoords = windowMatrix.postMult (projectionMatrix.postMult 
(viewMatrix.postMult (_refPoint)));

  I saw windowMatrix is the bias matrix and the viewport scale.
  refPoint is a Vec4d with w = 1. ( the 3D point i want to project into screen 
space )  and as operator * is not defined to multiply a Matrix with an Vec4d, i 
use postMult function.

  But i dont get a valid result... what did i missed ? :-x
  Thanks for your attention

  Regards,
  Harold 



------------------------------------------------------------------------------


  _______________________________________________
  osg-users mailing list
  [email protected]
  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to