Panda3D
seek.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file seek.cxx
10  * @author Deepak, John, Navin
11  * @date 2009-10-24
12  */
13 
14 #include "seek.h"
15 
16 Seek::Seek(AICharacter *ai_ch, NodePath target_object, float seek_wt) {
17  _ai_char = ai_ch;
18 
19  _seek_position = target_object.get_pos(_ai_char->_window_render);
20  _seek_weight = seek_wt;
21 
22  _seek_direction = _seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render);
23  _seek_direction.normalize();
24 
25  _seek_done = false;
26 }
27 
28 Seek::Seek(AICharacter *ai_ch, LVecBase3 pos, float seek_wt) {
29  _ai_char = ai_ch;
30 
31  _seek_position = pos;
32  _seek_weight = seek_wt;
33 
34  _seek_direction = _seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render);
35  _seek_direction.normalize();
36 
37  _seek_done = false;
38 }
39 
40 Seek::~Seek() {
41 }
42 
43 /**
44  * This function performs the seek and returns a seek force which is used in
45  * the calculate_prioritized function. This function is not to be used by the
46  * user.
47  */
48 LVecBase3 Seek::do_seek() {
49  double target_distance = (_seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render)).length();
50 
51  if(int(target_distance) == 0) {
52  _seek_done = true;
53  _ai_char->_steering->_steering_force = LVecBase3(0.0, 0.0, 0.0);
54  _ai_char->_steering->turn_off("seek");
55  return(LVecBase3(0.0, 0.0, 0.0));
56  }
57 
58  LVecBase3 desired_force = _seek_direction * _ai_char->_movt_force;
59  return(desired_force);
60 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void turn_off(std::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:992
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
LVecBase3 do_seek()
This function performs the seek and returns a seek force which is used in the calculate_prioritized f...
Definition: seek.cxx:48