Added rotation layer

This commit is contained in:
Glorf 2013-04-16 21:17:19 +02:00
parent e0357c7b7c
commit 1e92ffc314
5 changed files with 44 additions and 18 deletions

View file

@ -102,6 +102,11 @@ namespace MWScript
} }
else else
throw std::runtime_error ("invalid ration axis: " + axis); 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") 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") 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") 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 else
throw std::runtime_error ("invalid ration axis: " + axis); 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()); Interpreter::Type_Float rotation = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
runtime.pop(); runtime.pop();
float *objRot = ptr.getRefData().getPosition().rot;
if (axis == "x") if (axis == "x")
{ {
objRot[0]+=Ogre::Degree(rotation).valueRadians(); ptr.getRefData().getLocalRotation().rot[0]+=rotation;
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_X);
if (ptr.getRefData().getBaseNode() != 0)
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_X);
} }
else if (axis == "y") else if (axis == "y")
{ {
objRot[1]+=Ogre::Degree(rotation).valueRadians(); ptr.getRefData().getLocalRotation().rot[1]+=rotation;
if (ptr.getRefData().getBaseNode() != 0)
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_Y); MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_Y);
} }
else if (axis == "z") else if (axis == "z")
{ {
objRot[2]+=Ogre::Degree(rotation).valueRadians(); ptr.getRefData().getLocalRotation().rot[2]+=rotation;
if (ptr.getRefData().getBaseNode() != 0)
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_Z); MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_Z);
} }

View file

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

View file

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

View file

@ -50,6 +50,13 @@ namespace
rendering.addObject(ptr); rendering.addObject(ptr);
class_.insertObject(ptr, physics); class_.insertObject(ptr, physics);
MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true); 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); MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().mScale);
class_.adjustPosition(ptr); class_.adjustPosition(ptr);
} }

View file

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