Implement Face instruction (Feature #1424)
parent
6f376bd499
commit
dc0bc5b68c
@ -0,0 +1,31 @@
|
||||
#include "aiface.hpp"
|
||||
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "steering.hpp"
|
||||
|
||||
MWMechanics::AiFace::AiFace(float targetX, float targetY)
|
||||
: mTargetX(targetX), mTargetY(targetY)
|
||||
{
|
||||
}
|
||||
|
||||
MWMechanics::AiPackage *MWMechanics::AiFace::clone() const
|
||||
{
|
||||
return new AiFace(*this);
|
||||
}
|
||||
|
||||
bool MWMechanics::AiFace::execute(const MWWorld::Ptr& actor, MWMechanics::CharacterController& /*characterController*/, MWMechanics::AiState& /*state*/, float /*duration*/)
|
||||
{
|
||||
osg::Vec3f dir = osg::Vec3f(mTargetX, mTargetY, 0) - actor.getRefData().getPosition().asVec3();
|
||||
return zTurn(actor, std::atan2(dir.x(), dir.y()), osg::DegreesToRadians(3.f));
|
||||
}
|
||||
|
||||
int MWMechanics::AiFace::getTypeId() const
|
||||
{
|
||||
return AiPackage::TypeIdFace;
|
||||
}
|
||||
|
||||
unsigned int MWMechanics::AiFace::getPriority() const
|
||||
{
|
||||
return 2;
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef GAME_MWMECHANICS_AIFACE_H
|
||||
#define GAME_MWMECHANICS_AIFACE_H
|
||||
|
||||
#include "aipackage.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
/// AiPackage which makes an actor face a certain direction.
|
||||
class AiFace : public AiPackage {
|
||||
public:
|
||||
AiFace(float targetX, float targetY);
|
||||
|
||||
virtual AiPackage *clone() const;
|
||||
|
||||
virtual bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration);
|
||||
|
||||
virtual int getTypeId() const;
|
||||
|
||||
virtual unsigned int getPriority() const;
|
||||
|
||||
virtual bool canCancel() const { return false; }
|
||||
virtual bool shouldCancelPreviousAi() const { return false; }
|
||||
|
||||
private:
|
||||
float mTargetX, mTargetY;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue