Welcome to the new Ogre Wiki!
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
This is a port of this Ogre page. It was created for Mogre 1.7.
One way to have HUD Elements like targeting indicators or playernames positioned on 3D objects is projecting the 3D position to 2D and positioning the HUD Elements there. The following code can be used to do that.
Table of contents
Projecting position
// using MOGRE; // returns a vector with x,y with clamped screencoords in [-1;1] public Vector2 ProjectPos (Camera cam, Vector3 pos) { Vector2 ret = new Vector2(); Vector3 eyeSpacePos = cam.GetViewMatrix(true) * pos; if (eyeSpacePos.z < 0) { Vector3 screenSpacePos = cam.ProjectionMatrix * eyeSpacePos; ret.x = screenSpacePos.x; ret.y = screenSpacePos.y; } else { ret.x = (-eyeSpacePos.x > 0) ? -1 : 1; ret.y = (-eyeSpacePos.y > 0) ? -1 : 1; } return ret; }
Notes
- to check if the object is visible, check if the projected x,y are in -1;1 if not, it's behind the camera
Alias: MOGRE_Projecting_3D_position_to_2D
Contributors to this page: jacmoe
,
OgreWikiBot
and
Beauty
.
Page last modified on Monday 01 of August, 2011 00:24:04 GMT by jacmoe
.
The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.

