mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-01 11:45:34 +00:00
Working rotate, rotateworld
This commit is contained in:
parent
4e0233cf06
commit
972481f63f
8 changed files with 73 additions and 6 deletions
|
@ -251,6 +251,8 @@ namespace MWBase
|
|||
virtual void changePointer (const std::string& name) = 0;
|
||||
|
||||
virtual const Translation::Storage& getTranslationDataStorage() const = 0;
|
||||
|
||||
virtual int getFPS() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -230,6 +230,8 @@ namespace MWBase
|
|||
|
||||
virtual void rotateObject(const MWWorld::Ptr& ptr,float x,float y,float z, bool adjust = false) = 0;
|
||||
|
||||
virtual void localRotateObject (const MWWorld::Ptr& ptr, float rotation, Ogre::Vector3 axis) = 0;
|
||||
|
||||
virtual void safePlaceObject(const MWWorld::Ptr& ptr,MWWorld::CellStore &Cell,ESM::Position pos) = 0;
|
||||
///< place an object in a "safe" location (ie not in the void, etc).
|
||||
|
||||
|
|
|
@ -1200,3 +1200,8 @@ void WindowManager::frameStarted (float dt)
|
|||
{
|
||||
mInventoryWindow->doRenderUpdate ();
|
||||
}
|
||||
|
||||
int WindowManager::getFPS() const
|
||||
{
|
||||
return mFPS;
|
||||
}
|
||||
|
|
|
@ -248,6 +248,8 @@ namespace MWGui
|
|||
|
||||
void onSoulgemDialogButtonPressed (int button);
|
||||
|
||||
virtual int getFPS() const;
|
||||
|
||||
private:
|
||||
OEngine::GUI::MyGUIManager *mGuiManager;
|
||||
OEngine::Render::OgreRenderer *mRendering;
|
||||
|
|
|
@ -320,5 +320,7 @@ op 0x20001fd: IsWerewolf
|
|||
op 0x20001fe: IsWerewolf, explicit reference
|
||||
op 0x20001ff: Rotate
|
||||
op 0x2000200: Rotate, explicit reference
|
||||
op 0x2000201: RotateWorld
|
||||
op 0x2000202: RotateWorld, explicit reference
|
||||
|
||||
opcodes 0x2000201-0x3ffffff unused
|
||||
opcodes 0x2000203-0x3ffffff unused
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <components/interpreter/opcodes.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/player.hpp"
|
||||
|
@ -549,11 +550,11 @@ namespace MWScript
|
|||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWWorld::Ptr ptr = R()(runtime);
|
||||
const MWWorld::Ptr& ptr = R()(runtime);
|
||||
|
||||
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
Interpreter::Type_Float rotation = (runtime[0].mFloat/80); //It works this way, don't ask me why (probably framerate)
|
||||
Interpreter::Type_Float rotation = (runtime[0].mFloat/MWBase::Environment::get().getWindowManager()->getFPS());
|
||||
runtime.pop();
|
||||
|
||||
float *objRot = ptr.getRefData().getPosition().rot;
|
||||
|
@ -562,19 +563,22 @@ namespace MWScript
|
|||
{
|
||||
objRot[0]+=Ogre::Degree(rotation).valueRadians();
|
||||
|
||||
ptr.getRefData().getBaseNode()->rotate(Ogre::Quaternion(Ogre::Radian(Ogre::Degree(-rotation).valueRadians()), Ogre::Vector3::UNIT_X));;
|
||||
if (ptr.getRefData().getBaseNode() != 0)
|
||||
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_X);
|
||||
}
|
||||
else if (axis == "y")
|
||||
{
|
||||
objRot[1]+=Ogre::Degree(rotation).valueRadians();
|
||||
|
||||
ptr.getRefData().getBaseNode()->rotate(Ogre::Quaternion(Ogre::Radian(Ogre::Degree(-rotation).valueRadians()), Ogre::Vector3::UNIT_Y));
|
||||
if (ptr.getRefData().getBaseNode() != 0)
|
||||
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_Y);
|
||||
}
|
||||
else if (axis == "z")
|
||||
{
|
||||
objRot[2]+=Ogre::Degree(rotation).valueRadians();
|
||||
|
||||
ptr.getRefData().getBaseNode()->rotate(Ogre::Quaternion(Ogre::Radian(Ogre::Degree(-rotation).valueRadians()), Ogre::Vector3::UNIT_Z));
|
||||
if (ptr.getRefData().getBaseNode() != 0)
|
||||
MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_Z);
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -582,6 +586,43 @@ namespace MWScript
|
|||
}
|
||||
};
|
||||
|
||||
template<class R>
|
||||
class OpRotateWorld : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWWorld::Ptr ptr = R()(runtime);
|
||||
|
||||
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
Interpreter::Type_Float rotation = (runtime[0].mFloat/MWBase::Environment::get().getWindowManager()->getFPS());
|
||||
runtime.pop();
|
||||
|
||||
float *objRot = ptr.getRefData().getPosition().rot;
|
||||
|
||||
float ax = Ogre::Radian(objRot[0]).valueDegrees();
|
||||
float ay = Ogre::Radian(objRot[1]).valueDegrees();
|
||||
float az = Ogre::Radian(objRot[2]).valueDegrees();
|
||||
|
||||
if (axis == "x")
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax+rotation,ay,az);
|
||||
}
|
||||
else if (axis == "y")
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay+rotation,az);
|
||||
}
|
||||
else if (axis == "z")
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,az+rotation);
|
||||
}
|
||||
else
|
||||
throw std::runtime_error ("invalid rotation axis: " + axis);
|
||||
}
|
||||
};
|
||||
|
||||
const int opcodeSetScale = 0x2000164;
|
||||
const int opcodeSetScaleExplicit = 0x2000165;
|
||||
const int opcodeSetAngle = 0x2000166;
|
||||
|
@ -610,6 +651,8 @@ namespace MWScript
|
|||
const int opcodeModScaleExplicit = 0x20001e4;
|
||||
const int opcodeRotate = 0x20001ff;
|
||||
const int opcodeRotateExplicit = 0x2000200;
|
||||
const int opcodeRotateWorld = 0x2000201;
|
||||
const int opcodeRotateWorldExplicit = 0x2000202;
|
||||
|
||||
void registerExtensions (Compiler::Extensions& extensions)
|
||||
{
|
||||
|
@ -628,6 +671,7 @@ namespace MWScript
|
|||
extensions.registerInstruction("placeatme","clfl",opcodePlaceAtMe,opcodePlaceAtMeExplicit);
|
||||
extensions.registerInstruction("modscale","f",opcodeModScale,opcodeModScaleExplicit);
|
||||
extensions.registerInstruction("rotate","cf",opcodeRotate,opcodeRotateExplicit);
|
||||
extensions.registerInstruction("rotateworld","cf",opcodeRotateWorld,opcodeRotateWorldExplicit);
|
||||
}
|
||||
|
||||
void installOpcodes (Interpreter::Interpreter& interpreter)
|
||||
|
@ -659,6 +703,8 @@ namespace MWScript
|
|||
interpreter.installSegment5(opcodeModScaleExplicit,new OpModScale<ExplicitRef>);
|
||||
interpreter.installSegment5(opcodeRotate,new OpRotate<ImplicitRef>);
|
||||
interpreter.installSegment5(opcodeRotateExplicit,new OpRotate<ExplicitRef>);
|
||||
interpreter.installSegment5(opcodeRotateWorld,new OpRotateWorld<ImplicitRef>);
|
||||
interpreter.installSegment5(opcodeRotateWorldExplicit,new OpRotateWorld<ExplicitRef>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -826,6 +826,12 @@ 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);
|
||||
}
|
||||
|
||||
void World::adjustPosition(const Ptr &ptr)
|
||||
{
|
||||
Ogre::Vector3 pos (ptr.getRefData().getPosition().pos[0], ptr.getRefData().getPosition().pos[1], ptr.getRefData().getPosition().pos[2]);
|
||||
|
|
|
@ -254,6 +254,8 @@ namespace MWWorld
|
|||
/// \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 localRotateObject (const Ptr& ptr, float rotation, Ogre::Vector3 axis);
|
||||
|
||||
virtual void safePlaceObject(const MWWorld::Ptr& ptr,MWWorld::CellStore &Cell,ESM::Position pos);
|
||||
///< place an object in a "safe" location (ie not in the void, etc). Makes a copy of the Ptr.
|
||||
|
||||
|
|
Loading…
Reference in a new issue