18 WeightedData(
const SteeringPtr& _steering,
float _weight = 1.0f) :
19 steering(_steering), weight(_weight) {
20 ai_assert(weight > 0.0001f,
"Weight is too small");
23 typedef std::vector<WeightedData> WeightedSteerings;
24 typedef WeightedSteerings::const_iterator WeightedSteeringsIter;
31 WeightedSteerings _steerings;
34 _steerings(steerings) {
37 MoveVector execute (
const AIPtr& ai,
float speed)
const {
38 float totalWeight = 0.0f;
39 glm::vec3 vecBlended(0.0f);
40 float angularBlended = 0.0f;
42 const float weight = wd.weight;
43 const MoveVector& mv = wd.steering->execute(ai, speed);
44 if (isInfinite(mv.getVector())) {
48 vecBlended += mv.getVector() * weight;
49 angularBlended += mv.getRotation() * weight;
50 totalWeight += weight;
53 if (totalWeight <= 0.0000001f) {
57 const float scale = 1.0f / totalWeight;
58 return MoveVector(vecBlended * scale, fmodf(angularBlended * scale, glm::two_pi<float>()));
#define ai_assert(condition,...)
Provide your own assert - this is only executed in DEBUG mode.
Definition: Types.h:75
Definition: MoveVector.h:10
Defines some basic movement algorithms like Wandering, Seeking and Fleeing.
This class allows you to weight several steering methods and get a blended MoveVector out of it...
Definition: WeightedSteering.h:29
Steering and weight as input for WeightedSteering.
Definition: WeightedSteering.h:14