20 const static double rand_max = 0x7fff;
21 return ((rand()) / (rand_max + 1.0));
31 Wander::Wander(
AICharacter *ai_ch,
double wander_radius,
int flag,
double aoe,
float wander_weight) {
33 _wander_radius = wander_radius ;
34 _wander_weight = wander_weight;
39 _area_of_effect = aoe;
40 _init_pos = _ai_char->get_node_path().
get_pos(_ai_char->get_char_render());
46 _wander_target = LVecBase3(_wander_radius * cos(theta), _wander_radius * sin(theta),0);
50 _wander_target = LVecBase3(0, _wander_radius * cos(theta), _wander_radius * sin(theta));
54 _wander_target = LVecBase3(_wander_radius * cos(theta), 0, _wander_radius * sin(theta));
58 _wander_target = LVecBase3(_wander_radius * sin(theta) * cos(si), _wander_radius * sin(theta) * sin(si), _wander_radius * cos(theta));
62 _wander_target = LVecBase3(_wander_radius * cos(theta), _wander_radius * sin(theta),0);
77 LVecBase3 present_pos = _ai_char->get_node_path().
get_pos(_ai_char->get_char_render());
85 _wander_target += LVecBase3(time_slice_1, time_slice_2, 0);
89 _wander_target += LVecBase3(0, time_slice_1, time_slice_2);
93 _wander_target += LVecBase3(time_slice_1, 0, time_slice_2);
97 _wander_target += LVecBase3(time_slice_1, time_slice_2, time_slice_3);
102 _wander_target = LVecBase3(time_slice_1, time_slice_2, 0);
105 _wander_target.normalize();
106 _wander_target *= _wander_radius;
107 LVecBase3 target = _ai_char->get_char_render().
get_relative_vector(_ai_char->get_node_path(), LVector3::forward());
111 target = _wander_target + target;
112 LVecBase3 desired_target = present_pos + target;
113 LVecBase3 desired_force = desired_target - _ai_char->get_node_path().
get_pos() ;
114 desired_force.normalize();
115 desired_force *= _ai_char->_movt_force;
116 double distance = (present_pos - _init_pos).length();
117 if(_area_of_effect > 0 && distance > _area_of_effect) {
118 LVecBase3 direction = present_pos - _init_pos;
119 direction.normalize();
120 desired_force = - direction * _ai_char->_movt_force;
121 LVecBase3 dirn = _ai_char->_steering->_steering_force;
123 _ai_char->_steering->_steering_force = LVecBase3(0.0, 0.0, 0.0);
125 return desired_force;
LVector3 get_relative_vector(const NodePath &other, const LVecBase3 &vec) const
Given that the indicated vector is in the coordinate system of the other node, returns the same vecto...
double rand_float()
This function creates a random float point number.
double random_clamped()
This function returns a random floating point number in the range -1 to 1.
LPoint3 get_pos() const
Retrieves the translation component of the transform.
LVecBase3 do_wander()
This function performs the wander and returns the wander force which is used in the calculate_priorit...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.