Blender V2.61 - r43446
|
00001 /* 00002 * Add steering behaviors 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is: all of this file. 00021 * 00022 * Contributor(s): none yet. 00023 * 00024 * ***** END GPL LICENSE BLOCK ***** 00025 */ 00026 00027 #ifndef __KX_STEERINGACTUATOR 00028 #define __KX_STEERINGACTUATOR 00029 00030 #include "SCA_IActuator.h" 00031 #include "SCA_LogicManager.h" 00032 #include "MT_Matrix3x3.h" 00033 00034 class KX_GameObject; 00035 class KX_NavMeshObject; 00036 struct KX_Obstacle; 00037 class KX_ObstacleSimulation; 00038 const int MAX_PATH_LENGTH = 128; 00039 00040 class KX_SteeringActuator : public SCA_IActuator 00041 { 00042 Py_Header 00043 00045 KX_GameObject *m_target; 00046 KX_NavMeshObject *m_navmesh; 00047 int m_mode; 00048 float m_distance; 00049 float m_velocity; 00050 float m_acceleration; 00051 float m_turnspeed; 00052 KX_ObstacleSimulation* m_simulation; 00053 00054 double m_updateTime; 00055 KX_Obstacle* m_obstacle; 00056 bool m_isActive; 00057 bool m_isSelfTerminated; 00058 bool m_enableVisualization; 00059 short m_facingMode; 00060 bool m_normalUp; 00061 float m_path[MAX_PATH_LENGTH*3]; 00062 int m_pathLen; 00063 int m_pathUpdatePeriod; 00064 double m_pathUpdateTime; 00065 int m_wayPointIdx; 00066 MT_Matrix3x3 m_parentlocalmat; 00067 MT_Vector3 m_steerVec; 00068 void HandleActorFace(MT_Vector3& velocity); 00069 public: 00070 enum KX_STEERINGACT_MODE 00071 { 00072 KX_STEERING_NODEF = 0, 00073 KX_STEERING_SEEK, 00074 KX_STEERING_FLEE, 00075 KX_STEERING_PATHFOLLOWING, 00076 KX_STEERING_MAX 00077 }; 00078 00079 KX_SteeringActuator(class SCA_IObject* gameobj, 00080 int mode, 00081 KX_GameObject *target, 00082 KX_GameObject *navmesh, 00083 float distance, 00084 float velocity, 00085 float acceleration, 00086 float turnspeed, 00087 bool isSelfTerminated, 00088 int pathUpdatePeriod, 00089 KX_ObstacleSimulation* simulation, 00090 short facingmode, 00091 bool normalup, 00092 bool enableVisualization); 00093 virtual ~KX_SteeringActuator(); 00094 virtual bool Update(double curtime, bool frame); 00095 00096 virtual CValue* GetReplica(); 00097 virtual void ProcessReplica(); 00098 virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map); 00099 virtual bool UnlinkObject(SCA_IObject* clientobj); 00100 const MT_Vector3& GetSteeringVec(); 00101 00102 #ifndef DISABLE_PYTHON 00103 00104 /* --------------------------------------------------------------------- */ 00105 /* Python interface ---------------------------------------------------- */ 00106 /* --------------------------------------------------------------------- */ 00107 00108 /* These are used to get and set m_target */ 00109 static PyObject* pyattr_get_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); 00110 static int pyattr_set_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00111 static PyObject* pyattr_get_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); 00112 static int pyattr_set_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00113 static PyObject* pyattr_get_steeringVec(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); 00114 00115 00116 #endif // DISABLE_PYTHON 00117 00118 }; /* end of class KX_SteeringActuator : public SCA_PropertyActuator */ 00119 00120 #endif 00121