Well they are all pretty big... but here is what wasn't playing nice together
AutoObject.h
Code: Select all
#pragma once
#include "GameStd.h"
#include "SteeringBehaviors.h"
#include <OgreVector3.h>
class AutoObject : public IMovingObject
{
public:
AutoObject();
~AutoObject();
//Inherited from IGameManager
void Initialize();
void UpdateStarted(const Ogre::FrameEvent& gameTime);
void UpdateEnded(const Ogre::FrameEvent& gameTime);
void Cleanup();
//Inherited from IObject
void Draw();
bool HandleMessage(int message);
Ogre::Vector3 GetPosition();
void SetPostion(Ogre::Vector3 pos);
double GetBRadius();
void SetBRadius(double r);
int GetID();
void SetID(int id);
bool IsTagged();
void Tag();
void UnTag();
Ogre::Vector3 GetScale();
void SetScale(Ogre::Vector3 nScale);
void SetScale(double nScale);
ObjectType GetObjectType();
void SetObjectType(ObjectType nType);
void Write(std::ostream& os);
void Read(std::istream& is);
//Inherited from IMovingObject
Ogre::Vector3 GetVelocity();
void SetVelocity(Ogre::Vector3 nVelocity);
double GetMass();
void SetMass(double nMass);
Ogre::Vector3 GetPerp();
double GetMaxSpeed();
void SetMaxSpeed(double nSpeed);
double GetMaxForce();
void SetMaxForce(double nForce);
void SetAppliedForce(Ogre::Vector3 nForce);
Ogre::Vector3 GetAppliedForce();
bool IsSpeedMaxedOut();
double Speed();
double SpeedSq();
Ogre::Vector3 GetHeading();
void SetHeading(Ogre::Vector3 nHeading);
void SetHeading(int xHeading, int yHeading, int zHeading);
bool RotateHeadingToFacePosition(Ogre::Vector3 target);
double GetMaxTurnRate();
void SetMaxTurnRate(double nRate);
Ogre::Vector3 GetCurrentAccel();
void SetCurrentAccel(Ogre::Vector3 nAccel);
void SetCurrentAccel(double xAccel, double yAccel, double zAccel);
//Unique to AutoObject
SteeringBehaviors* Steering();
Ogre::Vector3 SmoothedHeading();
bool isSmoothingOn();
void SmoothingOn();
void SmoothingOff();
void ToggleSmoothing();
double TimeElapsed();
private:
int m_ID; //Unique, assigned by ObjectManager
ObjectType m_ObjectType; //A Auto object is designated by
//Autonomous, of the ObjectType enum
//in IObject
bool m_Tag;
Ogre::Vector3 m_Pos; //Indicates current position described by
//a 3D vector
Ogre::Vector3 m_Scale; //Indicates the current scale described by
//a 3D vector
double m_BoundingRadius;
Ogre::Vector3 m_Velocity; //The current velocity described by a 3D
//vector
Ogre::Vector3 m_Heading; //The current heading described by a 3D
//vector
Ogre::Vector3 m_Perp; //A unit vector perpendicular
//to the heading
Ogre::Vector3 m_Acceleration;
Ogre::Vector3 m_AppliedForce;
double m_Mass;
double m_MaxSpeed;
double m_MaxForce;
double m_MaxTurnRate;
SteeringBehaviors* m_Steering;
Ogre::Vector3 m_HeadingSmoother;
Ogre::Vector3 m_SmoothedHeading;
bool m_SmoothingOn;
double m_TimeElapsed;
};
SteeringBehaviors.h
Code: Select all
#pragma once
#include "GameStd.h"
#include "Path.h"
#include <OgreVector3.h>
class PlayerObject;
class AutoObject;
class StationaryObject;
const double WANDER_RADIUS = 1.2;
const double WANDER_DISTANCE = 2.0;
const double WANDER_JITTER = 80.0;
const double WAYPOINT_SEEK_DISTANCE = 20;
class SteeringBehaviors
{
public:
enum SummingMethod{WEIGHTED_AVERAGE, PRIORITIZED, DITHERED};
SteeringBehaviors(AutoObject* agent);
~SteeringBehaviors();
Ogre::Vector3 Calculate();
double ForwardComponent();
double SideComponent();
void SetTarget(Ogre::Vector3 Target);
void SetTargetAgent1(IMovingObject* agent);
void SetTargetAgent2(IMovingObject* agent);
void SetOffset(Ogre::Vector3 offset);
Ogre::Vector3 GetOffset();
void SetPath(std::list<Ogre::Vector3> newPath);
void CreateRandomPath(int numOfWaypoints, int mx, int my, int cx, int cy);
Ogre::Vector3 Force();
void ToggleSpacePartitioning();
bool isSpacePartitioningOn();
void SetSummingMethod(SummingMethod sm);
void SeekOn();
void PursuitOn(IMovingObject* agent);
void ArriveOn();
void InterposeOn(IMovingObject* agent1, IMovingObject* agent2);
void OffsetPursuitOn(IMovingObject* agent, Ogre::Vector3 newoffset);
void FleeOn();
void EvadeOn(IMovingObject* agent1);
void HideOn(IMovingObject* agent);
void WallAvoidanceOn();
void PathFollowingOn();
void WanderOn();
void SeperationOn();
void AlignmentOn();
void CohesionOn();
void FlockingOn();
void SeekOff();
void PursuitOff();
void ArriveOff();
void InterposeOff();
void OffsetPursuitOff();
void FleeOff();
void EvadeOff();
void HideOff();
void WallAvoidanceOff();
void PathFollowingOff();
void WanderOff();
void SeperationOff();
void AlignmentOff();
void CohesionOff();
void FlockingOff();
bool isSeekOn();
bool isPursuitOn();
bool isArriveOn();
bool isInterposeOn();
bool isOffsetPursuitOn();
bool isFleeOn();
bool isEvadeOn();
bool isHideOn();
bool isWallAvoidanceOn();
bool isPathFollowingOn();
bool isWanderOn();
bool isSeperationOn();
bool isAlignmentOn();
bool isCohesionOn();
bool isFlockingOn();
double GetDBoxLength();
std::vector<Ogre::Vector3> GetFeelers();
double GetWanderJitter();
double GetWanderDistance();
double GetWanderRadius();
double GetSeperationWeight();
double GetAlignmentWeight();
double GetCohesionWeight();
private:
enum BehaviorType{
none = 0x00000,
seek = 0x00002,
pursuit = 0x00004,
arrive = 0x00008,
interpose = 0x00010,
offset_pursuit = 0x00020,
flee = 0x00040,
evade = 0x00080,
hide = 0x00100,
wall_avoid = 0x00200,
path_following = 0x00400,
wander = 0x00800,
seperation = 0x01000,
alignment = 0x02000,
cohesion = 0x04000,
flocking = 0x08000
};
//A pointer to the owner of this instance
AutoObject* m_Vehicle;
Ogre::Vector3 m_SteeringForce;
IMovingObject* m_TargetAgent1;
IMovingObject* m_TargetAgent2;
Ogre::Vector3 m_Target;
std::vector<Ogre::Vector3> m_Feelers;
double m_WallDetectionFeelerLength;
Ogre::Vector3 m_WanderTarget;
double m_WanderJitter;
double m_WanderRadius;
double m_WanderDistance;
double m_WeightSeek;
double m_WeightPursuit;
double m_WeightArrive;
double m_WeightInterpose;
double m_WeightOffsetPursuit;
double m_WeightFlee;
double m_WeightEvade;
double m_WeightHide;
double m_WeightWallAvoid;
double m_WeightPathFollowing;
double m_WeightWander;
double m_WeightSeperation;
double m_WeightAlignment;
double m_WeightCohesion;
double m_WeightFlocking;
double m_ViewDistance;
Path* m_Path;
double m_WaypointSeekDistSq;
Ogre::Vector3 m_Offset;
int m_Flags;
enum Deceleration{SLOW,NORMAL,FAST};
Deceleration m_Deceleration;
bool m_CellSpaceOn;
SummingMethod m_SummingMethod;
double m_DBoxLength;
double PanicDistanceSq;
double ThreatRange;
bool On(BehaviorType bt);
bool AccumulateForce(Ogre::Vector3 &force, Ogre::Vector3 forceToAdd);
void CreateFeelers();
/* BEGIN BEHAVIOR DECLARATIONS */
Ogre::Vector3 Seek(Ogre::Vector3 TargetPos);
Ogre::Vector3 Pursuit(IMovingObject* agent);
Ogre::Vector3 Arrive(Ogre::Vector3 TargetPos, Deceleration decel);
Ogre::Vector3 Interpose(IMovingObject* agentA, IMovingObject* agentB);
Ogre::Vector3 OffsetPursuit(IMovingObject* agent, Ogre::Vector3 offset);
Ogre::Vector3 Flee(Ogre::Vector3 hunterPos) ;
Ogre::Vector3 Evade(IMovingObject* agent);
Ogre::Vector3 Hide(IMovingObject* hunter, std::vector<IObject*> &obstacles);
Ogre::Vector3 WallAvoidance(std::vector<StationaryObject> &walls);
Ogre::Vector3 FollowPath();
Ogre::Vector3 Wander();
Ogre::Vector3 Seperation(std::vector<IMovingObject*> &agents);
Ogre::Vector3 Alignment(std::vector<IMovingObject*> &agents);
Ogre::Vector3 Cohesion(std::vector<IMovingObject*> &agents);
Ogre::Vector3 Flocking(std::vector<IMovingObject*> &agents);
/* END BEHAVIOR DECLARATIONS */
Ogre::Vector3 CalculateWeightedSum();
Ogre::Vector3 CalculatePrioritized();
Ogre::Vector3 CalculateDithered();
Ogre::Vector3 GetHidingPosition(Ogre::Vector3 posOb, double radiusOb, Ogre::Vector3 posHunter);
};
My PlayerObject class and StationaryObject class don't have any issues, but my AutoObject produces the error. My guess is because Player and Stationary don't include the SteeringBehaviors class since my player moves by key presses and my stationary objects don't move.
The friend solution seems to have worked. Any other suggestions?
(This code is a modified version of the steering behaviors project found in the book
Programming Game AI by Example by Mat Buckland)