fixed rotation adjustment

actorid
greye 13 years ago
parent 5018db3332
commit 45306e4bc3

@ -27,10 +27,10 @@ namespace MWRender
// we are only interested in X and Y rotation
// Rotate around X axis
Ogre::Quaternion xr(Ogre::Degree(rot.x), Ogre::Vector3::UNIT_X);
Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X);
// Rotate around Y axis
Ogre::Quaternion yr(Ogre::Degree(-rot.z), Ogre::Vector3::UNIT_Y);
Ogre::Quaternion yr(Ogre::Radian(-rot.z), Ogre::Vector3::UNIT_Y);
pitchNode->setOrientation(xr);
yawNode->setOrientation(yr);
@ -56,8 +56,8 @@ namespace MWRender
Ogre::SceneNode *pitchNode = mCamera->getParentSceneNode();
Ogre::SceneNode *yawNode = pitchNode->getParentSceneNode();
pitchNode->pitch(Ogre::Degree(rot.x));
yawNode->yaw(Ogre::Degree(-rot.z));
pitchNode->pitch(Ogre::Radian(rot.x));
yawNode->yaw(Ogre::Radian(-rot.z));
controlFlip();
updateListener();

@ -37,9 +37,11 @@ namespace MWRender
Player (Ogre::Camera *camera, Ogre::SceneNode* mNode);
/// Set where the player is looking at. Uses Morrowind (euler) angles
/// \param rot Rotation angles in radians
/// \return true if player object needs to bo rotated physically
bool setRotation(const Ogre::Vector3 &rot);
/// \param rot Rotation angles in radians
/// \return true if player object needs to bo rotated physically
bool adjustRotation(const Ogre::Vector3 &rot);

@ -254,27 +254,31 @@ RenderingManager::rotateObject(
Ogre::Vector3 &rot,
bool adjust)
{
if (ptr.getRefData().getHandle() == "player") {
bool isPlayer = ptr.getRefData().getHandle() == "player";
bool force = true;
if (isPlayer) {
if (adjust) {
return mPlayer->adjustRotation(rot);
force = mPlayer->adjustRotation(rot);
} else {
return mPlayer->setRotation(rot);
force = mPlayer->setRotation(rot);
}
}
MWWorld::Class::get(ptr).adjustRotation(ptr, rot.x, rot.y, rot.z);
if (adjust) {
/// \note Stored and passed in radians
float *f = ptr.getRefData().getPosition().rot;
rot.x += f[0], rot.y += f[1], rot.z += f[2];
}
if (!isPlayer) {
Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X);
Ogre::Quaternion yr(Ogre::Radian(rot.y), Ogre::Vector3::UNIT_Y);
Ogre::Quaternion zr(Ogre::Radian(rot.z), Ogre::Vector3::UNIT_Z);
Ogre::Quaternion xr(Ogre::Degree(rot.x), Ogre::Vector3::UNIT_X);
Ogre::Quaternion yr(Ogre::Degree(rot.y), Ogre::Vector3::UNIT_Y);
Ogre::Quaternion zr(Ogre::Degree(rot.z), Ogre::Vector3::UNIT_Z);
ptr.getRefData().getBaseNode()->setOrientation(xr * yr * zr);
return true;
ptr.getRefData().getBaseNode()->setOrientation(xr * yr * zr);
}
return force;
}
void

@ -87,6 +87,7 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList
void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale);
/// Rotates object accordingly to its type
/// \param rot euler angles in radians
/// \param adjust indicates should rotation be set or adjusted
/// \return true if object needs to be rotated physically
bool rotateObject (const MWWorld::Ptr& ptr, Ogre::Vector3 &rot, bool adjust = false);

@ -150,7 +150,11 @@ namespace MWWorld
if (adjustPlayerPos) {
world->moveObject(player, pos.pos[0], pos.pos[1], pos.pos[2]);
world->rotateObject(player, pos.rot[0], pos.rot[1], pos.rot[2]);
float x = Ogre::Radian(pos.rot[0]).valueDegrees();
float y = Ogre::Radian(pos.rot[1]).valueDegrees();
float z = Ogre::Radian(pos.rot[2]).valueDegrees();
world->rotateObject(player, x, y, z);
}
MWMechanics::MechanicsManager *mechMgr =

@ -629,12 +629,14 @@ namespace MWWorld
void World::rotateObject (const Ptr& ptr,float x,float y,float z, bool adjust)
{
Ogre::Vector3 rot(x, y, z);
Ogre::Vector3 rot;
rot.x = Ogre::Degree(x).valueRadians();
rot.y = Ogre::Degree(y).valueRadians();
rot.z = Ogre::Degree(z).valueRadians();
if (mRendering->rotateObject(ptr, rot, adjust)) {
float *objRot = ptr.getRefData().getPosition().rot;
objRot[0] = Ogre::Degree(rot.x).valueRadians();
objRot[1] = Ogre::Degree(rot.y).valueRadians();
objRot[2] = Ogre::Degree(rot.z).valueRadians();
objRot[0] = rot.x, objRot[1] = rot.y, objRot[2] = rot.z;
mPhysics->rotateObject(
ptr.getRefData().getHandle(),

@ -210,6 +210,8 @@ namespace MWWorld
virtual void scaleObject (const Ptr& ptr, float scale);
/// Rotates object, uses degrees
/// \param adjust indicates rotation should be set or adjusted
virtual void rotateObject (const Ptr& ptr,float x,float y,float z, bool adjust = false);
virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false)

Loading…
Cancel
Save