- added options to enable visualization for obstacle simulation and steering actuator

- added python attributes for parameters of steering actuator
This commit is contained in:
Nick Samarin 2010-07-15 18:41:29 +00:00
parent 219e9022b9
commit 0fbca1dc19
16 changed files with 144 additions and 46 deletions

@ -557,7 +557,8 @@ class WORLD_PT_game_physics_obstacles(WorldButtonsPanel):
layout.prop(gs, "obstacle_simulation", text = "Type") layout.prop(gs, "obstacle_simulation", text = "Type")
if gs.obstacle_simulation != 'None': if gs.obstacle_simulation != 'None':
layout.prop(gs, "level_height", text="Level height") layout.prop(gs, "level_height")
layout.prop(gs, "show_obstacle_simulation")
classes = [ classes = [

@ -121,7 +121,7 @@ void mid_v3_v3v3(float r[3], float a[3], float b[3]);
MINLINE int is_zero_v3(float a[3]); MINLINE int is_zero_v3(float a[3]);
MINLINE int is_one_v3(float a[3]); MINLINE int is_one_v3(float a[3]);
MINLINE int equals_v3v3(float a[3], float b[3]); MINLINE int equals_v3v3(const float a[3],const float b[3]);
MINLINE int compare_v3v3(float a[3], float b[3], float limit); MINLINE int compare_v3v3(float a[3], float b[3], float limit);
MINLINE int compare_len_v3v3(float a[3], float b[3], float limit); MINLINE int compare_len_v3v3(float a[3], float b[3], float limit);

@ -404,7 +404,7 @@ MINLINE int is_one_v3(float *v)
return (v[0] == 1 && v[1] == 1 && v[2] == 1); return (v[0] == 1 && v[1] == 1 && v[2] == 1);
} }
MINLINE int equals_v3v3(float *v1, float *v2) MINLINE int equals_v3v3(const float *v1,const float *v2)
{ {
return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2])); return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]));
} }

@ -4324,7 +4324,11 @@ static void draw_actuator_steering(uiLayout *layout, PointerRNA *ptr)
row = uiLayoutRow(layout, 0); row = uiLayoutRow(layout, 0);
uiItemR(row, ptr, "selfterminated", 0, NULL, 0); uiItemR(row, ptr, "selfterminated", 0, NULL, 0);
if (RNA_enum_get(ptr, "mode")==ACT_STEERING_PATHFOLLOWING) if (RNA_enum_get(ptr, "mode")==ACT_STEERING_PATHFOLLOWING)
{
uiItemR(row, ptr, "updateperiod", 0, NULL, 0); uiItemR(row, ptr, "updateperiod", 0, NULL, 0);
row = uiLayoutRow(layout, 0);
}
uiItemR(row, ptr, "enablevisualization", 0, NULL, 0);
} }

@ -522,6 +522,7 @@ typedef struct FreeCamera {
#define ACT_STEERING_PATHFOLLOWING 2 #define ACT_STEERING_PATHFOLLOWING 2
/* steeringactuator->flag */ /* steeringactuator->flag */
#define ACT_STEERING_SELFTERMINATED 1 #define ACT_STEERING_SELFTERMINATED 1
#define ACT_STEERING_ENABLEVISUALIZATION 2
#endif #endif

@ -516,6 +516,7 @@ typedef struct GameData {
#define GAME_GLSL_NO_EXTRA_TEX (1 << 11) #define GAME_GLSL_NO_EXTRA_TEX (1 << 11)
#define GAME_IGNORE_DEPRECATION_WARNINGS (1 << 12) #define GAME_IGNORE_DEPRECATION_WARNINGS (1 << 12)
#define GAME_ENABLE_ANIMATION_RECORD (1 << 13) #define GAME_ENABLE_ANIMATION_RECORD (1 << 13)
#define GAME_SHOW_OBSTACLE_SIMULATION (1 << 14)
/* GameData.matmode */ /* GameData.matmode */
#define GAME_MAT_TEXFACE 0 #define GAME_MAT_TEXFACE 0

@ -1926,6 +1926,11 @@ static void rna_def_steering_actuator(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Self terminated", "Terminate when target is reached"); RNA_def_property_ui_text(prop, "Self terminated", "Terminate when target is reached");
RNA_def_property_update(prop, NC_LOGIC, NULL); RNA_def_property_update(prop, NC_LOGIC, NULL);
prop= RNA_def_property(srna, "enablevisualization", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_STEERING_ENABLEVISUALIZATION);
RNA_def_property_ui_text(prop, "Visualize", "Enable debug visualization");
RNA_def_property_update(prop, NC_LOGIC, NULL);
prop= RNA_def_property(srna, "updateperiod", PROP_INT, PROP_NONE); prop= RNA_def_property(srna, "updateperiod", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "updateTime"); RNA_def_property_int_sdna(prop, NULL, "updateTime");
RNA_def_property_ui_range(prop, -1, 100000, 1, 1); RNA_def_property_ui_range(prop, -1, 100000, 1, 1);

@ -1862,6 +1862,10 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Level height", "Max difference in heights of obstacles to enable their interaction"); RNA_def_property_ui_text(prop, "Level height", "Max difference in heights of obstacles to enable their interaction");
RNA_def_property_update(prop, NC_SCENE, NULL); RNA_def_property_update(prop, NC_SCENE, NULL);
prop= RNA_def_property(srna, "show_obstacle_simulation", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_SHOW_OBSTACLE_SIMULATION);
RNA_def_property_ui_text(prop, "Visualization", "Enable debug visualization for obstacle simulation");
/* Recast Settings */ /* Recast Settings */
prop= RNA_def_property(srna, "recast_data", PROP_POINTER, PROP_NONE); prop= RNA_def_property(srna, "recast_data", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL); RNA_def_property_flag(prop, PROP_NEVER_NULL);

@ -1058,11 +1058,12 @@ void BL_ConvertActuators(char* maggiename,
} }
bool selfTerminated = (stAct->flag & ACT_STEERING_SELFTERMINATED) !=0; bool selfTerminated = (stAct->flag & ACT_STEERING_SELFTERMINATED) !=0;
bool enableVisualization = (stAct->flag & ACT_STEERING_ENABLEVISUALIZATION) !=0;
KX_SteeringActuator *tmpstact KX_SteeringActuator *tmpstact
= new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist, = new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist,
stAct->velocity, stAct->acceleration, stAct->turnspeed, stAct->velocity, stAct->acceleration, stAct->turnspeed,
selfTerminated, stAct->updateTime, selfTerminated, stAct->updateTime,
scene->GetObstacleSimulation()); scene->GetObstacleSimulation(), enableVisualization);
baseact = tmpstact; baseact = tmpstact;
break; break;
} }

@ -446,6 +446,13 @@ bool KX_NavMeshObject::BuildVertIndArrays(RAS_MeshObject* meshobj, float *&verti
bool KX_NavMeshObject::BuildNavMesh() bool KX_NavMeshObject::BuildNavMesh()
{ {
if (m_navMesh)
{
delete m_navMesh;
m_navMesh = NULL;
}
if (GetMeshCount()==0) if (GetMeshCount()==0)
return false; return false;
@ -628,25 +635,23 @@ dtStatNavMesh* KX_NavMeshObject::GetNavMesh()
return m_navMesh; return m_navMesh;
} }
void KX_NavMeshObject::DrawNavMesh() void KX_NavMeshObject::DrawNavMesh(NavMeshRenderMode renderMode)
{ {
if (!m_navMesh) if (!m_navMesh)
return; return;
MT_Vector3 color(0.f, 0.f, 0.f); MT_Vector3 color(0.f, 0.f, 0.f);
enum RenderMode {POLYS ,DETAILED_TRIS, WALLS};
static const RenderMode renderMode = DETAILED_TRIS;// DETAILED_TRIS POLYS
switch (renderMode) switch (renderMode)
{ {
case POLYS : case RM_POLYS :
case WALLS : case RM_WALLS :
for (int pi=0; pi<m_navMesh->getPolyCount(); pi++) for (int pi=0; pi<m_navMesh->getPolyCount(); pi++)
{ {
const dtStatPoly* poly = m_navMesh->getPoly(pi); const dtStatPoly* poly = m_navMesh->getPoly(pi);
for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++) for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++)
{ {
if (poly->n[j] && renderMode==WALLS) if (poly->n[j] && renderMode==RM_WALLS)
continue; continue;
const float* vif = m_navMesh->getVertex(poly->v[i]); const float* vif = m_navMesh->getVertex(poly->v[i]);
const float* vjf = m_navMesh->getVertex(poly->v[j]); const float* vjf = m_navMesh->getVertex(poly->v[j]);
@ -658,7 +663,7 @@ void KX_NavMeshObject::DrawNavMesh()
} }
} }
break; break;
case DETAILED_TRIS : case RM_TRIS :
for (int i = 0; i < m_navMesh->getPolyDetailCount(); ++i) for (int i = 0; i < m_navMesh->getPolyDetailCount(); ++i)
{ {
const dtStatPoly* p = m_navMesh->getPoly(i); const dtStatPoly* p = m_navMesh->getPoly(i);
@ -800,7 +805,7 @@ PyTypeObject KX_NavMeshObject::Type = {
Methods, Methods,
0, 0,
0, 0,
&CValue::Type, &KX_GameObject::Type,
0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_new py_base_new
}; };
@ -814,6 +819,7 @@ PyMethodDef KX_NavMeshObject::Methods[] = {
KX_PYMETHODTABLE(KX_NavMeshObject, findPath), KX_PYMETHODTABLE(KX_NavMeshObject, findPath),
KX_PYMETHODTABLE(KX_NavMeshObject, raycast), KX_PYMETHODTABLE(KX_NavMeshObject, raycast),
KX_PYMETHODTABLE(KX_NavMeshObject, draw), KX_PYMETHODTABLE(KX_NavMeshObject, draw),
KX_PYMETHODTABLE(KX_NavMeshObject, rebuild),
{NULL,NULL} //Sentinel {NULL,NULL} //Sentinel
}; };
@ -854,10 +860,30 @@ KX_PYMETHODDEF_DOC(KX_NavMeshObject, raycast,
return PyFloat_FromDouble(hit); return PyFloat_FromDouble(hit);
} }
KX_PYMETHODDEF_DOC_NOARGS(KX_NavMeshObject, draw, KX_PYMETHODDEF_DOC(KX_NavMeshObject, draw,
"draw(): navigation mesh debug drawing\n") "draw(mode): navigation mesh debug drawing\n"
"mode: WALLS, POLYS, TRIS\n")
{ {
DrawNavMesh(); char* mode;
NavMeshRenderMode renderMode = RM_TRIS;
if (PyArg_ParseTuple(args,"s:rebuild",&mode))
{
STR_String mode_str(mode);
if (mode_str.IsEqualNoCase("WALLS"))
renderMode = RM_WALLS;
else if (mode_str.IsEqualNoCase("POLYS"))
renderMode = RM_POLYS;
else if (mode_str.IsEqualNoCase("TRIS"))
renderMode = RM_TRIS;
}
DrawNavMesh(renderMode);
Py_RETURN_NONE;
}
KX_PYMETHODDEF_DOC_NOARGS(KX_NavMeshObject, rebuild,
"rebuild(): rebuild navigation mesh\n")
{
BuildNavMesh();
Py_RETURN_NONE; Py_RETURN_NONE;
} }

@ -60,7 +60,9 @@ public:
dtStatNavMesh* GetNavMesh(); dtStatNavMesh* GetNavMesh();
int FindPath(const MT_Point3& from, const MT_Point3& to, float* path, int maxPathLen); int FindPath(const MT_Point3& from, const MT_Point3& to, float* path, int maxPathLen);
float Raycast(const MT_Point3& from, const MT_Point3& to); float Raycast(const MT_Point3& from, const MT_Point3& to);
void DrawNavMesh();
enum NavMeshRenderMode {RM_WALLS, RM_POLYS, RM_TRIS};
void DrawNavMesh(NavMeshRenderMode mode);
void DrawPath(const float *path, int pathLen, const MT_Vector3& color); void DrawPath(const float *path, int pathLen, const MT_Vector3& color);
MT_Point3 TransformToLocalCoords(const MT_Point3& wpos); MT_Point3 TransformToLocalCoords(const MT_Point3& wpos);
@ -72,7 +74,8 @@ public:
KX_PYMETHOD_DOC(KX_NavMeshObject, findPath); KX_PYMETHOD_DOC(KX_NavMeshObject, findPath);
KX_PYMETHOD_DOC(KX_NavMeshObject, raycast); KX_PYMETHOD_DOC(KX_NavMeshObject, raycast);
KX_PYMETHOD_DOC_NOARGS(KX_NavMeshObject, draw); KX_PYMETHOD_DOC(KX_NavMeshObject, draw);
KX_PYMETHOD_DOC_NOARGS(KX_NavMeshObject, rebuild);
#endif #endif
}; };

@ -166,8 +166,9 @@ static float interpolateToi(float a, const float* dir, const float* toi, const i
return 0; return 0;
} }
KX_ObstacleSimulation::KX_ObstacleSimulation(MT_Scalar levelHeight) KX_ObstacleSimulation::KX_ObstacleSimulation(MT_Scalar levelHeight, bool enableVisualization)
: m_levelHeight(levelHeight) : m_levelHeight(levelHeight)
, m_enableVisualization(enableVisualization)
{ {
} }
@ -276,6 +277,8 @@ void KX_ObstacleSimulation::AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_N
void KX_ObstacleSimulation::DrawObstacles() void KX_ObstacleSimulation::DrawObstacles()
{ {
if (!m_enableVisualization)
return;
static const MT_Vector3 bluecolor(0,0,1); static const MT_Vector3 bluecolor(0,0,1);
static const MT_Vector3 normal(0.,0.,1.); static const MT_Vector3 normal(0.,0.,1.);
static const int SECTORS_NUM = 32; static const int SECTORS_NUM = 32;
@ -341,8 +344,8 @@ bool KX_ObstacleSimulation::FilterObstacle(KX_Obstacle* activeObst, KX_NavMeshOb
return true; return true;
} }
KX_ObstacleSimulationTOI::KX_ObstacleSimulationTOI(MT_Scalar levelHeight): KX_ObstacleSimulationTOI::KX_ObstacleSimulationTOI(MT_Scalar levelHeight, bool enableVisualization):
KX_ObstacleSimulation(levelHeight), KX_ObstacleSimulation(levelHeight, enableVisualization),
m_avoidSteps(32), m_avoidSteps(32),
m_minToi(0.5f), m_minToi(0.5f),
m_maxToi(1.2f), m_maxToi(1.2f),

@ -74,11 +74,12 @@ protected:
std::vector<KX_Obstacle*> m_obstacles; std::vector<KX_Obstacle*> m_obstacles;
MT_Scalar m_levelHeight; MT_Scalar m_levelHeight;
bool m_enableVisualization;
virtual KX_Obstacle* CreateObstacle(KX_GameObject* gameobj); virtual KX_Obstacle* CreateObstacle(KX_GameObject* gameobj);
bool FilterObstacle(KX_Obstacle* activeObstacle, KX_NavMeshObject* activeNavMeshObj, KX_Obstacle* otherObstacle); bool FilterObstacle(KX_Obstacle* activeObstacle, KX_NavMeshObject* activeNavMeshObj, KX_Obstacle* otherObstacle);
public: public:
KX_ObstacleSimulation(MT_Scalar levelHeight); KX_ObstacleSimulation(MT_Scalar levelHeight, bool enableVisualization);
virtual ~KX_ObstacleSimulation(); virtual ~KX_ObstacleSimulation();
void DrawObstacles(); void DrawObstacles();
@ -117,7 +118,7 @@ protected:
std::vector<TOICircle*> m_toiCircles; // TOI circles (one per active agent) std::vector<TOICircle*> m_toiCircles; // TOI circles (one per active agent)
virtual KX_Obstacle* CreateObstacle(KX_GameObject* gameobj); virtual KX_Obstacle* CreateObstacle(KX_GameObject* gameobj);
public: public:
KX_ObstacleSimulationTOI(MT_Scalar levelHeight); KX_ObstacleSimulationTOI(MT_Scalar levelHeight, bool enableVisualization);
~KX_ObstacleSimulationTOI(); ~KX_ObstacleSimulationTOI();
virtual void AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj, virtual void AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
MT_Vector3& velocity, MT_Scalar maxDeltaSpeed,MT_Scalar maxDeltaAngle); MT_Vector3& velocity, MT_Scalar maxDeltaSpeed,MT_Scalar maxDeltaAngle);

@ -210,11 +210,12 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
m_rootnode = NULL; m_rootnode = NULL;
m_bucketmanager=new RAS_BucketManager(); m_bucketmanager=new RAS_BucketManager();
bool showObstacleSimulation = scene->gm.flag & GAME_SHOW_OBSTACLE_SIMULATION;
switch (scene->gm.obstacleSimulation) switch (scene->gm.obstacleSimulation)
{ {
case OBSTSIMULATION_TOI: case OBSTSIMULATION_TOI:
m_obstacleSimulation = new KX_ObstacleSimulationTOI((MT_Scalar)scene->gm.levelHeight);
m_obstacleSimulation = new KX_ObstacleSimulationTOI((MT_Scalar)scene->gm.levelHeight, showObstacleSimulation);
break; break;
default: default:
m_obstacleSimulation = NULL; m_obstacleSimulation = NULL;

@ -48,13 +48,14 @@ KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj,
int mode, int mode,
KX_GameObject *target, KX_GameObject *target,
KX_GameObject *navmesh, KX_GameObject *navmesh,
MT_Scalar distance, float distance,
MT_Scalar velocity, float velocity,
MT_Scalar acceleration, float acceleration,
MT_Scalar turnspeed, float turnspeed,
bool isSelfTerminated, bool isSelfTerminated,
int pathUpdatePeriod, int pathUpdatePeriod,
KX_ObstacleSimulation* simulation) : KX_ObstacleSimulation* simulation,
bool enableVisualization) :
SCA_IActuator(gameobj, KX_ACT_STEERING), SCA_IActuator(gameobj, KX_ACT_STEERING),
m_mode(mode), m_mode(mode),
m_target(target), m_target(target),
@ -67,6 +68,7 @@ KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj,
m_updateTime(0), m_updateTime(0),
m_isActive(false), m_isActive(false),
m_simulation(simulation), m_simulation(simulation),
m_enableVisualization(enableVisualization),
m_obstacle(NULL), m_obstacle(NULL),
m_pathLen(0), m_pathLen(0),
m_wayPointIdx(-1) m_wayPointIdx(-1)
@ -111,13 +113,11 @@ bool KX_SteeringActuator::UnlinkObject(SCA_IObject* clientobj)
{ {
if (clientobj == m_target) if (clientobj == m_target)
{ {
// this object is being deleted, we cannot continue to use it.
m_target = NULL; m_target = NULL;
return true; return true;
} }
else if (clientobj == m_navmesh) else if (clientobj == m_navmesh)
{ {
// this object is being deleted, we cannot continue to useit.
m_navmesh = NULL; m_navmesh = NULL;
return true; return true;
} }
@ -229,10 +229,13 @@ bool KX_SteeringActuator::Update(double curtime, bool frame)
steervec = waypoint - mypos; steervec = waypoint - mypos;
apply_steerforce = true; apply_steerforce = true;
//debug draw
static const MT_Vector3 PATH_COLOR(1,0,0);
m_navmesh->DrawPath(m_path, m_pathLen, PATH_COLOR);
if (m_enableVisualization)
{
//debug draw
static const MT_Vector3 PATH_COLOR(1,0,0);
m_navmesh->DrawPath(m_path, m_pathLen, PATH_COLOR);
}
} }
} }
@ -251,10 +254,12 @@ bool KX_SteeringActuator::Update(double curtime, bool frame)
//adjust velocity to avoid obstacles //adjust velocity to avoid obstacles
if (m_simulation && m_obstacle && !newvel.fuzzyZero()) if (m_simulation && m_obstacle && !newvel.fuzzyZero())
{ {
KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector3(1.,0.,0.)); if (m_enableVisualization)
KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector3(1.,0.,0.));
m_simulation->AdjustObstacleVelocity(m_obstacle, m_mode!=KX_STEERING_PATHFOLLOWING ? m_navmesh : NULL, m_simulation->AdjustObstacleVelocity(m_obstacle, m_mode!=KX_STEERING_PATHFOLLOWING ? m_navmesh : NULL,
newvel, m_acceleration*delta, m_turnspeed/180.0f*M_PI*delta); newvel, m_acceleration*delta, m_turnspeed/180.0f*M_PI*delta);
KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector3(0.,1.,0.)); if (m_enableVisualization)
KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector3(0.,1.,0.));
} }
if (isdyna) if (isdyna)
@ -313,7 +318,16 @@ PyMethodDef KX_SteeringActuator::Methods[] = {
}; };
PyAttributeDef KX_SteeringActuator::Attributes[] = { PyAttributeDef KX_SteeringActuator::Attributes[] = {
KX_PYATTRIBUTE_INT_RW("bevaiour", KX_STEERING_NODEF+1, KX_STEERING_MAX-1, true, KX_SteeringActuator, m_mode),
KX_PYATTRIBUTE_RW_FUNCTION("target", KX_SteeringActuator, pyattr_get_target, pyattr_set_target), KX_PYATTRIBUTE_RW_FUNCTION("target", KX_SteeringActuator, pyattr_get_target, pyattr_set_target),
KX_PYATTRIBUTE_RW_FUNCTION("navmesh", KX_SteeringActuator, pyattr_get_navmesh, pyattr_set_navmesh),
KX_PYATTRIBUTE_FLOAT_RW("distance", 0.0f, 1000.0f, KX_SteeringActuator, m_distance),
KX_PYATTRIBUTE_FLOAT_RW("velocity", 0.0f, 1000.0f, KX_SteeringActuator, m_velocity),
KX_PYATTRIBUTE_FLOAT_RW("acceleration", 0.0f, 1000.0f, KX_SteeringActuator, m_acceleration),
KX_PYATTRIBUTE_FLOAT_RW("turnspeed", 0.0f, 720.0f, KX_SteeringActuator, m_turnspeed),
KX_PYATTRIBUTE_BOOL_RW("selfterminated", KX_SteeringActuator, m_isSelfTerminated),
KX_PYATTRIBUTE_BOOL_RW("enableVisualization", KX_SteeringActuator, m_enableVisualization),
KX_PYATTRIBUTE_INT_RW("pathUpdatePeriod", -1, 100000, true, KX_SteeringActuator, m_pathUpdatePeriod),
{ NULL } //Sentinel { NULL } //Sentinel
}; };
@ -345,6 +359,34 @@ int KX_SteeringActuator::pyattr_set_target(void *self, const struct KX_PYATTRIBU
return PY_SET_ATTR_SUCCESS; return PY_SET_ATTR_SUCCESS;
} }
PyObject* KX_SteeringActuator::pyattr_get_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
if (!actuator->m_navmesh)
Py_RETURN_NONE;
else
return actuator->m_navmesh->GetProxy();
}
int KX_SteeringActuator::pyattr_set_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
KX_GameObject *gameobj;
if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
if (actuator->m_navmesh != NULL)
actuator->m_navmesh->UnregisterActuator(actuator);
actuator->m_navmesh = dynamic_cast<KX_NavMeshObject*>(gameobj);
if (actuator->m_navmesh)
actuator->m_navmesh->RegisterActuator(actuator);
return PY_SET_ATTR_SUCCESS;
}
#endif // DISABLE_PYTHON #endif // DISABLE_PYTHON
/* eof */ /* eof */

@ -53,16 +53,17 @@ class KX_SteeringActuator : public SCA_IActuator
KX_GameObject *m_target; KX_GameObject *m_target;
KX_NavMeshObject *m_navmesh; KX_NavMeshObject *m_navmesh;
int m_mode; int m_mode;
MT_Scalar m_distance; float m_distance;
MT_Scalar m_velocity; float m_velocity;
MT_Scalar m_acceleration; float m_acceleration;
MT_Scalar m_turnspeed; float m_turnspeed;
KX_ObstacleSimulation* m_simulation; KX_ObstacleSimulation* m_simulation;
KX_Obstacle* m_obstacle; KX_Obstacle* m_obstacle;
double m_updateTime; double m_updateTime;
bool m_isActive; bool m_isActive;
bool m_isSelfTerminated; bool m_isSelfTerminated;
bool m_enableVisualization;
float m_path[MAX_PATH_LENGTH*3]; float m_path[MAX_PATH_LENGTH*3];
int m_pathLen; int m_pathLen;
int m_pathUpdatePeriod; int m_pathUpdatePeriod;
@ -82,13 +83,14 @@ public:
int mode, int mode,
KX_GameObject *target, KX_GameObject *target,
KX_GameObject *navmesh, KX_GameObject *navmesh,
MT_Scalar distance, float distance,
MT_Scalar velocity, float velocity,
MT_Scalar acceleration, float acceleration,
MT_Scalar turnspeed, float turnspeed,
bool isSelfTerminated, bool isSelfTerminated,
int pathUpdatePeriod, int pathUpdatePeriod,
KX_ObstacleSimulation* simulation); KX_ObstacleSimulation* simulation,
bool enableVisualization);
virtual ~KX_SteeringActuator(); virtual ~KX_SteeringActuator();
virtual bool Update(double curtime, bool frame); virtual bool Update(double curtime, bool frame);
@ -106,6 +108,9 @@ public:
/* These are used to get and set m_target */ /* These are used to get and set m_target */
static PyObject* pyattr_get_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
#endif // DISABLE_PYTHON #endif // DISABLE_PYTHON