smoothed gun motion

This commit is contained in:
ottona 2018-11-14 13:34:08 +01:00
parent fa1a095cde
commit 3b2da3b022
2 changed files with 9 additions and 2 deletions

View File

@ -7,6 +7,8 @@ using namespace irr;
using namespace irr::core; using namespace irr::core;
FireUnit::FireUnit() FireUnit::FireUnit()
: aziTurnCoeffSmooth(0.f)
, elevTurnCoeffSmooth(0.f)
{ {
turretAzimuth = Globals::getSceneManager()->addEmptySceneNode(); turretAzimuth = Globals::getSceneManager()->addEmptySceneNode();
turretElevation = Globals::getSceneManager()->addMeshSceneNode(Globals::getSceneManager()->getMesh("../res/guns.obj"), turretAzimuth); turretElevation = Globals::getSceneManager()->addMeshSceneNode(Globals::getSceneManager()->getMesh("../res/guns.obj"), turretAzimuth);
@ -72,8 +74,11 @@ bool FireUnit::OnEvent(const SEvent& e)
// sec trigger released // sec trigger released
} }
aziTurnCoeffSmooth = aziTurnCoeffSmooth * .95f + aziTurnCoeff * .05f;
elevTurnCoeffSmooth = elevTurnCoeffSmooth * .95f + elevTurnCoeff * .05f;
vector3df rot = turretAzimuth->getRotation(); vector3df rot = turretAzimuth->getRotation();
rot.Y -= 1.f * aziTurnCoeff; rot.Y -= 1.f * aziTurnCoeffSmooth;
if (rot.Y > 360.f) if (rot.Y > 360.f)
rot.Y -= 360.f; rot.Y -= 360.f;
@ -83,7 +88,7 @@ bool FireUnit::OnEvent(const SEvent& e)
turretAzimuth->setRotation(rot); turretAzimuth->setRotation(rot);
rot = turretElevation->getRotation(); rot = turretElevation->getRotation();
rot.X += 1.f * elevTurnCoeff; rot.X += 1.f * elevTurnCoeffSmooth;
if (rot.X > 5.f) if (rot.X > 5.f)
rot.X = 5.f; rot.X = 5.f;

View File

@ -15,6 +15,8 @@ private:
irr::scene::ICameraSceneNode *cam; irr::scene::ICameraSceneNode *cam;
irr::scene::ISceneNode *turretElevation, *turretAzimuth; irr::scene::ISceneNode *turretElevation, *turretAzimuth;
irr::scene::ISceneNodeAnimator *turretCamAnimator; irr::scene::ISceneNodeAnimator *turretCamAnimator;
irr::f32 aziTurnCoeffSmooth, elevTurnCoeffSmooth;
}; };
#endif // FIREUNIT_HPP #endif // FIREUNIT_HPP