From 557e114992458b1d7c2768baaf342a64dc01542e Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 9 Jul 2012 19:28:44 +0200 Subject: [PATCH] clean-up + getScale/Angle script instructions --- .../mwscript/transformationextensions.cpp | 59 +++++++++++++++++-- apps/openmw/mwworld/worldimp.cpp | 4 +- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 14181a06e2..41eba4a994 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -1,6 +1,3 @@ - -#include "statsextensions.hpp" - #include #include @@ -17,6 +14,7 @@ #include "interpretercontext.hpp" #include "ref.hpp" +#include "OgreSceneNode.h" namespace MWScript { @@ -31,13 +29,25 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - Interpreter::Type_Float scale = runtime[0].mInteger; + Interpreter::Type_Float scale = runtime[0].mFloat; runtime.pop(); MWBase::Environment::get().getWorld()->scaleObject(ptr,scale); } }; + template + class OpGetScale : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + runtime.push(ptr.getCellRef().scale); + } + }; + template class OpSetAngle : public Interpreter::Opcode0 { @@ -49,7 +59,7 @@ namespace MWScript std::string axis = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - Interpreter::Type_Float angle = runtime[0].mInteger; + Interpreter::Type_Float angle = runtime[0].mFloat; runtime.pop(); if(axis == "X") @@ -67,15 +77,48 @@ namespace MWScript } }; + template + class OpGetAngle : 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(); + + if(axis == "X") + { + runtime.push(ptr.getRefData().getPosition().rot[0]); + } + if(axis == "Y") + { + runtime.push(ptr.getRefData().getPosition().rot[1]); + } + if(axis == "Z") + { + runtime.push(ptr.getRefData().getPosition().rot[0]); + } + } + }; + const int opcodeSetScale = 0x2000164; const int opcodeSetScaleExplicit = 0x2000165; const int opcodeSetAngle = 0x2000166; const int opcodeSetAngleExplicit = 0x2000167; + const int opcodeGetScale = 0x2000168; + const int opcodeGetScaleExplicit = 0x2000169; + const int opcodeGetAngle = 0x200016a; + const int opcodeGetAngleExplicit = 0x200016b; void registerExtensions (Compiler::Extensions& extensions) { extensions.registerInstruction("setscale","f",opcodeSetScale,opcodeSetScaleExplicit); - extensions.registerInstruction("setangle","Sl",opcodeSetAngle,opcodeSetAngleExplicit); + extensions.registerFunction("getscale",'f',"",opcodeGetScale,opcodeGetScaleExplicit); + extensions.registerInstruction("setangle","Sf",opcodeSetAngle,opcodeSetAngleExplicit); + extensions.registerFunction("getangle",'f',"S",opcodeGetAngle,opcodeGetAngleExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -84,6 +127,10 @@ namespace MWScript interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale); interpreter.installSegment5(opcodeSetAngle,new OpSetAngle); interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle); + interpreter.installSegment5(opcodeGetScale,new OpGetScale); + interpreter.installSegment5(opcodeGetScaleExplicit,new OpGetScale); + interpreter.installSegment5(opcodeGetAngle,new OpGetAngle); + interpreter.installSegment5(opcodeGetAngleExplicit,new OpGetAngle); } } } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index c6423563d1..5309fbe40c 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -612,8 +612,8 @@ namespace MWWorld MWWorld::Class::get(ptr).adjustRotation(ptr,x,y,z); ptr.getRefData().getPosition().rot[0] = Ogre::Degree(x).valueRadians(); - ptr.getRefData().getPosition().rot[0] = Ogre::Degree(y).valueRadians(); - ptr.getRefData().getPosition().rot[0] = Ogre::Degree(z).valueRadians(); + ptr.getRefData().getPosition().rot[1] = Ogre::Degree(y).valueRadians(); + ptr.getRefData().getPosition().rot[2] = Ogre::Degree(z).valueRadians(); Ogre::Quaternion rotx(Ogre::Degree(x),Ogre::Vector3::UNIT_X); Ogre::Quaternion roty(Ogre::Degree(y),Ogre::Vector3::UNIT_Y);