mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Avoid converting to and from quaternions
This commit is contained in:
parent
ee5d0277e8
commit
63af72c315
@ -262,37 +262,29 @@ void RenderingManager::scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3
|
|||||||
ptr.getRefData().getBaseNode()->setScale(scale);
|
ptr.getRefData().getBaseNode()->setScale(scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderingManager::rotateObject( const MWWorld::Ptr &ptr, Ogre::Vector3 &rot, bool adjust)
|
bool RenderingManager::rotateObject(const MWWorld::Ptr &ptr, Ogre::Vector3 &rot, bool adjust)
|
||||||
{
|
{
|
||||||
bool isActive = ptr.getRefData().getBaseNode() != 0;
|
bool isActive = ptr.getRefData().getBaseNode() != 0;
|
||||||
bool isPlayer = isActive && ptr.getRefData().getHandle() == "player";
|
bool isPlayer = isActive && ptr.getRefData().getHandle() == "player";
|
||||||
bool force = true;
|
bool force = true;
|
||||||
|
|
||||||
if (isPlayer)
|
if (isPlayer)
|
||||||
force = mPlayer->rotate(rot, adjust);
|
force = mPlayer->rotate(rot, adjust);
|
||||||
|
|
||||||
MWWorld::Class::get(ptr).adjustRotation(ptr, rot.x, rot.y, rot.z);
|
|
||||||
|
|
||||||
|
MWWorld::Class::get(ptr).adjustRotation(ptr, rot.x, rot.y, rot.z);
|
||||||
if (!isPlayer && isActive)
|
if (!isPlayer && isActive)
|
||||||
{
|
{
|
||||||
Ogre::Quaternion xr(Ogre::Radian(-rot.x), Ogre::Vector3::UNIT_X);
|
if(adjust)
|
||||||
Ogre::Quaternion yr(Ogre::Radian(-rot.y), Ogre::Vector3::UNIT_Y);
|
{
|
||||||
Ogre::Quaternion zr(Ogre::Radian(-rot.z), Ogre::Vector3::UNIT_Z);
|
const float *objRot = ptr.getRefData().getPosition().rot;
|
||||||
|
rot.x += objRot[0];
|
||||||
Ogre::Quaternion xref(Ogre::Radian(-ptr.getRefData().getPosition().rot[0]), Ogre::Vector3::UNIT_X);
|
rot.y += objRot[1];
|
||||||
Ogre::Quaternion yref(Ogre::Radian(-ptr.getRefData().getPosition().rot[1]), Ogre::Vector3::UNIT_Y);
|
rot.z += objRot[2];
|
||||||
Ogre::Quaternion zref(Ogre::Radian(-ptr.getRefData().getPosition().rot[2]), Ogre::Vector3::UNIT_Z);
|
}
|
||||||
|
|
||||||
Ogre::Quaternion newo = adjust ? (xr * yr * zr) * (xref*yref*zref) : xr * yr * zr;
|
|
||||||
|
|
||||||
Ogre::Matrix3 mat;
|
|
||||||
newo.ToRotationMatrix(mat);
|
|
||||||
Ogre::Radian ax,ay,az;
|
|
||||||
mat.ToEulerAnglesXYZ(ax,ay,az);
|
|
||||||
rot.x = -ax.valueRadians();
|
|
||||||
rot.y = -ay.valueRadians();
|
|
||||||
rot.z = -az.valueRadians();
|
|
||||||
|
|
||||||
|
Ogre::Quaternion newo = Ogre::Quaternion(Ogre::Radian(-rot.x), Ogre::Vector3::UNIT_X) *
|
||||||
|
Ogre::Quaternion(Ogre::Radian(-rot.y), Ogre::Vector3::UNIT_Y) *
|
||||||
|
Ogre::Quaternion(Ogre::Radian(-rot.z), Ogre::Vector3::UNIT_Z);
|
||||||
ptr.getRefData().getBaseNode()->setOrientation(newo);
|
ptr.getRefData().getBaseNode()->setOrientation(newo);
|
||||||
}
|
}
|
||||||
else if(isPlayer)
|
else if(isPlayer)
|
||||||
|
@ -816,7 +816,9 @@ namespace MWWorld
|
|||||||
{
|
{
|
||||||
// rotate physically iff renderer confirm so
|
// rotate physically iff renderer confirm so
|
||||||
float *objRot = ptr.getRefData().getPosition().rot;
|
float *objRot = ptr.getRefData().getPosition().rot;
|
||||||
objRot[0] = rot.x, objRot[1] = rot.y, objRot[2] = rot.z;
|
objRot[0] = rot.x;
|
||||||
|
objRot[1] = rot.y;
|
||||||
|
objRot[2] = rot.z;
|
||||||
|
|
||||||
if (ptr.getRefData().getBaseNode() != 0) {
|
if (ptr.getRefData().getBaseNode() != 0) {
|
||||||
mPhysics->rotateObject(ptr);
|
mPhysics->rotateObject(ptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user