1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 18:19:55 +00:00

Make thrown projectiles rotate

This commit is contained in:
Miloslav Číž 2017-11-23 00:32:22 +01:00
parent 36f4f0ef85
commit de42aa9d03
2 changed files with 18 additions and 1 deletions

View file

@ -316,6 +316,8 @@ namespace MWWorld
state.mIdArrow = projectile.getCellRef().getRefId();
state.mCasterHandle = actor;
state.mAttackStrength = attackStrength;
state.mThrown = projectile.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanThrown;
state.mTime = 0.0;
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), projectile.getCellRef().getRefId());
MWWorld::Ptr ptr = ref.getPtr();
@ -453,12 +455,25 @@ namespace MWWorld
// gravity constant - must be way lower than the gravity affecting actors, since we're not
// simulating aerodynamics at all
it->mVelocity -= osg::Vec3f(0, 0, 627.2f * 0.1f) * duration;
it->mTime += duration;
osg::Vec3f pos(it->mNode->getPosition());
osg::Vec3f newPos = pos + it->mVelocity * duration;
osg::Quat orient;
orient.makeRotate(osg::Vec3f(0,1,0), it->mVelocity);
orient.set(
osg::Matrixd::rotate(it->mThrown ? -1 * it->mTime : 0.0,osg::Vec3f(0,0,1)) *
osg::Matrixd::rotate(osg::PI / 2.0,osg::Vec3f(0,1,0)) *
osg::Matrixd::rotate(-1 * osg::PI / 2.0,osg::Vec3f(1,0,0)) *
osg::Matrixd::inverse(
osg::Matrixd::lookAt(
osg::Vec3f(0,0,0),
it->mVelocity,
osg::Vec3f(0,0,1))
)
);
it->mNode->setAttitude(orient);
it->mNode->setPosition(newPos);

View file

@ -112,6 +112,8 @@ namespace MWWorld
osg::Vec3f mVelocity;
float mAttackStrength;
float mTime;
bool mThrown;
};
std::vector<MagicBoltState> mMagicBolts;