| 260 | } |
| 261 | |
| 262 | bool MovableTextOverlay::computeOverlayPositionHead(Ogre::Vector2& position) |
| 263 | { |
| 264 | // the AABB of the target |
| 265 | const Ogre::AxisAlignedBox& AABB = mFollowedMov->getWorldBoundingBox(); |
| 266 | if (!mCamera->isVisible(AABB)) |
| 267 | return false; |
| 268 | |
| 269 | const Ogre::Vector3 farLeftTop = AABB.getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_TOP); |
| 270 | const Ogre::Vector3 nearRightTop = AABB.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_BOTTOM); |
| 271 | |
| 272 | const Ogre::Vector3 centerTop = (farLeftTop + nearRightTop) * 0.5; |
| 273 | |
| 274 | // Is the camera facing that point? |
| 275 | Ogre::Plane cameraPlane(Ogre::Vector3(mCamera->getDerivedOrientation().zAxis()), mCamera->getDerivedPosition()); |
| 276 | if(cameraPlane.getSide(centerTop) != Ogre::Plane::NEGATIVE_SIDE) |
| 277 | return false; |
| 278 | |
| 279 | // Transform 3D point to screen |
| 280 | Ogre::Vector3 screenPosition = mCamera->getProjectionMatrix() * (mCamera->getViewMatrix() * centerTop); |
| 281 | |
| 282 | // We transform from coordinate space [-1, 1] to [0, 1] |
| 283 | position.x = 0.5 + (screenPosition.x * 0.5); |
| 284 | position.y = 0.5 - (screenPosition.y * 0.5); |
| 285 | |
| 286 | return true; |
| 287 | } |
| 288 | |
| 289 | void MovableTextOverlay::displayOverlay(uint32_t childOverlayId, Ogre::Real time) |
| 290 | { |