mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 23:26:41 +00:00 
			
		
		
		
	Merge rotate
This commit is contained in:
		
						commit
						e0357c7b7c
					
				
					 5 changed files with 105 additions and 1 deletions
				
			
		|  | @ -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).
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -318,5 +318,9 @@ op 0x20001fb: DropSoulGem, explicit reference | |||
| op 0x20001fc: OnDeath | ||||
| 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 0x20001ff-0x3ffffff unused | ||||
| opcodes 0x2000203-0x3ffffff unused | ||||
|  |  | |||
|  | @ -542,6 +542,86 @@ namespace MWScript | |||
|                 } | ||||
|         }; | ||||
| 
 | ||||
|         template<class R> | ||||
|         class OpRotate : public Interpreter::Opcode0 | ||||
|         { | ||||
|             public: | ||||
| 
 | ||||
|                 virtual void execute (Interpreter::Runtime& runtime) | ||||
|                 { | ||||
|                     const 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().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); | ||||
|                     } | ||||
|                     else if (axis == "y") | ||||
|                     { | ||||
|                         objRot[1]+=Ogre::Degree(rotation).valueRadians(); | ||||
| 
 | ||||
|                         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(); | ||||
| 
 | ||||
|                         if (ptr.getRefData().getBaseNode() != 0) | ||||
|                         MWBase::Environment::get().getWorld()->localRotateObject(ptr, rotation, Ogre::Vector3::UNIT_Z); | ||||
|                     } | ||||
| 
 | ||||
|                     else | ||||
|                         throw std::runtime_error ("invalid rotation axis: " + axis); | ||||
|                 } | ||||
|         }; | ||||
| 
 | ||||
|         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().getFrameDuration()); | ||||
|                     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; | ||||
|  | @ -568,6 +648,10 @@ namespace MWScript | |||
|         const int opcodePlaceAtMeExplicit = 0x200019e; | ||||
|         const int opcodeModScale = 0x20001e3; | ||||
|         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) | ||||
|         { | ||||
|  | @ -585,6 +669,8 @@ namespace MWScript | |||
|             extensions.registerInstruction("placeatpc","clfl",opcodePlaceAtPc); | ||||
|             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) | ||||
|  | @ -614,6 +700,10 @@ namespace MWScript | |||
|             interpreter.installSegment5(opcodePlaceAtMeExplicit,new OpPlaceAtMe<ExplicitRef>); | ||||
|             interpreter.installSegment5(opcodeModScale,new OpModScale<ImplicitRef>); | ||||
|             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>); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -824,6 +824,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