Panda3D
pursue.cxx
1 ////////////////////////////////////////////////////////////////////////
2 // Filename : pursue.cxx
3 // Created by : Deepak, John, Navin
4 // Date : 24 Oct 09
5 ////////////////////////////////////////////////////////////////////
6 //
7 // PANDA 3D SOFTWARE
8 // Copyright (c) Carnegie Mellon University. All rights reserved.
9 //
10 // All use of this software is subject to the terms of the revised BSD
11 // license. You should have received a copy of this license along
12 // with this source code in a file named "LICENSE."
13 //
14 ////////////////////////////////////////////////////////////////////
15 
16 #include "pursue.h"
17 
18 Pursue::Pursue(AICharacter *ai_ch, NodePath target_object, float pursue_wt) {
19  _ai_char = ai_ch;
20 
21  _pursue_target = target_object;
22  _pursue_weight = pursue_wt;
23 
24  _pursue_done = false;
25 }
26 
27 Pursue::~Pursue() {
28 }
29 
30 /////////////////////////////////////////////////////////////////////////////////
31 //
32 // Function : do_pursue
33 // Description : This function performs the pursue and returns a pursue force which is used
34 // in the calculate_prioritized function.
35 // In case the target has been reached it resets the forces to 0 so that the character stops.
36 // This function is not to be used by the user.
37 
38 /////////////////////////////////////////////////////////////////////////////////
39 
41  assert(_pursue_target && "pursue target not assigned");
42 
43  LVecBase3 present_pos = _ai_char->_ai_char_np.get_pos(_ai_char->_window_render);
44  double target_distance = (_pursue_target.get_pos(_ai_char->_window_render) - present_pos).length();
45 
46  if(int(target_distance) == 0) {
47  _pursue_done = true;
48  _ai_char->_steering->_steering_force = LVecBase3(0.0, 0.0, 0.0);
49  _ai_char->_steering->_pursue_force = LVecBase3(0.0, 0.0, 0.0);
50  return(LVecBase3(0.0, 0.0, 0.0));
51  }
52  else {
53  _pursue_done = false;
54  }
55 
56  _pursue_direction = _pursue_target.get_pos(_ai_char->_window_render) - present_pos;
57  _pursue_direction.normalize();
58 
59  LVecBase3 desired_force = _pursue_direction * _ai_char->_movt_force;
60  return(desired_force);
61 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
LPoint3 get_pos() const
Retrieves the translation component of the transform.
Definition: nodePath.cxx:1178
LVecBase3 do_pursue()
This function performs the pursue and returns a pursue force which is used in the calculate_prioritiz...
Definition: pursue.cxx:40
bool normalize()
Normalizes the vector in place.
Definition: lvecBase3.h:783
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165