1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +00:00

Merge branch 'vec3_vs_xyz' into 'master'

Use Vec3f instead of x,y,z in World API

See merge request OpenMW/openmw!730
This commit is contained in:
Evil Eye 2021-07-31 10:36:11 +00:00
commit 5cdf1e7e6b
15 changed files with 74 additions and 102 deletions

View File

@ -283,10 +283,10 @@ namespace MWBase
virtual void deleteObject (const MWWorld::Ptr& ptr) = 0; virtual void deleteObject (const MWWorld::Ptr& ptr) = 0;
virtual void undeleteObject (const MWWorld::Ptr& ptr) = 0; virtual void undeleteObject (const MWWorld::Ptr& ptr) = 0;
virtual MWWorld::Ptr moveObject (const MWWorld::Ptr& ptr, float x, float y, float z, bool movePhysics=true, bool moveToActive=false) = 0; virtual MWWorld::Ptr moveObject (const MWWorld::Ptr& ptr, const osg::Vec3f& position, bool movePhysics=true, bool moveToActive=false) = 0;
///< @return an updated Ptr in case the Ptr's cell changes ///< @return an updated Ptr in case the Ptr's cell changes
virtual MWWorld::Ptr moveObject(const MWWorld::Ptr &ptr, MWWorld::CellStore* newCell, float x, float y, float z, bool movePhysics=true) = 0; virtual MWWorld::Ptr moveObject(const MWWorld::Ptr &ptr, MWWorld::CellStore* newCell, const osg::Vec3f& position, bool movePhysics=true) = 0;
///< @return an updated Ptr ///< @return an updated Ptr
virtual MWWorld::Ptr moveObjectBy(const MWWorld::Ptr &ptr, osg::Vec3f vec, bool moveToActive, bool ignoreCollisions) = 0; virtual MWWorld::Ptr moveObjectBy(const MWWorld::Ptr &ptr, osg::Vec3f vec, bool moveToActive, bool ignoreCollisions) = 0;
@ -294,8 +294,7 @@ namespace MWBase
virtual void scaleObject (const MWWorld::Ptr& ptr, float scale) = 0; virtual void scaleObject (const MWWorld::Ptr& ptr, float scale) = 0;
virtual void rotateObject(const MWWorld::Ptr& ptr, float x, float y, float z, virtual void rotateObject(const MWWorld::Ptr& ptr, const osg::Vec3f& rot, RotationFlags flags = RotationFlag_inverseOrder) = 0;
RotationFlags flags = RotationFlag_inverseOrder) = 0;
virtual MWWorld::Ptr placeObject(const MWWorld::ConstPtr& ptr, MWWorld::CellStore* cell, ESM::Position pos) = 0; virtual MWWorld::Ptr placeObject(const MWWorld::ConstPtr& ptr, MWWorld::CellStore* cell, ESM::Position pos) = 0;
///< Place an object. Makes a copy of the Ptr. ///< Place an object. Makes a copy of the Ptr.

View File

@ -834,9 +834,7 @@ namespace MWClass
ptr.getRefData().setCustomData(nullptr); ptr.getRefData().setCustomData(nullptr);
// Reset to original position // Reset to original position
MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().getPosition().pos[0], MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().getPosition().asVec3());
ptr.getCellRef().getPosition().pos[1],
ptr.getCellRef().getPosition().pos[2]);
} }
} }
} }

View File

@ -1388,9 +1388,7 @@ namespace MWClass
ptr.getRefData().setCustomData(nullptr); ptr.getRefData().setCustomData(nullptr);
// Reset to original position // Reset to original position
MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().getPosition().pos[0], MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().getPosition().asVec3());
ptr.getCellRef().getPosition().pos[1],
ptr.getCellRef().getPosition().pos[2]);
} }
} }
} }

View File

@ -57,7 +57,7 @@ namespace MWInput
} }
else if (key == "playerlooking" && !value) else if (key == "playerlooking" && !value)
{ {
MWBase::Environment::get().getWorld()->rotateObject(player.getPlayer(), 0.f, 0.f, 0.f); MWBase::Environment::get().getWorld()->rotateObject(player.getPlayer(), osg::Vec3f());
} }
mSwitches[key] = value; mSwitches[key] = value;
} }

View File

@ -39,8 +39,8 @@ namespace MWLua
} }
else else
{ {
MWWorld::Ptr newObj = world->moveObject(obj, cell, mPos.x(), mPos.y(), mPos.z()); MWWorld::Ptr newObj = world->moveObject(obj, cell, mPos);
world->rotateObject(newObj, mRot.x(), mRot.y(), mRot.z()); world->rotateObject(newObj, mRot);
} }
} }

View File

@ -93,11 +93,12 @@ namespace MWMechanics
void AiTravel::fastForward(const MWWorld::Ptr& actor, AiState& state) void AiTravel::fastForward(const MWWorld::Ptr& actor, AiState& state)
{ {
if (!isWithinMaxRange(osg::Vec3f(mX, mY, mZ), actor.getRefData().getPosition().asVec3())) osg::Vec3f pos(mX, mY, mZ);
if (!isWithinMaxRange(pos, actor.getRefData().getPosition().asVec3()))
return; return;
// does not do any validation on the travel target (whether it's in air, inside collision geometry, etc), // does not do any validation on the travel target (whether it's in air, inside collision geometry, etc),
// that is the user's responsibility // that is the user's responsibility
MWBase::Environment::get().getWorld()->moveObject(actor, mX, mY, mZ); MWBase::Environment::get().getWorld()->moveObject(actor, pos);
actor.getClass().adjustPosition(actor, false); actor.getClass().adjustPosition(actor, false);
reset(); reset();
} }

View File

@ -744,8 +744,8 @@ namespace MWMechanics
state.moveIn(new AiWanderStorage()); state.moveIn(new AiWanderStorage());
MWBase::Environment::get().getWorld()->moveObject(actor, static_cast<float>(dest.mX), osg::Vec3f pos(static_cast<float>(dest.mX), static_cast<float>(dest.mY), static_cast<float>(dest.mZ));
static_cast<float>(dest.mY), static_cast<float>(dest.mZ)); MWBase::Environment::get().getWorld()->moveObject(actor, pos);
actor.getClass().adjustPosition(actor, false); actor.getClass().adjustPosition(actor, false);
} }

View File

@ -2394,12 +2394,15 @@ void CharacterController::update(float duration)
if(!isKnockedDown() && !isKnockedOut()) if(!isKnockedDown() && !isKnockedOut())
{ {
if (rot != osg::Vec3f()) if (rot != osg::Vec3f())
world->rotateObject(mPtr, rot.x(), rot.y(), rot.z(), true); world->rotateObject(mPtr, rot, true);
} }
else //avoid z-rotating for knockdown else //avoid z-rotating for knockdown
{ {
if (rot.x() != 0 && rot.y() != 0) if (rot.x() != 0 && rot.y() != 0)
world->rotateObject(mPtr, rot.x(), rot.y(), 0.0f, true); {
rot.z() = 0.0f;
world->rotateObject(mPtr, rot, true);
}
} }
if (!mMovementAnimationControlled) if (!mMovementAnimationControlled)

View File

@ -958,7 +958,7 @@ namespace MWPhysics
if (mWaterCollision && mPosition.z() < mWaterlevel && canMoveToWaterSurface(mActorRaw, mWaterlevel, world)) if (mWaterCollision && mPosition.z() < mWaterlevel && canMoveToWaterSurface(mActorRaw, mWaterlevel, world))
{ {
mPosition.z() = mWaterlevel; mPosition.z() = mWaterlevel;
MWBase::Environment::get().getWorld()->moveObject(mActorRaw->getPtr(), mPosition.x(), mPosition.y(), mPosition.z(), false); MWBase::Environment::get().getWorld()->moveObject(mActorRaw->getPtr(), mPosition, false);
} }
mOldHeight = mPosition.z(); mOldHeight = mPosition.z();
mRefpos = mActorRaw->getPtr().getRefData().getPosition(); mRefpos = mActorRaw->getPtr().getRefData().getPosition();

View File

@ -167,17 +167,17 @@ namespace MWScript
// XYZ axis use the inverse (XYZ) rotation order like vanilla SetAngle. // XYZ axis use the inverse (XYZ) rotation order like vanilla SetAngle.
// UWV axis use the standard (ZYX) rotation order like TESCS/OpenMW-CS and the rest of the game. // UWV axis use the standard (ZYX) rotation order like TESCS/OpenMW-CS and the rest of the game.
if (axis == "x") if (axis == "x")
MWBase::Environment::get().getWorld()->rotateObject(ptr,angle,ay,az,MWBase::RotationFlag_inverseOrder); MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(angle,ay,az),MWBase::RotationFlag_inverseOrder);
else if (axis == "y") else if (axis == "y")
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,angle,az,MWBase::RotationFlag_inverseOrder); MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(ax,angle,az),MWBase::RotationFlag_inverseOrder);
else if (axis == "z") else if (axis == "z")
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,angle,MWBase::RotationFlag_inverseOrder); MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(ax,ay,angle),MWBase::RotationFlag_inverseOrder);
else if (axis == "u") else if (axis == "u")
MWBase::Environment::get().getWorld()->rotateObject(ptr,angle,ay,az,MWBase::RotationFlag_none); MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(angle,ay,az),MWBase::RotationFlag_none);
else if (axis == "w") else if (axis == "w")
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,angle,az,MWBase::RotationFlag_none); MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(ax,angle,az),MWBase::RotationFlag_none);
else if (axis == "v") else if (axis == "v")
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,angle,MWBase::RotationFlag_none); MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(ax,ay,angle),MWBase::RotationFlag_none);
} }
}; };
@ -393,17 +393,17 @@ namespace MWScript
if(store) if(store)
{ {
MWWorld::Ptr base = ptr; MWWorld::Ptr base = ptr;
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr,store,x,y,z); ptr = MWBase::Environment::get().getWorld()->moveObject(ptr,store,osg::Vec3f(x,y,z));
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base,ptr); dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base,ptr);
float ax = ptr.getRefData().getPosition().rot[0]; auto rot = ptr.getRefData().getPosition().asRotationVec3();
float ay = ptr.getRefData().getPosition().rot[1];
// Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200) // Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200)
// except for when you position the player, then degrees must be used. // except for when you position the player, then degrees must be used.
// See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference. // See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference.
if(ptr != MWMechanics::getPlayer()) if(ptr != MWMechanics::getPlayer())
zRot = zRot/60.0f; zRot = zRot/60.0f;
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,osg::DegreesToRadians(zRot)); rot.z() = osg::DegreesToRadians(zRot);
MWBase::Environment::get().getWorld()->rotateObject(ptr,rot);
ptr.getClass().adjustPosition(ptr, false); ptr.getClass().adjustPosition(ptr, false);
} }
@ -444,22 +444,22 @@ namespace MWScript
if (ptr == MWMechanics::getPlayer()) if (ptr == MWMechanics::getPlayer())
{ {
MWWorld::CellStore* cell = MWBase::Environment::get().getWorld()->getExterior(cx,cy); MWWorld::CellStore* cell = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr,cell,x,y,z); ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, cell, osg::Vec3(x, y, z));
} }
else else
{ {
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, x, y, z, true, true); ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, osg::Vec3f(x, y, z), true, true);
} }
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base,ptr); dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base,ptr);
float ax = ptr.getRefData().getPosition().rot[0]; auto rot = ptr.getRefData().getPosition().asRotationVec3();
float ay = ptr.getRefData().getPosition().rot[1];
// Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200) // Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200)
// except for when you position the player, then degrees must be used. // except for when you position the player, then degrees must be used.
// See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference. // See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference.
if(ptr != MWMechanics::getPlayer()) if(ptr != MWMechanics::getPlayer())
zRot = zRot/60.0f; zRot = zRot/60.0f;
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,osg::DegreesToRadians(zRot)); rot.z() = osg::DegreesToRadians(zRot);
MWBase::Environment::get().getWorld()->rotateObject(ptr,rot);
ptr.getClass().adjustPosition(ptr, false); ptr.getClass().adjustPosition(ptr, false);
} }
}; };
@ -621,16 +621,14 @@ namespace MWScript
Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration()); Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
runtime.pop(); runtime.pop();
float ax = ptr.getRefData().getPosition().rot[0]; auto rot = ptr.getRefData().getPosition().asRotationVec3();
float ay = ptr.getRefData().getPosition().rot[1];
float az = ptr.getRefData().getPosition().rot[2];
if (axis == "x") if (axis == "x")
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax+rotation,ay,az); rot.x() += rotation;
else if (axis == "y") else if (axis == "y")
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay+rotation,az); rot.y() += rotation;
else if (axis == "z") else if (axis == "z")
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,az+rotation); rot.z() += rotation;
MWBase::Environment::get().getWorld()->rotateObject(ptr,rot);
} }
}; };
@ -682,15 +680,10 @@ namespace MWScript
if (!ptr.isInCell()) if (!ptr.isInCell())
return; return;
float xr = ptr.getCellRef().getPosition().rot[0]; MWBase::Environment::get().getWorld()->rotateObject(ptr, ptr.getCellRef().getPosition().asRotationVec3());
float yr = ptr.getCellRef().getPosition().rot[1];
float zr = ptr.getCellRef().getPosition().rot[2];
MWBase::Environment::get().getWorld()->rotateObject(ptr, xr, yr, zr);
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(ptr, dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(ptr,
MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().getPosition().pos[0], MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().getPosition().asVec3()));
ptr.getCellRef().getPosition().pos[1], ptr.getCellRef().getPosition().pos[2]));
} }
}; };

View File

@ -55,10 +55,10 @@ namespace MWWorld
int cellY; int cellY;
world->positionToIndex(mPosition.pos[0],mPosition.pos[1],cellX,cellY); world->positionToIndex(mPosition.pos[0],mPosition.pos[1],cellX,cellY);
world->moveObject(actor,world->getExterior(cellX,cellY), world->moveObject(actor,world->getExterior(cellX,cellY),
mPosition.pos[0],mPosition.pos[1],mPosition.pos[2]); mPosition.asVec3());
} }
else else
world->moveObject(actor,world->getInterior(mCellName),mPosition.pos[0],mPosition.pos[1],mPosition.pos[2]); world->moveObject(actor,world->getInterior(mCellName),mPosition.asVec3());
} }
} }

View File

@ -190,7 +190,7 @@ namespace
const ESM::Position & newpos = iter->mData.getPosition(); const ESM::Position & newpos = iter->mData.getPosition();
const MWWorld::Ptr ptr(&*iter, cellstore); const MWWorld::Ptr ptr(&*iter, cellstore);
if ((oldscale != iter->mRef.getScale() || oldpos.asVec3() != newpos.asVec3() || oldpos.rot[0] != newpos.rot[0] || oldpos.rot[1] != newpos.rot[1] || oldpos.rot[2] != newpos.rot[2]) && !ptr.getClass().isActor()) if ((oldscale != iter->mRef.getScale() || oldpos.asVec3() != newpos.asVec3() || oldpos.rot[0] != newpos.rot[0] || oldpos.rot[1] != newpos.rot[1] || oldpos.rot[2] != newpos.rot[2]) && !ptr.getClass().isActor())
MWBase::Environment::get().getWorld()->moveObject(ptr, newpos.pos[0], newpos.pos[1], newpos.pos[2]); MWBase::Environment::get().getWorld()->moveObject(ptr, newpos.asVec3());
if (!iter->mData.isEnabled()) if (!iter->mData.isEnabled())
{ {
iter->mData.enable(); iter->mData.enable();

View File

@ -842,12 +842,8 @@ namespace MWWorld
mRendering.updatePlayerPtr(player); mRendering.updatePlayerPtr(player);
if (adjustPlayerPos) { if (adjustPlayerPos) {
world->moveObject(player, pos.pos[0], pos.pos[1], pos.pos[2]); world->moveObject(player, pos.asVec3());
world->rotateObject(player, pos.asRotationVec3());
float x = pos.rot[0];
float y = pos.rot[1];
float z = pos.rot[2];
world->rotateObject(player, x, y, z);
player.getClass().adjustPosition(player, true); player.getClass().adjustPosition(player, true);
} }
@ -921,12 +917,8 @@ namespace MWWorld
if(mCurrentCell != nullptr && *mCurrentCell == *cell) if(mCurrentCell != nullptr && *mCurrentCell == *cell)
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
world->moveObject(world->getPlayerPtr(), position.pos[0], position.pos[1], position.pos[2]); world->moveObject(world->getPlayerPtr(), position.asVec3());
world->rotateObject(world->getPlayerPtr(), position.asRotationVec3());
float x = position.rot[0];
float y = position.rot[1];
float z = position.rot[2];
world->rotateObject(world->getPlayerPtr(), x, y, z);
if (adjustPlayerPos) if (adjustPlayerPos)
world->getPlayerPtr().getClass().adjustPosition(world->getPlayerPtr(), true); world->getPlayerPtr().getClass().adjustPosition(world->getPlayerPtr(), true);

View File

@ -1128,18 +1128,12 @@ namespace MWWorld
} }
} }
MWWorld::Ptr World::moveObject(const Ptr &ptr, CellStore* newCell, float x, float y, float z, bool movePhysics) MWWorld::Ptr World::moveObject(const Ptr &ptr, CellStore* newCell, const osg::Vec3f& position, bool movePhysics)
{ {
ESM::Position pos = ptr.getRefData().getPosition(); ESM::Position pos = ptr.getRefData().getPosition();
std::memcpy(pos.pos, &position, sizeof(osg::Vec3f));
pos.pos[0] = x;
pos.pos[1] = y;
pos.pos[2] = z;
ptr.getRefData().setPosition(pos); ptr.getRefData().setPosition(pos);
osg::Vec3f vec(x, y, z);
CellStore *currCell = ptr.isInCell() ? ptr.getCell() : nullptr; // currCell == nullptr should only happen for player, during initial startup CellStore *currCell = ptr.isInCell() ? ptr.getCell() : nullptr; // currCell == nullptr should only happen for player, during initial startup
bool isPlayer = ptr == mPlayer->getPlayer(); bool isPlayer = ptr == mPlayer->getPlayer();
bool haveToMove = isPlayer || (currCell && mWorldScene->isCellActive(*currCell)); bool haveToMove = isPlayer || (currCell && mWorldScene->isCellActive(*currCell));
@ -1228,7 +1222,7 @@ namespace MWWorld
} }
if (haveToMove && newPtr.getRefData().getBaseNode()) if (haveToMove && newPtr.getRefData().getBaseNode())
{ {
mWorldScene->updateObjectPosition(newPtr, vec, movePhysics); mWorldScene->updateObjectPosition(newPtr, position, movePhysics);
if (movePhysics) if (movePhysics)
{ {
if (const auto object = mPhysics->getObject(ptr)) if (const auto object = mPhysics->getObject(ptr))
@ -1237,7 +1231,7 @@ namespace MWWorld
} }
if (isPlayer) if (isPlayer)
mWorldScene->playerMoved(vec); mWorldScene->playerMoved(position);
else else
{ {
mRendering->pagingBlacklistObject(mStore.find(ptr.getCellRef().getRefId()), ptr); mRendering->pagingBlacklistObject(mStore.find(ptr.getCellRef().getRefId()), ptr);
@ -1247,10 +1241,10 @@ namespace MWWorld
return newPtr; return newPtr;
} }
MWWorld::Ptr World::moveObject (const Ptr& ptr, float x, float y, float z, bool movePhysics, bool moveToActive) MWWorld::Ptr World::moveObject(const Ptr& ptr, const osg::Vec3f& position, bool movePhysics, bool moveToActive)
{ {
int cellX, cellY; int cellX, cellY;
positionToIndex(x, y, cellX, cellY); positionToIndex(position.x(), position.y(), cellX, cellY);
CellStore* cell = ptr.getCell(); CellStore* cell = ptr.getCell();
CellStore* newCell = getExterior(cellX, cellY); CellStore* newCell = getExterior(cellX, cellY);
@ -1259,7 +1253,7 @@ namespace MWWorld
if (cell->isExterior() || (moveToActive && isCellActive && ptr.getClass().isActor())) if (cell->isExterior() || (moveToActive && isCellActive && ptr.getClass().isActor()))
cell = newCell; cell = newCell;
return moveObject(ptr, cell, x, y, z, movePhysics); return moveObject(ptr, cell, position, movePhysics);
} }
MWWorld::Ptr World::moveObjectBy(const Ptr& ptr, osg::Vec3f vec, bool moveToActive, bool ignoreCollisions) MWWorld::Ptr World::moveObjectBy(const Ptr& ptr, osg::Vec3f vec, bool moveToActive, bool ignoreCollisions)
@ -1269,8 +1263,8 @@ namespace MWWorld
if (actor) if (actor)
actor->adjustPosition(vec, ignoreCollisions); actor->adjustPosition(vec, ignoreCollisions);
if (ptr.getClass().isActor()) if (ptr.getClass().isActor())
return moveObject(ptr, newpos.x(), newpos.y(), newpos.z(), false, moveToActive && ptr != getPlayerPtr()); return moveObject(ptr, newpos, false, moveToActive && ptr != getPlayerPtr());
return moveObject(ptr, newpos.x(), newpos.y(), newpos.z()); return moveObject(ptr, newpos);
} }
void World::scaleObject (const Ptr& ptr, float scale) void World::scaleObject (const Ptr& ptr, float scale)
@ -1294,7 +1288,7 @@ namespace MWWorld
updateNavigatorObject(*object); updateNavigatorObject(*object);
} }
void World::rotateObjectImp(const Ptr& ptr, const osg::Vec3f& rot, MWBase::RotationFlags flags) void World::rotateObject(const Ptr& ptr, const osg::Vec3f& rot, MWBase::RotationFlags flags)
{ {
const float pi = static_cast<float>(osg::PI); const float pi = static_cast<float>(osg::PI);
@ -1377,7 +1371,7 @@ namespace MWWorld
pos.z() = std::min(pos.z(), traced.z()); pos.z() = std::min(pos.z(), traced.z());
} }
moveObject(ptr, ptr.getCell(), pos.x(), pos.y(), pos.z()); moveObject(ptr, ptr.getCell(), pos);
} }
void World::fixPosition() void World::fixPosition()
@ -1416,11 +1410,6 @@ namespace MWWorld
} }
} }
void World::rotateObject (const Ptr& ptr, float x, float y, float z, MWBase::RotationFlags flags)
{
rotateObjectImp(ptr, osg::Vec3f(x, y, z), flags);
}
void World::rotateWorldObject (const Ptr& ptr, osg::Quat rotate) void World::rotateWorldObject (const Ptr& ptr, osg::Quat rotate)
{ {
if(ptr.getRefData().getBaseNode() != nullptr) if(ptr.getRefData().getBaseNode() != nullptr)
@ -1536,7 +1525,7 @@ namespace MWWorld
auto* physactor = mPhysics->getActor(actor); auto* physactor = mPhysics->getActor(actor);
assert(physactor); assert(physactor);
const auto position = physactor->getSimulationPosition(); const auto position = physactor->getSimulationPosition();
moveObject(actor, position.x(), position.y(), position.z(), false, false); moveObject(actor, position, false, false);
} }
} }
@ -1546,7 +1535,7 @@ namespace MWWorld
auto* physactor = mPhysics->getActor(*player); auto* physactor = mPhysics->getActor(*player);
assert(physactor); assert(physactor);
const auto position = physactor->getSimulationPosition(); const auto position = physactor->getSimulationPosition();
moveObject(*player, position.x(), position.y(), position.z(), false, false); moveObject(*player, position, false, false);
} }
} }
@ -1604,14 +1593,16 @@ namespace MWWorld
bool World::rotateDoor(const Ptr door, MWWorld::DoorState state, float duration) bool World::rotateDoor(const Ptr door, MWWorld::DoorState state, float duration)
{ {
const ESM::Position& objPos = door.getRefData().getPosition(); const ESM::Position& objPos = door.getRefData().getPosition();
float oldRot = objPos.rot[2]; auto oldRot = objPos.asRotationVec3();
auto newRot = oldRot;
float minRot = door.getCellRef().getPosition().rot[2]; float minRot = door.getCellRef().getPosition().rot[2];
float maxRot = minRot + osg::DegreesToRadians(90.f); float maxRot = minRot + osg::DegreesToRadians(90.f);
float diff = duration * osg::DegreesToRadians(90.f) * (state == MWWorld::DoorState::Opening ? 1 : -1); float diff = duration * osg::DegreesToRadians(90.f) * (state == MWWorld::DoorState::Opening ? 1 : -1);
float targetRot = std::min(std::max(minRot, oldRot + diff), maxRot); float targetRot = std::clamp(oldRot.z() + diff, minRot, maxRot);
rotateObject(door, objPos.rot[0], objPos.rot[1], targetRot, MWBase::RotationFlag_none); newRot.z() = targetRot;
rotateObject(door, newRot, MWBase::RotationFlag_none);
bool reached = (targetRot == maxRot && state != MWWorld::DoorState::Idle) || targetRot == minRot; bool reached = (targetRot == maxRot && state != MWWorld::DoorState::Idle) || targetRot == minRot;
@ -1662,7 +1653,7 @@ namespace MWWorld
MWBase::Environment::get().getSoundManager()->stopSound3D(door, closeSound); MWBase::Environment::get().getSoundManager()->stopSound3D(door, closeSound);
} }
rotateObject(door, objPos.rot[0], objPos.rot[1], oldRot, MWBase::RotationFlag_none); rotateObject(door, oldRot, MWBase::RotationFlag_none);
} }
return reached; return reached;
@ -2279,7 +2270,7 @@ namespace MWWorld
pos.pos[0] -= adjust.x(); pos.pos[0] -= adjust.x();
pos.pos[1] -= adjust.y(); pos.pos[1] -= adjust.y();
pos.pos[2] -= adjust.z(); pos.pos[2] -= adjust.z();
moveObject(dropped, pos.pos[0], pos.pos[1], pos.pos[2]); moveObject(dropped, pos.asVec3());
} }
} }
@ -2513,7 +2504,7 @@ namespace MWWorld
player.getClass().getInventoryStore(player).setContListener(anim); player.getClass().getInventoryStore(player).setContListener(anim);
scaleObject(player, player.getCellRef().getScale()); // apply race height scaleObject(player, player.getCellRef().getScale()); // apply race height
rotateObject(player, 0.f, 0.f, 0.f, MWBase::RotationFlag_inverseOrder | MWBase::RotationFlag_adjust); rotateObject(player, osg::Vec3f(), MWBase::RotationFlag_inverseOrder | MWBase::RotationFlag_adjust);
MWBase::Environment::get().getMechanicsManager()->add(getPlayerPtr()); MWBase::Environment::get().getMechanicsManager()->add(getPlayerPtr());
MWBase::Environment::get().getWindowManager()->watchActor(getPlayerPtr()); MWBase::Environment::get().getWindowManager()->watchActor(getPlayerPtr());
@ -3859,8 +3850,8 @@ namespace MWWorld
return true; return true;
const ESM::Position& origPos = ptr.getCellRef().getPosition(); const ESM::Position& origPos = ptr.getCellRef().getPosition();
MWBase::Environment::get().getWorld()->moveObject(ptr, origPos.pos[0], origPos.pos[1], origPos.pos[2]); MWBase::Environment::get().getWorld()->moveObject(ptr, origPos.asVec3());
MWBase::Environment::get().getWorld()->rotateObject(ptr, origPos.rot[0], origPos.rot[1], origPos.rot[2]); MWBase::Environment::get().getWorld()->rotateObject(ptr, origPos.asRotationVec3());
ptr.getClass().adjustPosition(ptr, true); ptr.getClass().adjustPosition(ptr, true);
} }
return true; return true;

View File

@ -133,8 +133,6 @@ namespace MWWorld
void updateWeather(float duration, bool paused = false); void updateWeather(float duration, bool paused = false);
void rotateObjectImp (const Ptr& ptr, const osg::Vec3f& rot, MWBase::RotationFlags flags);
Ptr copyObjectToCell(const ConstPtr &ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos); Ptr copyObjectToCell(const ConstPtr &ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos);
void updateSoundListener(); void updateSoundListener();
@ -372,10 +370,10 @@ namespace MWWorld
void undeleteObject (const Ptr& ptr) override; void undeleteObject (const Ptr& ptr) override;
MWWorld::Ptr moveObject (const Ptr& ptr, float x, float y, float z, bool movePhysics=true, bool moveToActive=false) override; MWWorld::Ptr moveObject (const Ptr& ptr, const osg::Vec3f& position, bool movePhysics=true, bool moveToActive=false) override;
///< @return an updated Ptr in case the Ptr's cell changes ///< @return an updated Ptr in case the Ptr's cell changes
MWWorld::Ptr moveObject (const Ptr& ptr, CellStore* newCell, float x, float y, float z, bool movePhysics=true) override; MWWorld::Ptr moveObject (const Ptr& ptr, CellStore* newCell, const osg::Vec3f& position, bool movePhysics=true) override;
///< @return an updated Ptr ///< @return an updated Ptr
MWWorld::Ptr moveObjectBy(const Ptr& ptr, osg::Vec3f vec, bool moveToActive, bool ignoreCollisions) override; MWWorld::Ptr moveObjectBy(const Ptr& ptr, osg::Vec3f vec, bool moveToActive, bool ignoreCollisions) override;
@ -387,8 +385,7 @@ namespace MWWorld
/// @note Rotations via this method use a different rotation order than the initial rotations in the CS. This /// @note Rotations via this method use a different rotation order than the initial rotations in the CS. This
/// could be considered a bug, but is needed for MW compatibility. /// could be considered a bug, but is needed for MW compatibility.
/// \param adjust indicates rotation should be set or adjusted /// \param adjust indicates rotation should be set or adjusted
void rotateObject (const Ptr& ptr, float x, float y, float z, void rotateObject (const Ptr& ptr, const osg::Vec3f& rot, MWBase::RotationFlags flags = MWBase::RotationFlag_inverseOrder) override;
MWBase::RotationFlags flags = MWBase::RotationFlag_inverseOrder) override;
MWWorld::Ptr placeObject(const MWWorld::ConstPtr& ptr, MWWorld::CellStore* cell, ESM::Position pos) override; MWWorld::Ptr placeObject(const MWWorld::ConstPtr& ptr, MWWorld::CellStore* cell, ESM::Position pos) override;
///< Place an object. Makes a copy of the Ptr. ///< Place an object. Makes a copy of the Ptr.