Panda3D
seek.cxx
1 ////////////////////////////////////////////////////////////////////////
2 // Filename : seek.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 "seek.h"
17 
18 Seek::Seek(AICharacter *ai_ch, NodePath target_object, float seek_wt) {
19  _ai_char = ai_ch;
20 
21  _seek_position = target_object.get_pos(_ai_char->_window_render);
22  _seek_weight = seek_wt;
23 
24  _seek_direction = _seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render);
25  _seek_direction.normalize();
26 
27  _seek_done = false;
28 }
29 
30 Seek::Seek(AICharacter *ai_ch, LVecBase3 pos, float seek_wt) {
31  _ai_char = ai_ch;
32 
33  _seek_position = pos;
34  _seek_weight = seek_wt;
35 
36  _seek_direction = _seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render);
37  _seek_direction.normalize();
38 
39  _seek_done = false;
40 }
41 
42 Seek::~Seek() {
43 }
44 
45 /////////////////////////////////////////////////////////////////////////////////
46 //
47 // Function : do_seek
48 // Description : This function performs the seek and returns a seek force which is used
49 // in the calculate_prioritized function.
50 // This function is not to be used by the user.
51 
52 /////////////////////////////////////////////////////////////////////////////////
53 
55  double target_distance = (_seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render)).length();
56 
57  if(int(target_distance) == 0) {
58  _seek_done = true;
59  _ai_char->_steering->_steering_force = LVecBase3(0.0, 0.0, 0.0);
60  _ai_char->_steering->turn_off("seek");
61  return(LVecBase3(0.0, 0.0, 0.0));
62  }
63 
64  LVecBase3 desired_force = _seek_direction * _ai_char->_movt_force;
65  return(desired_force);
66 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
void turn_off(string ai_type)
This function turns off any aiBehavior which is passed as a string.
LPoint3 get_pos() const
Retrieves the translation component of the transform.
Definition: nodePath.cxx:1178
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
LVecBase3 do_seek()
This function performs the seek and returns a seek force which is used in the calculate_prioritized f...
Definition: seek.cxx:54