16 #include "aiCharacter.h" 18 AICharacter::AICharacter(
string model_name,
NodePath model_np,
double mass,
double movt_force,
double max_force) {
20 _ai_char_np = model_np;
23 _max_force = max_force;
24 _movt_force = movt_force;
27 _steering_force =
LVecBase3(0.0, 0.0, 0.0);
30 _steering->_ai_char =
this;
35 AICharacter::~AICharacter() {
48 if (!_steering->
is_off(_steering->_none)) {
51 LVecBase3 acceleration = steering_force / _mass;
53 _velocity = acceleration;
55 LVecBase3 direction = _steering->_steering_force;
58 _ai_char_np.set_pos(old_pos + _velocity) ;
60 if (steering_force.
length() > 0) {
61 _ai_char_np.
look_at(old_pos + (direction * 5));
62 _ai_char_np.set_h(_ai_char_np.get_h() + 180);
63 _ai_char_np.set_p(-_ai_char_np.get_p());
64 _ai_char_np.set_r(-_ai_char_np.get_r());
67 _steering->_steering_force =
LVecBase3(0.0, 0.0, 0.0);
68 _steering->_seek_force =
LVecBase3(0.0, 0.0, 0.0);
69 _steering->_flee_force =
LVecBase3(0.0, 0.0, 0.0);
70 _steering->_pursue_force =
LVecBase3(0.0, 0.0, 0.0);
71 _steering->_evade_force =
LVecBase3(0.0, 0.0, 0.0);
72 _steering->_arrival_force =
LVecBase3(0.0, 0.0, 0.0);
73 _steering->_flock_force =
LVecBase3(0.0, 0.0, 0.0);
74 _steering->_wander_force =
LVecBase3(0.0, 0.0, 0.0);
82 void AICharacter::set_velocity(
LVecBase3 velocity) {
86 double AICharacter::get_mass() {
90 void AICharacter::set_mass(
double m) {
94 double AICharacter::get_max_force() {
98 void AICharacter::set_max_force(
double max_force) {
99 _max_force = max_force;
102 NodePath AICharacter::get_node_path() {
106 void AICharacter::set_node_path(
NodePath np) {
114 void AICharacter::set_char_render(
NodePath render) {
115 _window_render = render;
118 NodePath AICharacter::get_char_render() {
119 return _window_render;
122 void AICharacter::set_pf_guide(
bool pf_guide) {
123 _pf_guide = pf_guide;
This is the base class for all three-component vectors and points.
LVecBase3 calculate_prioritized()
This function updates the main steering force for the ai character using the accumulate function and ...
bool is_off(_behavior_type bt)
This function returns true if an aiBehavior is off.
LPoint3 get_pos() const
Retrieves the translation component of the transform.
float length() const
Returns the length of the vector, by the Pythagorean theorem.
bool normalize()
Normalizes the vector in place.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
void update()
Each character's update will update its ai and physics based on his resultant steering force...
void look_at(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the transform on this NodePath so that it rotates to face the indicated point in space...