1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-30 17:41:34 +00:00

tooltips labels

Signed-off-by: Bret Curtis <psi29a@gmail.com>
This commit is contained in:
bzzt lost a hitlab login 2020-05-11 13:37:00 +00:00 committed by Bret Curtis
parent 9f0398c021
commit 89ec6cfea2
5 changed files with 26 additions and 12 deletions

View file

@ -397,6 +397,15 @@ namespace MWPhysics
return osg::Vec3f();
}
osg::BoundingBox PhysicsSystem::getBoundingBox(const MWWorld::ConstPtr &object) const
{
const Object * physobject = getObject(object);
if (!physobject) return osg::BoundingBox();
btVector3 min, max;
physobject->getCollisionObject()->getCollisionShape()->getAabb(physobject->getCollisionObject()->getWorldTransform(), min, max);
return osg::BoundingBox(Misc::Convert::toOsg(min), Misc::Convert::toOsg(max));
}
osg::Vec3f PhysicsSystem::getCollisionObjectPosition(const MWWorld::ConstPtr &actor) const
{
const Actor* physactor = getActor(actor);

View file

@ -7,6 +7,7 @@
#include <algorithm>
#include <osg/Quat>
#include <osg/BoundingBox>
#include <osg/ref_ptr>
#include "../mwworld/ptr.hpp"
@ -144,6 +145,9 @@ namespace MWPhysics
/// @note The collision shape's origin is in its center, so the position returned can be described as center of the actor collision box in world space.
osg::Vec3f getCollisionObjectPosition(const MWWorld::ConstPtr& actor) const;
/// Get bounding box in world space of the given object.
osg::BoundingBox getBoundingBox(const MWWorld::ConstPtr &object) const;
/// Queues velocity movement for a Ptr. If a Ptr is already queued, its velocity will
/// be overwritten. Valid until the next call to applyQueuedMovement.
void queueObjectMovement(const MWWorld::Ptr &ptr, const osg::Vec3f &velocity);

View file

@ -977,20 +977,14 @@ namespace MWRender
renderCameraToImage(rttCamera.get(),image,w,h);
}
osg::Vec4f RenderingManager::getScreenBounds(const MWWorld::Ptr& ptr)
osg::Vec4f RenderingManager::getScreenBounds(const osg::BoundingBox &worldbb)
{
if (!ptr.getRefData().getBaseNode())
return osg::Vec4f();
osg::ComputeBoundsVisitor computeBoundsVisitor;
computeBoundsVisitor.setTraversalMask(~(Mask_ParticleSystem|Mask_Effect));
ptr.getRefData().getBaseNode()->accept(computeBoundsVisitor);
if (!worldbb.valid()) return osg::Vec4f();
osg::Matrix viewProj = mViewer->getCamera()->getViewMatrix() * mViewer->getCamera()->getProjectionMatrix();
float min_x = 1.0f, max_x = 0.0f, min_y = 1.0f, max_y = 0.0f;
for (int i=0; i<8; ++i)
{
osg::Vec3f corner = computeBoundsVisitor.getBoundingBox().corner(i);
osg::Vec3f corner = worldbb.corner(i);
corner = corner * viewProj;
float x = (corner.x() + 1.f) * 0.5f;

View file

@ -168,7 +168,7 @@ namespace MWRender
RayResult castCameraToViewportRay(const float nX, const float nY, float maxDistance, bool ignorePlayer, bool ignoreActors=false);
/// Get the bounding box of the given object in screen coordinates as (minX, minY, maxX, maxY), with (0,0) being the top left corner.
osg::Vec4f getScreenBounds(const MWWorld::Ptr& ptr);
osg::Vec4f getScreenBounds(const osg::BoundingBox &worldbb);
void setSkyEnabled(bool enabled);

View file

@ -1934,8 +1934,15 @@ namespace MWWorld
// retrieve object dimensions so we know where to place the floating label
if (!object.isEmpty ())
{
osg::Vec4f screenBounds = mRendering->getScreenBounds(object);
osg::BoundingBox bb = mPhysics->getBoundingBox(object);
if (!bb.valid() && object.getRefData().getBaseNode())
{
osg::ComputeBoundsVisitor computeBoundsVisitor;
computeBoundsVisitor.setTraversalMask(~(MWRender::Mask_ParticleSystem|MWRender::Mask_Effect));
object.getRefData().getBaseNode()->accept(computeBoundsVisitor);
bb = computeBoundsVisitor.getBoundingBox();
}
osg::Vec4f screenBounds = mRendering->getScreenBounds(bb);
MWBase::Environment::get().getWindowManager()->setFocusObjectScreenCoords(
screenBounds.x(), screenBounds.y(), screenBounds.z(), screenBounds.w());
}