00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "seek.h"
00017
00018 Seek::Seek(AICharacter *ai_ch, NodePath target_object, float seek_wt) {
00019 _ai_char = ai_ch;
00020
00021 _seek_position = target_object.get_pos(_ai_char->_window_render);
00022 _seek_weight = seek_wt;
00023
00024 _seek_direction = _seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render);
00025 _seek_direction.normalize();
00026
00027 _seek_done = false;
00028 }
00029
00030 Seek::Seek(AICharacter *ai_ch, LVecBase3f pos, float seek_wt) {
00031 _ai_char = ai_ch;
00032
00033 _seek_position = pos;
00034 _seek_weight = seek_wt;
00035
00036 _seek_direction = _seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render);
00037 _seek_direction.normalize();
00038
00039 _seek_done = false;
00040 }
00041
00042 Seek::~Seek() {
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 LVecBase3f Seek::do_seek() {
00055 double target_distance = (_seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render)).length();
00056
00057 if(int(target_distance) == 0) {
00058 _seek_done = true;
00059 _ai_char->_steering->_steering_force = LVecBase3f(0.0, 0.0, 0.0);
00060 _ai_char->_steering->turn_off("seek");
00061 return(LVecBase3f(0.0, 0.0, 0.0));
00062 }
00063
00064 LVecBase3f desired_force = _seek_direction * _ai_char->_movt_force;
00065 return(desired_force);
00066 }