Remove last remains of Ogre math

c++11
scrawl 10 years ago
parent 364b785e8f
commit b70383d127

@ -1797,7 +1797,7 @@ void CharacterController::update(float duration)
if (mMovementState == CharState_TurnLeft || mMovementState == CharState_TurnRight)
{
if (duration > 0)
mAnimation->adjustSpeedMult(mCurrentMovement, std::min(1.5f, std::abs(rot.z()) / duration / Ogre::Math::PI));
mAnimation->adjustSpeedMult(mCurrentMovement, std::min(1.5f, std::abs(rot.z()) / duration / static_cast<float>(osg::PI)));
}
if (!mSkipAnim)

@ -31,10 +31,10 @@ namespace
float getFightDistanceBias(const MWWorld::Ptr& actor1, const MWWorld::Ptr& actor2)
{
Ogre::Vector3 pos1 (actor1.getRefData().getPosition().pos);
Ogre::Vector3 pos2 (actor2.getRefData().getPosition().pos);
osg::Vec3f pos1 (actor1.getRefData().getPosition().asVec3());
osg::Vec3f pos2 (actor2.getRefData().getPosition().asVec3());
float d = pos1.distance(pos2);
float d = (pos1 - pos2).length();
static const int iFightDistanceBase = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
"iFightDistanceBase")->getInt();

@ -37,7 +37,7 @@ namespace MWMechanics
MWWorld::CellRefList<ESM::Door>& doors = cell->get<ESM::Door>();
MWWorld::CellRefList<ESM::Door>::List& refList = doors.mList;
MWWorld::CellRefList<ESM::Door>::List::iterator it = refList.begin();
Ogre::Vector3 pos(actor.getRefData().getPosition().pos);
osg::Vec3f pos(actor.getRefData().getPosition().asVec3());
/// TODO: How to check whether the actor is facing a door? Below code is for
/// the player, perhaps it can be adapted.
@ -50,7 +50,7 @@ namespace MWMechanics
for (; it != refList.end(); ++it)
{
MWWorld::LiveCellRef<ESM::Door>& ref = *it;
if(pos.squaredDistance(Ogre::Vector3(ref.mData.getPosition().pos)) < minSqr)
if((pos - ref.mData.getPosition().asVec3()).length2() < minSqr)
if((closed && ref.mData.getLocalRotation().rot[2] == 0) ||
(!closed && ref.mData.getLocalRotation().rot[2] >= 1))
{

@ -22,9 +22,9 @@ namespace MWMechanics
public:
PathFinder();
static float sgn(Ogre::Radian a)
static float sgn(float val)
{
if(a.valueRadians() > 0)
if(val > 0)
return 1.0;
return -1.0;
}
@ -77,12 +77,6 @@ namespace MWMechanics
mPath.push_back(point);
}
/// utility function to convert a Ogre::Vector3 to a Pathgrid::Point
static ESM::Pathgrid::Point MakePathgridPoint(const Ogre::Vector3& v)
{
return ESM::Pathgrid::Point(static_cast<int>(v[0]), static_cast<int>(v[1]), static_cast<int>(v[2]));
}
/// utility function to convert a osg::Vec3f to a Pathgrid::Point
static ESM::Pathgrid::Point MakePathgridPoint(const osg::Vec3f& v)
{
@ -100,12 +94,6 @@ namespace MWMechanics
return osg::Vec3f(static_cast<float>(p.mX), static_cast<float>(p.mY), static_cast<float>(p.mZ));
}
/// utility function to convert a Pathgrid::Point to a Ogre::Vector3
static Ogre::Vector3 MakeOgreVector3(const ESM::Pathgrid::Point& p)
{
return Ogre::Vector3(static_cast<Ogre::Real>(p.mX), static_cast<Ogre::Real>(p.mY), static_cast<Ogre::Real>(p.mZ));
}
private:
bool mIsPathConstructed;

@ -115,13 +115,14 @@ namespace MWMechanics
if (!found)
{
ESM::Position ipos = mActor.getRefData().getPosition();
Ogre::Vector3 pos(ipos.pos);
Ogre::Quaternion rot(Ogre::Radian(-ipos.rot[2]), Ogre::Vector3::UNIT_Z);
osg::Vec3f pos(ipos.asVec3());
osg::Quat rot (-ipos.rot[2], osg::Vec3f(0,0,1));
const float distance = 50;
pos = pos + distance*rot.yAxis();
ipos.pos[0] = pos.x;
ipos.pos[1] = pos.y;
ipos.pos[2] = pos.z;
pos = pos + (rot * osg::Vec3f(0,1,0)) * distance;
ipos.pos[0] = pos.x();
ipos.pos[1] = pos.y();
ipos.pos[2] = pos.z();
ipos.rot[0] = 0;
ipos.rot[1] = 0;
ipos.rot[2] = 0;

@ -1062,26 +1062,4 @@ void NpcAnimation::updatePtr(const MWWorld::Ptr &updated)
mHeadAnimationTime->updatePtr(updated);
}
/*
void NpcAnimation::setHeadPitch(Ogre::Radian pitch)
{
mHeadPitch = pitch;
}
void NpcAnimation::setHeadYaw(Ogre::Radian yaw)
{
mHeadYaw = yaw;
}
Ogre::Radian NpcAnimation::getHeadPitch() const
{
return mHeadPitch;
}
Ogre::Radian NpcAnimation::getHeadYaw() const
{
return mHeadYaw;
}
*/
}

@ -120,8 +120,6 @@ private:
void addPartGroup(int group, int priority, const std::vector<ESM::PartReference> &parts,
bool enchantedGlow=false, osg::Vec4f* glowColor=NULL);
//void applyAlpha(float alpha, Ogre::Entity* ent, NifOgre::ObjectScenePtr scene);
osg::ref_ptr<NeckController> mFirstPersonNeckController;
osg::ref_ptr<RotateController> mHeadController;
@ -171,19 +169,12 @@ public:
virtual Resource::ResourceSystem* getResourceSystem();
// WeaponAnimation
//virtual NifOgre::ObjectScenePtr getWeapon() { return mObjectParts[ESM::PRT_Weapon]; }
virtual void showWeapon(bool show) { showWeapons(show); }
//virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot);
void setViewMode(ViewMode viewMode);
void updateParts();
/// \brief Applies a translation to the arms and hands.
/// This may be called multiple times before the animation
/// is updated to add additional offsets.
//void addFirstPersonOffset(const Ogre::Vector3 &offset);
/// Rebuilds the NPC, updating their root model, animation sources, and equipment.
void rebuild();

@ -56,16 +56,11 @@ namespace MWRender
virtual osg::Node* getWeaponNode() = 0;
virtual Resource::ResourceSystem* getResourceSystem() = 0;
//virtual NifOgre::ObjectScenePtr getWeapon() = 0;
virtual void showWeapon(bool show) = 0;
//virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot) = 0;
/// A relative factor (0-1) that decides if and how much the skeleton should be pitched
/// to indicate the facing orientation of the character, for ranged weapon aiming.
float mPitchFactor;
//void pitchSkeleton(float xrot, Ogre::SkeletonInstance* skel);
};
}

@ -1045,8 +1045,8 @@ namespace MWScript
msg << "Cell: " << MWBase::Environment::get().getWorld()->getCellName(cell) << std::endl;
if (cell->getCell()->isExterior())
msg << "Grid: " << cell->getCell()->getGridX() << " " << cell->getCell()->getGridY() << std::endl;
Ogre::Vector3 pos (ptr.getRefData().getPosition().pos);
msg << "Coordinates: " << pos << std::endl;
osg::Vec3f pos (ptr.getRefData().getPosition().asVec3());
msg << "Coordinates: " << pos.x() << " " << pos.y() << " " << pos.z() << std::endl;
msg << "Model: " << ptr.getClass().getModel(ptr) << std::endl;
if (!ptr.getClass().getScript(ptr).empty())
msg << "Script: " << ptr.getClass().getScript(ptr) << std::endl;

@ -84,9 +84,9 @@ namespace MWScript
Interpreter::Type_Float angle = runtime[0].mFloat;
runtime.pop();
float ax = Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees();
float ay = Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees();
float az = Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees();
float ax = osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[0]);
float ay = osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[1]);
float az = osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[2]);
MWWorld::LocalRotation localRot = ptr.getRefData().getLocalRotation();
@ -127,15 +127,15 @@ namespace MWScript
if (axis == "x")
{
runtime.push(Ogre::Radian(ptr.getCellRef().getPosition().rot[0]).valueDegrees());
runtime.push(osg::RadiansToDegrees(ptr.getCellRef().getPosition().rot[0]));
}
else if (axis == "y")
{
runtime.push(Ogre::Radian(ptr.getCellRef().getPosition().rot[1]).valueDegrees());
runtime.push(osg::RadiansToDegrees(ptr.getCellRef().getPosition().rot[1]));
}
else if (axis == "z")
{
runtime.push(Ogre::Radian(ptr.getCellRef().getPosition().rot[2]).valueDegrees());
runtime.push(osg::RadiansToDegrees(ptr.getCellRef().getPosition().rot[2]));
}
else
throw std::runtime_error ("invalid rotation axis: " + axis);
@ -156,15 +156,15 @@ namespace MWScript
if (axis=="x")
{
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees());
runtime.push(osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[0]));
}
else if (axis=="y")
{
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees());
runtime.push(osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[1]));
}
else if (axis=="z")
{
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees());
runtime.push(osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[2]));
}
else
throw std::runtime_error ("invalid rotation axis: " + axis);
@ -326,8 +326,8 @@ namespace MWScript
ptr = MWWorld::Ptr(ptr.getBase(), store);
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(ptr);
float ax = Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees();
float ay = Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees();
float ax = osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[0]);
float ay = osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[1]);
// Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200)
// except for when you position the player, then degrees must be used.
// See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference.
@ -382,8 +382,8 @@ namespace MWScript
}
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(ptr);
float ax = Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees();
float ay = Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees();
float ax = osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[0]);
float ay = osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[1]);
// Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200)
// except for when you position the player, then degrees must be used.
// See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference.
@ -567,9 +567,9 @@ namespace MWScript
Interpreter::Type_Float rotation = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
runtime.pop();
float ax = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[0]).valueDegrees();
float ay = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[1]).valueDegrees();
float az = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[2]).valueDegrees();
float ax = osg::RadiansToDegrees(ptr.getRefData().getLocalRotation().rot[0]);
float ay = osg::RadiansToDegrees(ptr.getRefData().getLocalRotation().rot[1]);
float az = osg::RadiansToDegrees(ptr.getRefData().getLocalRotation().rot[2]);
if (axis == "x")
{
@ -604,9 +604,9 @@ namespace MWScript
const 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();
float ax = osg::RadiansToDegrees(objRot[0]);
float ay = osg::RadiansToDegrees(objRot[1]);
float az = osg::RadiansToDegrees(objRot[2]);
if (axis == "x")
{

@ -40,8 +40,7 @@ namespace MWWorld
for(std::set<MWWorld::Ptr>::iterator it = followers.begin();it != followers.end();++it)
{
MWWorld::Ptr follower = *it;
if (Ogre::Vector3(follower.getRefData().getPosition().pos).squaredDistance(
Ogre::Vector3( actor.getRefData().getPosition().pos))
if ((follower.getRefData().getPosition().asVec3() - actor.getRefData().getPosition().asVec3()).length2()
<= 800*800)
teleport(*it);
}

@ -418,9 +418,9 @@ namespace MWWorld
if (adjustPlayerPos) {
world->moveObject(player, pos.pos[0], pos.pos[1], pos.pos[2]);
float x = Ogre::Radian(pos.rot[0]).valueDegrees();
float y = Ogre::Radian(pos.rot[1]).valueDegrees();
float z = Ogre::Radian(pos.rot[2]).valueDegrees();
float x = osg::RadiansToDegrees(pos.rot[0]);
float y = osg::RadiansToDegrees(pos.rot[1]);
float z = osg::RadiansToDegrees(pos.rot[2]);
world->rotateObject(player, x, y, z);
player.getClass().adjustPosition(player, true);
@ -475,9 +475,9 @@ namespace MWWorld
MWBase::World *world = MWBase::Environment::get().getWorld();
world->moveObject(world->getPlayerPtr(), position.pos[0], position.pos[1], position.pos[2]);
float x = Ogre::Radian(position.rot[0]).valueDegrees();
float y = Ogre::Radian(position.rot[1]).valueDegrees();
float z = Ogre::Radian(position.rot[2]).valueDegrees();
float x = osg::RadiansToDegrees(position.rot[0]);
float y = osg::RadiansToDegrees(position.rot[1]);
float z = osg::RadiansToDegrees(position.rot[2]);
world->rotateObject(world->getPlayerPtr(), x, y, z);
world->getPlayerPtr().getClass().adjustPosition(world->getPlayerPtr(), true);

@ -66,10 +66,11 @@ namespace
// Wraps a value to (-PI, PI]
void wrap(float& rad)
{
const float pi = static_cast<float>(osg::PI);
if (rad>0)
rad = std::fmod(rad+Ogre::Math::PI, 2.0f*Ogre::Math::PI)-Ogre::Math::PI;
rad = std::fmod(rad+pi, 2.0f*pi)-pi;
else
rad = std::fmod(rad-Ogre::Math::PI, 2.0f*Ogre::Math::PI)+Ogre::Math::PI;
rad = std::fmod(rad-pi, 2.0f*pi)+pi;
}
}
@ -1220,24 +1221,24 @@ namespace MWWorld
mWorldScene->updateObjectScale(ptr);
}
void World::rotateObjectImp (const Ptr& ptr, Ogre::Vector3 rot, bool adjust)
void World::rotateObjectImp (const Ptr& ptr, const osg::Vec3f& rot, bool adjust)
{
const float two_pi = Ogre::Math::TWO_PI;
const float pi = Ogre::Math::PI;
const float pi = static_cast<float>(osg::PI);
const float two_pi = pi*2.f;
ESM::Position pos = ptr.getRefData().getPosition();
float *objRot = pos.rot;
if(adjust)
{
objRot[0] += rot.x;
objRot[1] += rot.y;
objRot[2] += rot.z;
objRot[0] += rot.x();
objRot[1] += rot.y();
objRot[2] += rot.z();
}
else
{
objRot[0] = rot.x;
objRot[1] = rot.y;
objRot[2] = rot.z;
objRot[0] = rot.x();
objRot[1] = rot.y();
objRot[2] = rot.z();
}
if(ptr.getClass().isActor())
@ -1246,7 +1247,7 @@ namespace MWWorld
* currently it's done so for rotating the camera, which needs
* clamping.
*/
const float half_pi = Ogre::Math::HALF_PI;
const float half_pi = pi/2.f;
if(objRot[0] < -half_pi) objRot[0] = -half_pi;
else if(objRot[0] > half_pi) objRot[0] = half_pi;
@ -1272,9 +1273,9 @@ namespace MWWorld
void World::localRotateObject (const Ptr& ptr, float x, float y, float z)
{
LocalRotation rot = ptr.getRefData().getLocalRotation();
rot.rot[0]=Ogre::Degree(x).valueRadians();
rot.rot[1]=Ogre::Degree(y).valueRadians();
rot.rot[2]=Ogre::Degree(z).valueRadians();
rot.rot[0]=osg::DegreesToRadians(x);
rot.rot[1]=osg::DegreesToRadians(y);
rot.rot[2]=osg::DegreesToRadians(z);
wrap(rot.rot[0]);
wrap(rot.rot[1]);
@ -1332,9 +1333,9 @@ namespace MWWorld
void World::rotateObject (const Ptr& ptr,float x,float y,float z, bool adjust)
{
rotateObjectImp(ptr, Ogre::Vector3(Ogre::Degree(x).valueRadians(),
Ogre::Degree(y).valueRadians(),
Ogre::Degree(z).valueRadians()),
rotateObjectImp(ptr, osg::Vec3f(osg::DegreesToRadians(x),
osg::DegreesToRadians(y),
osg::DegreesToRadians(z)),
adjust);
}
@ -2904,8 +2905,7 @@ namespace MWWorld
World::DetectionType mType;
bool operator() (MWWorld::Ptr ptr)
{
if (Ogre::Vector3(ptr.getRefData().getPosition().pos).squaredDistance(
Ogre::Vector3(mDetector.getRefData().getPosition().pos)) >= mSquaredDist)
if ((ptr.getRefData().getPosition().asVec3() - mDetector.getRefData().getPosition().asVec3()).length2() >= mSquaredDist)
return true;
if (!ptr.getRefData().isEnabled() || ptr.getRefData().isDeleted())
@ -3096,13 +3096,13 @@ namespace MWWorld
return;
ESM::Position ipos = mPlayer->getPlayer().getRefData().getPosition();
Ogre::Vector3 pos(ipos.pos);
Ogre::Quaternion rot(Ogre::Radian(-ipos.rot[2]), Ogre::Vector3::UNIT_Z);
osg::Vec3f pos(ipos.asVec3());
osg::Quat rot(-ipos.rot[2], osg::Vec3f(0,0,1));
const float distance = 50;
pos = pos + distance*rot.yAxis();
ipos.pos[0] = pos.x;
ipos.pos[1] = pos.y;
ipos.pos[2] = pos.z;
pos = pos + (rot * osg::Vec3f(0,1,0)) * distance;
ipos.pos[0] = pos.x();
ipos.pos[1] = pos.y();
ipos.pos[2] = pos.z();
ipos.rot[0] = 0;
ipos.rot[1] = 0;
ipos.rot[2] = 0;

@ -111,7 +111,7 @@ namespace MWWorld
void updateWeather(float duration, bool paused = false);
int getDaysPerMonth (int month) const;
void rotateObjectImp (const Ptr& ptr, Ogre::Vector3 rot, bool adjust);
void rotateObjectImp (const Ptr& ptr, const osg::Vec3f& rot, bool adjust);
Ptr moveObjectImp (const Ptr& ptr, float x, float y, float z);
///< @return an updated Ptr in case the Ptr's cell changes

@ -17,13 +17,7 @@ struct Quaternion
float mValues[4];
Quaternion() {}
Quaternion (Ogre::Quaternion q)
{
mValues[0] = q.w;
mValues[1] = q.x;
mValues[2] = q.y;
mValues[3] = q.z;
}
Quaternion(const osg::Quat& q)
{
mValues[0] = q.w();
@ -32,11 +26,6 @@ struct Quaternion
mValues[3] = q.z();
}
operator Ogre::Quaternion () const
{
return Ogre::Quaternion(mValues[0], mValues[1], mValues[2], mValues[3]);
}
operator osg::Quat () const
{
return osg::Quat(mValues[1], mValues[2], mValues[3], mValues[0]);
@ -48,12 +37,7 @@ struct Vector3
float mValues[3];
Vector3() {}
Vector3 (Ogre::Vector3 v)
{
mValues[0] = v.x;
mValues[1] = v.y;
mValues[2] = v.z;
}
Vector3(const osg::Vec3f& v)
{
mValues[0] = v.x();
@ -61,11 +45,6 @@ struct Vector3
mValues[2] = v.z();
}
operator Ogre::Vector3 () const
{
return Ogre::Vector3(&mValues[0]);
}
operator osg::Vec3f () const
{
return osg::Vec3f(mValues[0], mValues[1], mValues[2]);

Loading…
Cancel
Save