mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-11 00:44:33 +00:00
Change rotateObject() to take a osg::Vec3f argument instead of 3 floats
for readability.
This commit is contained in:
parent
88a5ca440b
commit
a7b190ad29
@ -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.
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ namespace MWLua
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
MWWorld::Ptr newObj = world->moveObject(obj, cell, mPos);
|
MWWorld::Ptr newObj = world->moveObject(obj, cell, mPos);
|
||||||
world->rotateObject(newObj, mRot.x(), mRot.y(), mRot.z());
|
world->rotateObject(newObj, mRot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -396,14 +396,14 @@ namespace MWScript
|
|||||||
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr,store,osg::Vec3f(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);
|
||||||
}
|
}
|
||||||
@ -452,14 +452,14 @@ namespace MWScript
|
|||||||
}
|
}
|
||||||
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,11 +680,7 @@ 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().asVec3()));
|
MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().getPosition().asVec3()));
|
||||||
|
@ -843,11 +843,7 @@ namespace MWWorld
|
|||||||
|
|
||||||
if (adjustPlayerPos) {
|
if (adjustPlayerPos) {
|
||||||
world->moveObject(player, pos.asVec3());
|
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);
|
||||||
}
|
}
|
||||||
@ -922,11 +918,7 @@ namespace MWWorld
|
|||||||
{
|
{
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
world->moveObject(world->getPlayerPtr(), position.asVec3());
|
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);
|
||||||
|
@ -1131,11 +1131,7 @@ namespace MWWorld
|
|||||||
MWWorld::Ptr World::moveObject(const Ptr &ptr, CellStore* newCell, const osg::Vec3f& position, 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] = position.x();
|
|
||||||
pos.pos[1] = position.y();
|
|
||||||
pos.pos[2] = position.z();
|
|
||||||
|
|
||||||
ptr.getRefData().setPosition(pos);
|
ptr.getRefData().setPosition(pos);
|
||||||
|
|
||||||
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
|
||||||
@ -1292,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);
|
||||||
|
|
||||||
@ -1414,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)
|
||||||
@ -1602,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;
|
||||||
|
|
||||||
@ -1660,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;
|
||||||
@ -2511,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());
|
||||||
@ -3858,7 +3851,7 @@ namespace MWWorld
|
|||||||
|
|
||||||
const ESM::Position& origPos = ptr.getCellRef().getPosition();
|
const ESM::Position& origPos = ptr.getCellRef().getPosition();
|
||||||
MWBase::Environment::get().getWorld()->moveObject(ptr, origPos.asVec3());
|
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;
|
||||||
|
@ -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();
|
||||||
@ -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.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user