Panda3D
 All Classes Functions Variables Enumerations
seek.cxx
00001 ////////////////////////////////////////////////////////////////////////
00002 // Filename    : seek.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 "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 // Function : do_seek
00048 // Description : This function performs the seek and returns a seek force which is used
00049 //                in the calculate_prioritized function.
00050 //                This function is not to be used by the user.
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 }
 All Classes Functions Variables Enumerations