mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 20:26:43 +00:00 
			
		
		
		
	rotateObject, scaleObject
This commit is contained in:
		
							parent
							
								
									6f3e920f85
								
							
						
					
					
						commit
						1c0e3a6488
					
				
					 6 changed files with 39 additions and 47 deletions
				
			
		|  | @ -102,25 +102,6 @@ void Objects::insertBegin(const MWWorld::Ptr& ptr) | |||
|     const float *f = ptr.getRefData().getPosition().pos; | ||||
| 
 | ||||
|     insert->setPosition(osg::Vec3(f[0], f[1], f[2])); | ||||
|     insert->setScale(osg::Vec3(ptr.getCellRef().getScale(), ptr.getCellRef().getScale(), ptr.getCellRef().getScale())); | ||||
| 
 | ||||
|     // Convert MW rotation to a quaternion:
 | ||||
|     f = ptr.getCellRef().getPosition().rot; | ||||
| 
 | ||||
|     // Rotate around X axis
 | ||||
|     osg::Quat xr(-f[0], osg::Vec3(1,0,0)); | ||||
| 
 | ||||
|     // Rotate around Y axis
 | ||||
|     osg::Quat yr(-f[1], osg::Vec3(0,1,0)); | ||||
| 
 | ||||
|     // Rotate around Z axis
 | ||||
|     osg::Quat zr(-f[2], osg::Vec3(0,0,1)); | ||||
| 
 | ||||
|     // Rotates first around z, then y, then x
 | ||||
|     if (ptr.getClass().isActor()) | ||||
|         insert->setAttitude(zr); | ||||
|     else | ||||
|         insert->setAttitude(zr*yr*xr); | ||||
| 
 | ||||
|     ptr.getRefData().setBaseNode(insert); | ||||
| } | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ | |||
| #include <osg/LightModel> | ||||
| #include <osg/Fog> | ||||
| #include <osg/Group> | ||||
| #include <osg/PositionAttitudeTransform> | ||||
| 
 | ||||
| #include <osgViewer/Viewer> | ||||
| 
 | ||||
|  | @ -211,6 +212,25 @@ namespace MWRender | |||
|         mSky->update(dt); | ||||
|     } | ||||
| 
 | ||||
|     void RenderingManager::rotateObject(const MWWorld::Ptr &ptr, const osg::Quat& rot) | ||||
|     { | ||||
|         //if(ptr.getRefData().getHandle() == mCamera->getHandle() &&
 | ||||
|         //   !mCamera->isVanityOrPreviewModeEnabled())
 | ||||
|         //    mCamera->rotateCamera(-rot, false);
 | ||||
| 
 | ||||
|         ptr.getRefData().getBaseNode()->setAttitude(rot); | ||||
|     } | ||||
| 
 | ||||
|     void RenderingManager::moveObject(const MWWorld::Ptr &ptr, const osg::Vec3f &pos) | ||||
|     { | ||||
|         ptr.getRefData().getBaseNode()->setPosition(pos); | ||||
|     } | ||||
| 
 | ||||
|     void RenderingManager::scaleObject(const MWWorld::Ptr &ptr, const osg::Vec3f &scale) | ||||
|     { | ||||
|         ptr.getRefData().getBaseNode()->setScale(scale); | ||||
|     } | ||||
| 
 | ||||
|     void RenderingManager::spawnEffect(const std::string &model, const std::string &texture, const osg::Vec3f &worldPosition, float scale) | ||||
|     { | ||||
|         mEffectManager->addEffect(model, texture, worldPosition, scale); | ||||
|  |  | |||
|  | @ -57,6 +57,11 @@ namespace MWRender | |||
| 
 | ||||
|         void removeCell(const MWWorld::CellStore* store); | ||||
| 
 | ||||
|         // TODO rename to setRotation/setPosition/setScale, along with the World equivalents
 | ||||
|         void rotateObject(const MWWorld::Ptr& ptr, const osg::Quat& rot); | ||||
|         void moveObject(const MWWorld::Ptr& ptr, const osg::Vec3f& pos); | ||||
|         void scaleObject(const MWWorld::Ptr& ptr, const osg::Vec3f& scale); | ||||
| 
 | ||||
|         void setSkyEnabled(bool enabled); | ||||
| 
 | ||||
|         SkyManager* getSkyManager(); | ||||
|  |  | |||
|  | @ -42,7 +42,7 @@ namespace | |||
|         //ptr.getClass().insertObject (ptr, model, physics);
 | ||||
|     } | ||||
| 
 | ||||
|     void updateObjectLocalRotation (const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, | ||||
|     void updateObjectLocalRotation (const MWWorld::Ptr& ptr, /*MWWorld::PhysicsSystem& physics,*/ | ||||
|                                     MWRender::RenderingManager& rendering) | ||||
|     { | ||||
|         if (ptr.getRefData().getBaseNode() != NULL) | ||||
|  | @ -60,7 +60,7 @@ namespace | |||
|             if (!ptr.getClass().isActor()) | ||||
|                 rot = rot * osg::Quat(y, osg::Vec3(0,-1,0)) * osg::Quat(x, osg::Vec3(-1,0,0)); | ||||
| 
 | ||||
|             ptr.getRefData().getBaseNode()->setAttitude(rot * worldRotQuat); | ||||
|             rendering.rotateObject(ptr, rot * worldRotQuat); | ||||
|             //physics.rotateObject(ptr);
 | ||||
|         } | ||||
|     } | ||||
|  | @ -102,12 +102,12 @@ namespace | |||
|             try | ||||
|             { | ||||
|                 addObject(ptr, /*mPhysics, */mRendering); | ||||
|                 //updateObjectLocalRotation(ptr, mPhysics, mRendering);
 | ||||
|                 updateObjectLocalRotation(ptr, /*mPhysics,*/ mRendering); | ||||
|                 if (ptr.getRefData().getBaseNode()) | ||||
|                 { | ||||
|                     float scale = ptr.getCellRef().getScale(); | ||||
|                     ptr.getClass().adjustScale(ptr, scale); | ||||
|                     //mRendering.scaleObject(ptr, Ogre::Vector3(scale));
 | ||||
|                     mRendering.scaleObject(ptr, osg::Vec3f(scale, scale, scale)); | ||||
|                 } | ||||
|                 ptr.getClass().adjustPosition (ptr, false); | ||||
|             } | ||||
|  | @ -130,16 +130,7 @@ namespace MWWorld | |||
| 
 | ||||
|     void Scene::updateObjectLocalRotation (const Ptr& ptr) | ||||
|     { | ||||
|         //::updateObjectLocalRotation(ptr, *mPhysics, mRendering);
 | ||||
|     } | ||||
| 
 | ||||
|     void Scene::updateObjectRotation (const Ptr& ptr) | ||||
|     { | ||||
|         if(ptr.getRefData().getBaseNodeOld() != 0) | ||||
|         { | ||||
|             //mRendering.rotateObject(ptr);
 | ||||
|             //mPhysics->rotateObject(ptr);
 | ||||
|         } | ||||
|         ::updateObjectLocalRotation(ptr, /* *mPhysics,*/ mRendering); | ||||
|     } | ||||
| 
 | ||||
|     void Scene::getGridCenter(int &cellX, int &cellY) | ||||
|  | @ -563,8 +554,8 @@ namespace MWWorld | |||
|         try | ||||
|         { | ||||
|             addObject(ptr, /* *mPhysics, */mRendering); | ||||
|             //MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true);
 | ||||
|             //MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().getScale());
 | ||||
|             MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true); | ||||
|             MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().getScale()); | ||||
|         } | ||||
|         catch (std::exception& e) | ||||
|         { | ||||
|  |  | |||
|  | @ -117,8 +117,6 @@ namespace MWWorld | |||
| 
 | ||||
|             void updateObjectLocalRotation (const Ptr& ptr); | ||||
| 
 | ||||
|             void updateObjectRotation (const Ptr& ptr); | ||||
| 
 | ||||
|             bool isCellActive(const CellStore &cell); | ||||
| 
 | ||||
|             Ptr searchPtrViaHandle (const std::string& handle); | ||||
|  |  | |||
|  | @ -1217,9 +1217,9 @@ namespace MWWorld | |||
|                 ptr.getRefData().setCount(0); | ||||
|             } | ||||
|         } | ||||
|         if (haveToMove && ptr.getRefData().getBaseNodeOld()) | ||||
|         if (haveToMove && ptr.getRefData().getBaseNode()) | ||||
|         { | ||||
|             //mRendering->moveObject(ptr, vec);
 | ||||
|             mRendering->moveObject(ptr, osg::Vec3f(vec.x, vec.y, vec.z)); | ||||
|             //mPhysics->moveObject (ptr);
 | ||||
|         } | ||||
|         if (isPlayer) | ||||
|  | @ -1256,9 +1256,9 @@ namespace MWWorld | |||
|         ptr.getCellRef().setScale(scale); | ||||
|         ptr.getClass().adjustScale(ptr,scale); | ||||
| 
 | ||||
|         if(ptr.getRefData().getBaseNodeOld() == 0) | ||||
|         if(ptr.getRefData().getBaseNode() == 0) | ||||
|             return; | ||||
|         //mRendering->scaleObject(ptr, Vector3(scale,scale,scale));
 | ||||
|         mRendering->scaleObject(ptr, osg::Vec3f(scale,scale,scale)); | ||||
|         //mPhysics->scaleObject(ptr);
 | ||||
|     } | ||||
| 
 | ||||
|  | @ -1307,13 +1307,10 @@ namespace MWWorld | |||
| 
 | ||||
|         ptr.getRefData().setPosition(pos); | ||||
| 
 | ||||
|         if(ptr.getRefData().getBaseNodeOld() == 0) | ||||
|         if(ptr.getRefData().getBaseNode() == 0) | ||||
|             return; | ||||
| 
 | ||||
|         if (ptr.getClass().isActor()) | ||||
|             mWorldScene->updateObjectRotation(ptr); | ||||
|         else | ||||
|             mWorldScene->updateObjectLocalRotation(ptr); | ||||
|         mWorldScene->updateObjectLocalRotation(ptr); | ||||
|     } | ||||
| 
 | ||||
|     void World::localRotateObject (const Ptr& ptr, float x, float y, float z) | ||||
|  | @ -1329,7 +1326,7 @@ namespace MWWorld | |||
| 
 | ||||
|         ptr.getRefData().setLocalRotation(rot); | ||||
| 
 | ||||
|         if (ptr.getRefData().getBaseNodeOld() != 0) | ||||
|         if (ptr.getRefData().getBaseNode() != 0) | ||||
|         { | ||||
|             mWorldScene->updateObjectLocalRotation(ptr); | ||||
|         } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue