This commit is contained in:
gugus 2012-07-09 18:47:59 +02:00
parent e6716c25c3
commit 0a67f60a6e
7 changed files with 124 additions and 103 deletions

View file

@ -178,11 +178,9 @@ namespace MWBase
virtual void moveObject (const MWWorld::Ptr& ptr, float x, float y, float z) = 0;
virtual void scaleObject (MWWorld::Ptr& ptr, float scale) = 0;
virtual void scaleObject (const MWWorld::Ptr& ptr, float scale) = 0;
virtual void rotateObject (MWWorld::Ptr& ptr,float x,float y,float z,bool WorldAxis) = 0;
virtual void setObjectRotation (MWWorld::Ptr& ptr,float x,float y,float z) = 0;
virtual void rotateObject(const MWWorld::Ptr& ptr,float x,float y,float z) = 0;
virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false)
const = 0;

View file

@ -15,6 +15,7 @@
#include "controlextensions.hpp"
#include "dialogueextensions.hpp"
#include "animationextensions.hpp"
#include "transformationextensions.hpp"
namespace MWScript
{
@ -31,6 +32,7 @@ namespace MWScript
Control::registerExtensions (extensions);
Dialogue::registerExtensions (extensions);
Animation::registerExtensions (extensions);
Transformation::registerExtensions (extensions);
}
void installOpcodes (Interpreter::Interpreter& interpreter)
@ -47,5 +49,6 @@ namespace MWScript
Control::installOpcodes (interpreter);
Dialogue::installOpcodes (interpreter);
Animation::installOpcodes (interpreter);
Transformation::installOpcodes (interpreter);
}
}

View file

@ -505,50 +505,6 @@ namespace MWScript
}
};
template<class R>
class OpSetScale : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Float scale = runtime[0].mInteger;
runtime.pop();
MWBase::Environment::get().getWorld()->scaleObject(ptr,scale);
}
};
template<class R>
class OpSetAngle : 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 angle = runtime[0].mInteger;
runtime.pop();
if(axis == "X")
{
MWBase::Environment::get().getWorld()->setObjectRotation(ptr,angle,0,0);
}
if(axis == "Y")
{
MWBase::Environment::get().getWorld()->setObjectRotation(ptr,0,angle,0);
}
if(axis == "Z")
{
MWBase::Environment::get().getWorld()->setObjectRotation(ptr,0,0,angle);
}
}
};
const int numberOfAttributes = 8;
@ -596,11 +552,6 @@ namespace MWScript
const int opcodeModDisposition = 0x200014d;
const int opcodeModDispositionExplicit = 0x200014e;
const int opcodeSetScale = 0x2000164;
const int opcodeSetScaleExplicit = 0x2000165;
const int opcodeSetAngle = 0x2000166;
const int opcodeSetAngleExplicit = 0x2000167;
void registerExtensions (Compiler::Extensions& extensions)
{
static const char *attributes[numberOfAttributes] =
@ -683,9 +634,6 @@ namespace MWScript
extensions.registerInstruction("moddisposition","l",opcodeModDisposition,
opcodeModDispositionExplicit);
extensions.registerFunction("getpcrank",'l',"/S",opcodeGetPCRank,opcodeGetPCRankExplicit);
extensions.registerInstruction("setscale","l",opcodeSetScale,opcodeSetScaleExplicit);
extensions.registerInstruction("setangle","Sl",opcodeSetAngle,opcodeSetAngleExplicit);
}
void installOpcodes (Interpreter::Interpreter& interpreter)
@ -757,11 +705,6 @@ namespace MWScript
interpreter.installSegment5(opcodeModDispositionExplicit,new OpModDisposition<ExplicitRef>);
interpreter.installSegment3(opcodeGetPCRank,new OpGetPCRank<ImplicitRef>);
interpreter.installSegment3(opcodeGetPCRankExplicit,new OpGetPCRank<ExplicitRef>);
interpreter.installSegment5(opcodeSetScale,new OpSetScale<ImplicitRef>);
interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale<ExplicitRef>);
interpreter.installSegment5(opcodeSetAngle,new OpSetAngle<ImplicitRef>);
interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle<ExplicitRef>);
}
}
}

View file

@ -0,0 +1,89 @@
#include "statsextensions.hpp"
#include <boost/algorithm/string.hpp>
#include <components/esm_store/store.hpp>
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
#include "../mwbase/environment.hpp"
#include "../mwworld/class.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
namespace MWScript
{
namespace Transformation
{
template<class R>
class OpSetScale : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Float scale = runtime[0].mInteger;
runtime.pop();
MWBase::Environment::get().getWorld()->scaleObject(ptr,scale);
}
};
template<class R>
class OpSetAngle : 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 angle = runtime[0].mInteger;
runtime.pop();
if(axis == "X")
{
MWBase::Environment::get().getWorld()->rotateObject(ptr,angle,0,0);
}
if(axis == "Y")
{
MWBase::Environment::get().getWorld()->rotateObject(ptr,0,angle,0);
}
if(axis == "Z")
{
MWBase::Environment::get().getWorld()->rotateObject(ptr,0,0,angle);
}
}
};
const int opcodeSetScale = 0x2000164;
const int opcodeSetScaleExplicit = 0x2000165;
const int opcodeSetAngle = 0x2000166;
const int opcodeSetAngleExplicit = 0x2000167;
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerInstruction("setscale","f",opcodeSetScale,opcodeSetScaleExplicit);
extensions.registerInstruction("setangle","Sl",opcodeSetAngle,opcodeSetAngleExplicit);
}
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5(opcodeSetScale,new OpSetScale<ImplicitRef>);
interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale<ExplicitRef>);
interpreter.installSegment5(opcodeSetAngle,new OpSetAngle<ImplicitRef>);
interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle<ExplicitRef>);
}
}
}

View file

@ -0,0 +1,25 @@
#ifndef GAME_SCRIPT_TRANSFORMATIONEXTENSIONS_H
#define GAME_SCRIPT_TRANSFORMATIONEXTENSIONS_H
namespace Compiler
{
class Extensions;
}
namespace Interpreter
{
class Interpreter;
}
namespace MWScript
{
/// \brief stats-related script functionality (creatures and NPCs)
namespace Transformation
{
void registerExtensions (Compiler::Extensions& extensions);
void installOpcodes (Interpreter::Interpreter& interpreter);
}
}
#endif

View file

@ -597,7 +597,7 @@ namespace MWWorld
mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z));
}
void World::scaleObject (Ptr& ptr, float scale)
void World::scaleObject (const Ptr& ptr, float scale)
{
MWWorld::Class::get(ptr).adjustScale(ptr,scale);
@ -607,41 +607,7 @@ namespace MWWorld
mPhysics->scaleObject( ptr.getRefData().getHandle(), scale );
}
void World::rotateObject (Ptr& ptr,float x,float y,float z,bool WorldAxis)
{
MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z);
if(WorldAxis)
{
ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(x));
ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(y));
ptr.getRefData().getBaseNode()->rotate(Ogre::Vector3::UNIT_X,Ogre::Degree(z));
}
else
{
Ogre::Matrix3 axis = ptr.getRefData().getBaseNode()->getLocalAxes();
Ogre::Vector3 xAxis = axis.GetColumn(0);
Ogre::Vector3 yAxis = axis.GetColumn(1);
Ogre::Vector3 zAxis = axis.GetColumn(2);
ptr.getRefData().getBaseNode()->rotate(xAxis,Ogre::Degree(x));
ptr.getRefData().getBaseNode()->rotate(yAxis,Ogre::Degree(y));
ptr.getRefData().getBaseNode()->rotate(zAxis,Ogre::Degree(z));
}
Ogre::Matrix3 rot;
ptr.getRefData().getBaseNode()->getOrientation().ToRotationMatrix(rot);
Ogre::Radian rx,ry,rz;
rot.ToEulerAnglesXYZ(rx,ry,rz);
ptr.getRefData().getPosition().rot[0] = rx.valueRadians();
ptr.getRefData().getPosition().rot[0] = ry.valueRadians();
ptr.getRefData().getPosition().rot[0] = rz.valueRadians();
mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode()->getOrientation());
//ptr.getRefData().getBaseNode()->rotate(ptr.getRefData().getBaseNode()->get
//mPhysics->scaleObject( Class::get(ptr).getId(ptr), scale );
}
void World::setObjectRotation (Ptr& ptr,float x,float y,float z)
void World::rotateObject (const Ptr& ptr,float x,float y,float z)
{
MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z);
@ -653,8 +619,7 @@ namespace MWWorld
Ogre::Quaternion roty(Ogre::Degree(y),Ogre::Vector3::UNIT_Y);
Ogre::Quaternion rotz(Ogre::Degree(z),Ogre::Vector3::UNIT_Z);
ptr.getRefData().getBaseNode()->setOrientation(rotx*roty*rotz);
mPhysics->rotateObject(Class::get(ptr).getId(ptr),ptr.getRefData().getBaseNode()->getOrientation());
std::cout << Class::get(ptr).getId(ptr);
mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode()->getOrientation());
}
void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const

View file

@ -219,11 +219,9 @@ namespace MWWorld
virtual void moveObject (const Ptr& ptr, float x, float y, float z);
virtual void scaleObject (Ptr& ptr, float scale);
virtual void scaleObject (const Ptr& ptr, float scale);
virtual void rotateObject (Ptr& ptr,float x,float y,float z,bool WorldAxis);
virtual void setObjectRotation (Ptr& ptr,float x,float y,float z);
virtual void rotateObject (const Ptr& ptr,float x,float y,float z);
virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false)
const;