Panda3D
|
00001 //////////////////////////////////////////////////////////////////////// 00002 // Filename : pursue.cxx 00003 // Created by : Deepak, John, Navin 00004 // Date : 24 Oct 09 00005 //////////////////////////////////////////////////////////////////// 00006 // 00007 // PANDA 3D SOFTWARE 00008 // Copyright (c) Carnegie Mellon University. All rights reserved. 00009 // 00010 // All use of this software is subject to the terms of the revised BSD 00011 // license. You should have received a copy of this license along 00012 // with this source code in a file named "LICENSE." 00013 // 00014 //////////////////////////////////////////////////////////////////// 00015 00016 #include "pursue.h" 00017 00018 Pursue::Pursue(AICharacter *ai_ch, NodePath target_object, float pursue_wt) { 00019 _ai_char = ai_ch; 00020 00021 _pursue_target = target_object; 00022 _pursue_weight = pursue_wt; 00023 00024 _pursue_done = false; 00025 } 00026 00027 Pursue::~Pursue() { 00028 } 00029 00030 ///////////////////////////////////////////////////////////////////////////////// 00031 // 00032 // Function : do_pursue 00033 // Description : This function performs the pursue and returns a pursue force which is used 00034 // in the calculate_prioritized function. 00035 // In case the target has been reached it resets the forces to 0 so that the character stops. 00036 // This function is not to be used by the user. 00037 00038 ///////////////////////////////////////////////////////////////////////////////// 00039 00040 LVecBase3f Pursue::do_pursue() { 00041 assert(_pursue_target && "pursue target not assigned"); 00042 00043 LVecBase3f present_pos = _ai_char->_ai_char_np.get_pos(_ai_char->_window_render); 00044 double target_distance = (_pursue_target.get_pos(_ai_char->_window_render) - present_pos).length(); 00045 00046 if(int(target_distance) == 0) { 00047 _pursue_done = true; 00048 _ai_char->_steering->_steering_force = LVecBase3f(0.0, 0.0, 0.0); 00049 _ai_char->_steering->_pursue_force = LVecBase3f(0.0, 0.0, 0.0); 00050 return(LVecBase3f(0.0, 0.0, 0.0)); 00051 } 00052 else { 00053 _pursue_done = false; 00054 } 00055 00056 _pursue_direction = _pursue_target.get_pos(_ai_char->_window_render) - present_pos; 00057 _pursue_direction.normalize(); 00058 00059 LVecBase3f desired_force = _pursue_direction * _ai_char->_movt_force; 00060 return(desired_force); 00061 }