can anyone tell me how i could get the position of a scenenode in 2D coordinates?
i need to determine the viewport UV position, window pixel position and screen pixel position of a mesh.
any guidance is greatly appreciated.
convert 3D position to 2D position
-
- Gnoblar
- Posts: 5
- Joined: Wed Sep 17, 2003 10:23 pm
- Location: Toronto, Ontario
-
- Gnoblar
- Posts: 5
- Joined: Wed Sep 17, 2003 10:23 pm
- Location: Toronto, Ontario
just an update...i'm close to solving my problem...here's my function:
this function seems to yield the results i'm looking for, however it does not appear to take into account the camera's FOV. can anyone point me in the right direction to properly take that into account?
Code: Select all
Vector2 WorldSpaceToUV(float x, float y, float z)
{
Matrix4 V = g_pCamera->getViewMatrix();
Vector4 res = V * Vector4( x, y, z, 1 );
return Vector2( out.x + 0.5, (-out.y) + 0.5 );
}
-
- OGRE Retired Moderator
- Posts: 4011
- Joined: Fri Sep 19, 2003 6:28 pm
- Location: Burgos, Spain
- x 2
-
- Gnoblar
- Posts: 5
- Joined: Wed Sep 17, 2003 10:23 pm
- Location: Toronto, Ontario
yes, this is my finished version of the function:
this function returns the screen UVs of the 3D position in space.
Code: Select all
Vector2 WorldSpaceToUV(float x, float y, float z)
{
Vector3 pos = cam->getProjectionMatrix() * (cam->getViewMatrix() * Vector3(x,y,z));
return Vector2((-pos.x+1)/2,(pos.y+1)/2);
}
-
- Halfling
- Posts: 55
- Joined: Thu Mar 04, 2004 7:08 pm
- Location: Belgium
-
- OGRE Retired Moderator
- Posts: 4011
- Joined: Fri Sep 19, 2003 6:28 pm
- Location: Burgos, Spain
- x 2