Panda3D

pursue.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 pursue.cxx
10 * @author Deepak, John, Navin
11 * @date 2009-10-24
12 */
13
14 #include "pursue.h"
15
16 Pursue::
17 Pursue(AICharacter *ai_ch, NodePath target_object, float pursue_wt) {
18 _ai_char = ai_ch;
19
20 _pursue_target = target_object;
21 _pursue_weight = pursue_wt;
22
23 _pursue_done = false;
24 }
25
26 Pursue::
27 ~Pursue() {
28 }
29
30 /**
31 * This function performs the pursue and returns a pursue force which is used
32 * in the calculate_prioritized function. In case the target has been reached
33 * it resets the forces to 0 so that the character stops. This function is
34 * not to be used by the user.
35 */
36 LVecBase3 Pursue::
37 do_pursue() {
38 assert(_pursue_target && "pursue target not assigned");
39
40 LVecBase3 present_pos = _ai_char->_ai_char_np.get_pos(_ai_char->_window_render);
41 double target_distance = (_pursue_target.get_pos(_ai_char->_window_render) - present_pos).length();
42
43 if(int(target_distance) == 0) {
44 _pursue_done = true;
45 _ai_char->_steering->_steering_force = LVecBase3(0.0, 0.0, 0.0);
46 _ai_char->_steering->_pursue_force = LVecBase3(0.0, 0.0, 0.0);
47 return LVecBase3(0.0, 0.0, 0.0);
48 }
49 else {
50 _pursue_done = false;
51 }
52
53 _pursue_direction = _pursue_target.get_pos(_ai_char->_window_render) - present_pos;
54 _pursue_direction.normalize();
55
56 LVecBase3 desired_force = _pursue_direction * _ai_char->_movt_force;
57 return desired_force;
58 }
AICharacter
Definition: aiCharacter.h:29
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
NodePath::get_pos
LPoint3 get_pos() const
Retrieves the translation component of the transform.
Definition: nodePath.cxx:1040
Pursue::do_pursue
LVecBase3 do_pursue()
This function performs the pursue and returns a pursue force which is used in the calculate_prioritiz...
Definition: pursue.cxx:37
pursue.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.