Added rotation layer

actorid
Glorf 12 years ago
parent e0357c7b7c
commit 1e92ffc314

@ -102,6 +102,11 @@ namespace MWScript
}
else
throw std::runtime_error ("invalid ration axis: " + axis);
//Local rotations clear
ptr.getRefData().getLocalRotation().rot[0]=0;
ptr.getRefData().getLocalRotation().rot[1]=0;
ptr.getRefData().getLocalRotation().rot[2]=0;
}
};
@ -148,15 +153,15 @@ namespace MWScript
if (axis=="x")
{
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees());
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[0]+ptr.getRefData().getLocalRotation().rot[0]).valueDegrees());
}
else if (axis=="y")
{
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees());
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[1]+ptr.getRefData().getLocalRotation().rot[1]).valueDegrees());
}
else if (axis=="z")
{
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees());
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[2]+ptr.getRefData().getLocalRotation().rot[2]).valueDegrees());
}
else
throw std::runtime_error ("invalid ration axis: " + axis);
@ -556,27 +561,19 @@ namespace MWScript
Interpreter::Type_Float rotation = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
runtime.pop();
float *objRot = ptr.getRefData().getPosition().rot;
if (axis == "x")
{
objRot[0]+=Ogre::Degree(rotation).valueRadians();
if (ptr.getRefData().getBaseNode() != 0)
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_X);
ptr.getRefData().getLocalRotation().rot[0]+=rotation;
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_X);
}
else if (axis == "y")
{
objRot[1]+=Ogre::Degree(rotation).valueRadians();
if (ptr.getRefData().getBaseNode() != 0)
ptr.getRefData().getLocalRotation().rot[1]+=rotation;
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_Y);
}
else if (axis == "z")
{
objRot[2]+=Ogre::Degree(rotation).valueRadians();
if (ptr.getRefData().getBaseNode() != 0)
ptr.getRefData().getLocalRotation().rot[2]+=rotation;
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_Z);
}

@ -19,6 +19,7 @@ namespace MWWorld
mEnabled = refData.mEnabled;
mCount = refData.mCount;
mPosition = refData.mPosition;
mLocalRotation = refData.mLocalRotation;
mCustomData = refData.mCustomData ? refData.mCustomData->clone() : 0;
}
@ -34,7 +35,11 @@ namespace MWWorld
RefData::RefData (const ESM::CellRef& cellRef)
: mBaseNode(0), mHasLocals (false), mEnabled (true), mCount (1), mPosition (cellRef.mPos),
mCustomData (0)
{}
{
mLocalRotation.rot[0]=0;
mLocalRotation.rot[1]=0;
mLocalRotation.rot[2]=0;
}
RefData::RefData (const RefData& refData)
: mBaseNode(0), mCustomData (0)
@ -141,6 +146,11 @@ namespace MWWorld
return mPosition;
}
LocalRotation& RefData::getLocalRotation()
{
return mLocalRotation;
}
void RefData::setCustomData (CustomData *data)
{
delete mCustomData;

@ -5,6 +5,8 @@
#include "../mwscript/locals.hpp"
#include <OgreVector3.h>
namespace Ogre
{
class SceneNode;
@ -18,6 +20,10 @@ namespace ESM
namespace MWWorld
{
struct LocalRotation{
float rot[3];
};
class CustomData;
class RefData
@ -34,6 +40,8 @@ namespace MWWorld
ESM::Position mPosition;
LocalRotation mLocalRotation;
CustomData *mCustomData;
void copy (const RefData& refData);
@ -78,6 +86,8 @@ namespace MWWorld
ESM::Position& getPosition();
LocalRotation& getLocalRotation();
void setCustomData (CustomData *data);
///< Set custom data (potentially replacing old custom data). The ownership of \æ data is
/// transferred to this.

@ -50,6 +50,13 @@ namespace
rendering.addObject(ptr);
class_.insertObject(ptr, physics);
MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true);
//To keep local-rotations
const float *local = ptr.getRefData().getLocalRotation().rot;
MWBase::Environment::get().getWorld()->localRotateObject(ptr, local[0], Ogre::Vector3::UNIT_X);
MWBase::Environment::get().getWorld()->localRotateObject(ptr, local[1], Ogre::Vector3::UNIT_Y);
MWBase::Environment::get().getWorld()->localRotateObject(ptr, local[2], Ogre::Vector3::UNIT_Z);
MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().mScale);
class_.adjustPosition(ptr);
}

@ -826,8 +826,10 @@ namespace MWWorld
void World::localRotateObject (const Ptr& ptr, float rotation, Ogre::Vector3 axis)
{
ptr.getRefData().getBaseNode()->rotate(Ogre::Quaternion(Ogre::Radian(Ogre::Degree(-rotation).valueRadians()), axis));
mPhysics->rotateObject(ptr);
if (ptr.getRefData().getBaseNode() != 0) {
ptr.getRefData().getBaseNode()->rotate(Ogre::Quaternion(Ogre::Radian(Ogre::Degree(-rotation).valueRadians()), axis));
mPhysics->rotateObject(ptr);
}
}
void World::adjustPosition(const Ptr &ptr)

Loading…
Cancel
Save