From c4951d1e73fface33580f70474dd315404c8a404 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 26 May 2015 18:10:31 +0200 Subject: [PATCH] Map rotation fix --- apps/openmw/mwrender/localmap.cpp | 16 ++++++++++------ apps/openmw/mwrender/localmap.hpp | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 8ab16283e..0da14f702 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -73,10 +73,10 @@ LocalMap::~LocalMap() mRoot->removeChild(*it); } -const osg::Vec2f LocalMap::rotatePoint(const osg::Vec2f& p, const osg::Vec2f& c, const float angle) +const osg::Vec2f LocalMap::rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle) { - return osg::Vec2f( std::cos(angle) * (p.x() - c.x()) - std::sin(angle) * (p.y() - c.y()) + c.x(), - std::sin(angle) * (p.x() - c.x()) + std::cos(angle) * (p.y() - c.y()) + c.y()); + return osg::Vec2f( std::cos(angle) * (point.x() - center.x()) - std::sin(angle) * (point.y() - center.y()) + center.x(), + std::sin(angle) * (point.x() - center.x()) + std::cos(angle) * (point.y() - center.y()) + center.y()); } void LocalMap::clear() @@ -330,12 +330,16 @@ void LocalMap::requestInteriorMap(MWWorld::CellStore* cell) mAngle = std::atan2(north.x(), north.y()); // Rotate the cell and merge the rotated corners to the bounding box - osg::Vec2f _center(bounds.center().x(), bounds.center().y()); + osg::Vec2f origCenter(bounds.center().x(), bounds.center().y()); + osg::Vec3f origCorners[8]; + for (int i=0; i<8; ++i) + origCorners[i] = mBounds.corner(i); + for (int i=0; i<8; ++i) { - osg::Vec3f corner = mBounds.corner(i); + osg::Vec3f corner = origCorners[i]; osg::Vec2f corner2d (corner.x(), corner.y()); - corner2d = rotatePoint(corner2d, _center, mAngle); + corner2d = rotatePoint(corner2d, origCenter, mAngle); mBounds.expandBy(osg::Vec3f(corner2d.x(), corner2d.y(), 0)); } diff --git a/apps/openmw/mwrender/localmap.hpp b/apps/openmw/mwrender/localmap.hpp index 8160c325c..ba92cde24 100644 --- a/apps/openmw/mwrender/localmap.hpp +++ b/apps/openmw/mwrender/localmap.hpp @@ -117,7 +117,7 @@ namespace MWRender float mMapWorldSize; float mAngle; - const osg::Vec2f rotatePoint(const osg::Vec2f& p, const osg::Vec2f& c, const float angle); + const osg::Vec2f rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle); void requestExteriorMap(MWWorld::CellStore* cell); void requestInteriorMap(MWWorld::CellStore* cell);