#pragma once #include #include // fastNormalize #include // perpendicular #include "BasicEntity.h" #include #include #include #include /** * @class MovingEntity * @brief Child of BasicEntity class. Has methods for moving * an entity around a world. Is dumb and does not know how to move. * Code is based on the textbook: * "Programming game AI by Example" by Matt Buckland * * @author Michael John * @version 1.00 * @date 21/08/2021 * * * @todo rotate heading to target doesnt work correctly * @todo test all functions * * @bug */ class MovingEntity : public BasicEntity { public: /** * Constructor * @param position BasicEntity position * @param scale BasicEntity position * @param boundRadius BasicEntity position * @param heading Normalised heading vector * @param velocity Current velocity * @param mass Entity mass used for acceleration calcs * @param maxSpeed Max velocity of entity * @param maxForce Max Force of Entity * @param maxTurnRate Max turn speed */ MovingEntity(glm::vec2 position, glm::vec2 scale, float boundRadius, glm::vec2 heading, glm::vec2 velocity, float mass, float maxSpeed, float maxForce, float maxTurnRate) : BasicEntity(0, position, scale, boundRadius), m_VelocityVec(velocity), m_HeadingVec(heading), m_mass(mass), m_MaxSpeed(maxSpeed), m_MaxForce(maxForce), m_MaxTurnRate(maxTurnRate) { ; } virtual ~MovingEntity() = default; /** * Gets velocity vector * @return glm::vec2 velocity vector */ glm::vec2 getVelocityVec() const; /** * Sets velocity vector * @param velocity glm::vec2 velocity vector */ void setVelocityVec(const glm::vec2 velocity); /** * Gets normalised heading vector * @return glm::vec2 heading vector */ glm::vec2 getHeadingVec() const; /** * Sets heading vector. Will normalise if length > 1 * @param heading glm::vec2 heading vector */ void setHeadingVec(const glm::vec2 heading); /** * Calculates perpendicular right normalised vector to the heading vector * @return glm::vec2 normalised right vector */ glm::vec2 getSideVec() const; /** * Gets mass of entity * @return float Entities mass */ float getMass() const; /** * Sets entities mass * @param mass float mass of entity */ void setMass(const float mass); /** * Gets max speed * @return float maxspeed of entity */ float getMaxSpeed() const; /** * Sets the entities max speed * @param speed float max speed of entity */ void setMaxSpeed(const float speed); /** * Gets Max force of entity for acceleration calcs * @return float max force */ float getMaxForce() const; /** * Sets max force for acceleration calcs * @param force float max force */ void setMaxForce(const float force); /** * Gets max turn rate of Entity * @return float number of degrees entity can turn per frame */ float getMaxTurnRate() const; /** * Sets max turn rate * Set to number of degrees the entity can turn per frame * @param turn float max degrees that can be turned a frame */ void setMaxTurnRate(const float turn); /** * Gets the entities current speed * @return float entities speed */ float getSpeed(); /** * Rotates max amount of turn to the target * @param target vector to turn to * @return true if facing target */ bool rotateHeadingToTarget(glm::vec2 target); protected: glm::vec2 m_VelocityVec; glm::vec2 m_HeadingVec; glm::vec2 m_Perpendicular; float m_mass; float m_MaxSpeed; float m_MaxForce; float m_MaxTurnRate; private: };