I'm trying to get a 2D screen position so I unproject a point from 3D into 2D screen coordinates by that following function: I'm trying to get a 2D screen position so I unproject a point from 3D into 2D screen coordinates by that following function:

Ogre::Vector2 SpaceTransformHelper::convertWorldToScreenPosition( const Ogre::Vector3&amp; worldPosition )
{
    Stages::AStage* currStage = Stages::StageManager::getSingleton()-&gt;getActiveStage();
    Core::Resolution screenRes = Core::EnvironmentInformation::getSingleton()-&gt;getScreenResolution();

    // Get worldviewprojection from camera.
    Ogre::Matrix4 worldViewProjection = currStage-&gt;getActiveCamera()-&gt;getCameraViewProjectionMatrix();

    // Transform world coordinates.
    Ogre::Vector3 transformedWorldPosition = worldViewProjection * worldPosition;

    // Calculate screen coordinates from world coordinates.
    Ogre::Vector2 screenPosition;
    screenPosition.x = (int) ( ( ( transformedWorldPosition.x + 1 ) / 2.0 ) * screenRes.width + 0.5 );
    screenPosition.y = (int) ( ( ( 1 - transformedWorldPosition.y ) / 2.0 ) * screenRes.height + 0.5 );

    return screenPosition;
}


Now I want to convert that screenPosition into Image space to crop an image:

Core::Resolution screenRes = Core::EnvironmentInformation::getSingleton()-&gt;getScreenResolution();
float screenPositionX = (screenPosition.x / screenRes.width) * (pixelBuffer-&gt;getWidth());
float screenPositionY =  (screenPosition.y / screenRes.height) * (pixelBuffer-&gt;getHeight());




When I click on the mobile screen on the Green LED I get that cropped image.. but what I want is to only crop that green led.. Is there a problem with the transformation ?

  const Core::Resolution cameraRes = Core::EnvironmentInformation::getSingleton()-&gt;getCameraResolutionUpLoad( plane );
    Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture[plane]-&gt;getBuffer( 0, 0 );

    viewarassert( screenPosition.x &lt; cameraRes.width || screenPosition.x &gt;= 0 || screenPosition.y &lt; cameraRes.height || screenPosition.y &gt;= 0 );

   Core::Resolution screenRes = Core::EnvironmentInformation::getSingleton()-&gt;getScreenResolution();
   std::pair&lt; Ogre::Vector2, Ogre::Vector2 &gt; uvBounds = calculateSingleViewTextureCoordinates();

    float screenPositionX = cameraRes.height - (screenPosition.x / screenRes.width) * ((int)pixelBuffer-&gt;getHeight());
    float screenPositionY=  cameraRes.width -  (screenPosition.y / screenRes.height) * ((int)pixelBuffer-&gt;getWidth());

    int  min_x = std::max( 0,(int)screenPositionX - radius);
    int  min_y = std::max( 0,(int)screenPositionY - radius);
    int  max_x = std::min( (int)cameraRes.width, (int) screenPositionX + radius );
    int  max_y = std::min( (int)cameraRes.height, (int) screenPositionY+ radius );

    // Get the pixelbox within the radius.
    pixelBuffer-&gt;lock(Ogre::HardwareBuffer::HBL_READ_ONLY);
    const Ogre::PixelBox &amp;readrefpb = pixelBuffer-&gt;getCurrentLock();

    unsigned char *readrefdata = static_cast&lt;unsigned char*&gt;(readrefpb.data);

    Ogre::Image img;
    img = img.loadDynamicImage (readrefdata, pixelBuffer-&gt;getWidth(),
                                pixelBuffer-&gt;getHeight(), pixelBuffer-&gt;getFormat());
    img = img.flipAroundY();

    Ogre::Image *out = cropImage(img,  min_x, min_y,  max_x,  max_y);
Not sure if Ogre does it implicitely, but using a 4x4 matrix to transform a 3D point to get the correct 2D coordinates (as it would be rendered with the same matrix),  requires a transition from homogeneous coordinates by dividing the result by w. 

In other words, you must multiply the matrix by a 4-component vector (x,y,z,1.0f) instead of a 3-component vector. And then the resulting vector will look like (X,Y,Z,W) and you need to divide by W to get the position like it would be rendered. 

Like this: 

// Transform world coordinates.
Ogre::Vector4 transformedWorldPosition = worldViewProjection * Ogre::Vector4(worldPosition,1.0);

//Divide by w 
transformedWorldPosition = transformedWorldPosition / transformedWorldPosition.w; 

// Calculate screen coordinates from world coordinates.
Ogre::Vector2 screenPosition;
screenPosition.x = (int) ( ( ( transformedWorldPosition.x + 1 ) / 2.0 ) * screenRes.width + 0.5 );
screenPosition.y = (int) ( ( ( 1 - transformedWorldPosition.y ) / 2.0 ) * screenRes.height + 0.5 );