rotateObject, scaleObject

This commit is contained in:
scrawl 2015-04-23 23:50:46 +02:00
parent 6f3e920f85
commit 1c0e3a6488
6 changed files with 39 additions and 47 deletions

View file

@ -102,25 +102,6 @@ void Objects::insertBegin(const MWWorld::Ptr& ptr)
const float *f = ptr.getRefData().getPosition().pos; const float *f = ptr.getRefData().getPosition().pos;
insert->setPosition(osg::Vec3(f[0], f[1], f[2])); 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); ptr.getRefData().setBaseNode(insert);
} }

View file

@ -7,6 +7,7 @@
#include <osg/LightModel> #include <osg/LightModel>
#include <osg/Fog> #include <osg/Fog>
#include <osg/Group> #include <osg/Group>
#include <osg/PositionAttitudeTransform>
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
@ -211,6 +212,25 @@ namespace MWRender
mSky->update(dt); 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) void RenderingManager::spawnEffect(const std::string &model, const std::string &texture, const osg::Vec3f &worldPosition, float scale)
{ {
mEffectManager->addEffect(model, texture, worldPosition, scale); mEffectManager->addEffect(model, texture, worldPosition, scale);

View file

@ -57,6 +57,11 @@ namespace MWRender
void removeCell(const MWWorld::CellStore* store); 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); void setSkyEnabled(bool enabled);
SkyManager* getSkyManager(); SkyManager* getSkyManager();

View file

@ -42,7 +42,7 @@ namespace
//ptr.getClass().insertObject (ptr, model, physics); //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) MWRender::RenderingManager& rendering)
{ {
if (ptr.getRefData().getBaseNode() != NULL) if (ptr.getRefData().getBaseNode() != NULL)
@ -60,7 +60,7 @@ namespace
if (!ptr.getClass().isActor()) if (!ptr.getClass().isActor())
rot = rot * osg::Quat(y, osg::Vec3(0,-1,0)) * osg::Quat(x, osg::Vec3(-1,0,0)); 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); //physics.rotateObject(ptr);
} }
} }
@ -102,12 +102,12 @@ namespace
try try
{ {
addObject(ptr, /*mPhysics, */mRendering); addObject(ptr, /*mPhysics, */mRendering);
//updateObjectLocalRotation(ptr, mPhysics, mRendering); updateObjectLocalRotation(ptr, /*mPhysics,*/ mRendering);
if (ptr.getRefData().getBaseNode()) if (ptr.getRefData().getBaseNode())
{ {
float scale = ptr.getCellRef().getScale(); float scale = ptr.getCellRef().getScale();
ptr.getClass().adjustScale(ptr, scale); ptr.getClass().adjustScale(ptr, scale);
//mRendering.scaleObject(ptr, Ogre::Vector3(scale)); mRendering.scaleObject(ptr, osg::Vec3f(scale, scale, scale));
} }
ptr.getClass().adjustPosition (ptr, false); ptr.getClass().adjustPosition (ptr, false);
} }
@ -130,16 +130,7 @@ namespace MWWorld
void Scene::updateObjectLocalRotation (const Ptr& ptr) void Scene::updateObjectLocalRotation (const Ptr& ptr)
{ {
//::updateObjectLocalRotation(ptr, *mPhysics, mRendering); ::updateObjectLocalRotation(ptr, /* *mPhysics,*/ mRendering);
}
void Scene::updateObjectRotation (const Ptr& ptr)
{
if(ptr.getRefData().getBaseNodeOld() != 0)
{
//mRendering.rotateObject(ptr);
//mPhysics->rotateObject(ptr);
}
} }
void Scene::getGridCenter(int &cellX, int &cellY) void Scene::getGridCenter(int &cellX, int &cellY)
@ -563,8 +554,8 @@ namespace MWWorld
try try
{ {
addObject(ptr, /* *mPhysics, */mRendering); addObject(ptr, /* *mPhysics, */mRendering);
//MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true); MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true);
//MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().getScale()); MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().getScale());
} }
catch (std::exception& e) catch (std::exception& e)
{ {

View file

@ -117,8 +117,6 @@ namespace MWWorld
void updateObjectLocalRotation (const Ptr& ptr); void updateObjectLocalRotation (const Ptr& ptr);
void updateObjectRotation (const Ptr& ptr);
bool isCellActive(const CellStore &cell); bool isCellActive(const CellStore &cell);
Ptr searchPtrViaHandle (const std::string& handle); Ptr searchPtrViaHandle (const std::string& handle);

View file

@ -1217,9 +1217,9 @@ namespace MWWorld
ptr.getRefData().setCount(0); 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); //mPhysics->moveObject (ptr);
} }
if (isPlayer) if (isPlayer)
@ -1256,9 +1256,9 @@ namespace MWWorld
ptr.getCellRef().setScale(scale); ptr.getCellRef().setScale(scale);
ptr.getClass().adjustScale(ptr,scale); ptr.getClass().adjustScale(ptr,scale);
if(ptr.getRefData().getBaseNodeOld() == 0) if(ptr.getRefData().getBaseNode() == 0)
return; return;
//mRendering->scaleObject(ptr, Vector3(scale,scale,scale)); mRendering->scaleObject(ptr, osg::Vec3f(scale,scale,scale));
//mPhysics->scaleObject(ptr); //mPhysics->scaleObject(ptr);
} }
@ -1307,12 +1307,9 @@ namespace MWWorld
ptr.getRefData().setPosition(pos); ptr.getRefData().setPosition(pos);
if(ptr.getRefData().getBaseNodeOld() == 0) if(ptr.getRefData().getBaseNode() == 0)
return; return;
if (ptr.getClass().isActor())
mWorldScene->updateObjectRotation(ptr);
else
mWorldScene->updateObjectLocalRotation(ptr); mWorldScene->updateObjectLocalRotation(ptr);
} }
@ -1329,7 +1326,7 @@ namespace MWWorld
ptr.getRefData().setLocalRotation(rot); ptr.getRefData().setLocalRotation(rot);
if (ptr.getRefData().getBaseNodeOld() != 0) if (ptr.getRefData().getBaseNode() != 0)
{ {
mWorldScene->updateObjectLocalRotation(ptr); mWorldScene->updateObjectLocalRotation(ptr);
} }