Added parameters for obstacle avoidance simulation: for object - flag for creation representation in simulation(OB_HASOBSTACLE) and obstacle radius (obstacleRad), for scene - obstacle simulation type (obstacleSimulation); added ui for new parameters

This commit is contained in:
Nick Samarin 2010-06-10 00:19:06 +00:00
parent 9d1b8bf0f8
commit 0183d55108
11 changed files with 111 additions and 8 deletions

View File

@ -194,7 +194,31 @@ class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel):
if wide_ui:
col = split.column()
col.prop(game, "collision_compound", text="Compound")
class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel):
bl_label = "Create obstacle"
def poll(self, context):
game = context.object.game
rd = context.scene.render
return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine == 'BLENDER_GAME')
def draw_header(self, context):
game = context.active_object.game
self.layout.prop(game, "create_obstacle", text="")
def draw(self, context):
layout = self.layout
game = context.active_object.game
wide_ui = context.region.width > narrowui
layout.active = game.create_obstacle
split = layout.split()
col = split.column()
col.prop(game, "obstacle_radius", text="Radius")
class RenderButtonsPanel(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
@ -510,10 +534,21 @@ class WORLD_PT_game_physics(WorldButtonsPanel):
col.label(text="Logic Steps:")
col.prop(gs, "logic_step_max", text="Max")
class WORLD_PT_game_physics_obstacles(WorldButtonsPanel):
bl_label = "Obstacle simulation"
def draw(self, context):
layout = self.layout
gs = context.scene.game_data
wide_ui = context.region.width > narrowui
layout.prop(gs, "obstacle_simulation", text = "Type")
classes = [
PHYSICS_PT_game_physics,
PHYSICS_PT_game_collision_bounds,
PHYSICS_PT_game_obstacles,
RENDER_PT_game,
RENDER_PT_game_player,
@ -525,7 +560,8 @@ classes = [
WORLD_PT_game_context_world,
WORLD_PT_game_world,
WORLD_PT_game_mist,
WORLD_PT_game_physics]
WORLD_PT_game_physics,
WORLD_PT_game_physics_obstacles]
def register():

View File

@ -1028,6 +1028,7 @@ Object *add_only_object(int type, char *name)
ob->margin = 0.0;
/* ob->pad3 == Contact Processing Threshold */
ob->m_contactProcessingThreshold = 1.;
ob->obstacleRad = 1.;
/* NT fluid sim defaults */
ob->fluidsimFlag = 0;

View File

@ -472,6 +472,8 @@ Scene *add_scene(char *name)
sce->gm.flag = GAME_DISPLAY_LISTS;
sce->gm.matmode = GAME_MAT_MULTITEX;
sce->gm.obstacleSimulation= OBSTSIMULATION_NONE;
sound_create_scene(sce);
return sce;

View File

@ -182,6 +182,8 @@ typedef struct Object {
float max_vel; /* clamp the maximum velocity 0.0 is disabled */
float min_vel; /* clamp the maximum velocity 0.0 is disabled */
float m_contactProcessingThreshold;
float obstacleRad;
char pad0[4];
short rotmode; /* rotation mode - uses defines set out in DNA_action_types.h for PoseChannel rotations... */
@ -465,6 +467,7 @@ extern Object workob;
#define OB_OCCLUDER 0x40000
#define OB_SENSOR 0x80000
#define OB_NAVMESH 0x100000
#define OB_HASOBSTACLE 0x200000
/* ob->gameflag2 */
#define OB_NEVER_DO_ACTIVITY_CULLING 1

View File

@ -451,10 +451,11 @@ typedef struct GameData {
* bit 3: (gameengine): Activity culling is enabled.
* bit 5: (gameengine) : enable Bullet DBVT tree for view frustrum culling
*/
short mode, flag, matmode, pad[3];
short mode, flag, matmode, pad[6];
short occlusionRes; /* resolution of occlusion Z buffer in pixel */
short physicsEngine;
short ticrate, maxlogicstep, physubstep, maxphystep;
short obstacleSimulation;
/* standalone player */
struct GameFraming framing;
@ -488,6 +489,10 @@ typedef struct GameData {
#define WOPHY_ODE 4
#define WOPHY_BULLET 5
/* obstacleSimulation */
#define OBSTSIMULATION_NONE 0
#define OBSTSIMULATION_TOI 1
/* GameData.flag */
#define GAME_ENABLE_ALL_FRAMES (1 << 1)
#define GAME_SHOW_DEBUG_PROPS (1 << 2)

View File

@ -1269,6 +1269,15 @@ static void rna_def_object_game_settings(BlenderRNA *brna)
RNA_def_property_pointer_sdna(prop, NULL, "bsoft");
RNA_def_property_ui_text(prop, "Soft Body Settings", "Settings for Bullet soft body simulation");
prop= RNA_def_property(srna, "create_obstacle", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_HASOBSTACLE);
RNA_def_property_ui_text(prop, "Create obstacle", "Create representation for obstacle simulation");
prop= RNA_def_property(srna, "obstacle_radius", PROP_FLOAT, PROP_NONE|PROP_UNIT_LENGTH);
RNA_def_property_float_sdna(prop, NULL, "obstacleRad");
RNA_def_property_range(prop, 0.0, 1000.0);
RNA_def_property_ui_text(prop, "Obstacle Radius", "Radius of object representation in obstacle simulation");
/* state */
prop= RNA_def_property(srna, "state", PROP_BOOLEAN, PROP_LAYER_MEMBER);

View File

@ -1511,6 +1511,11 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
{GAME_MAT_GLSL, "GLSL", 0, "GLSL", "OpenGL shading language shaders"},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem obstacle_simulation_items[] = {
{OBSTSIMULATION_NONE, "NONE", 0, "None", ""},
{OBSTSIMULATION_TOI, "TOI", 0, "TOI", ""},
{0, NULL, 0, NULL, NULL}};
srna= RNA_def_struct(brna, "SceneGameData", NULL);
RNA_def_struct_sdna(srna, "GameData");
RNA_def_struct_nested(brna, srna, "Scene");
@ -1748,6 +1753,13 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_EXTRA_TEX);
RNA_def_property_ui_text(prop, "GLSL Extra Textures", "Use extra textures like normal or specular maps for GLSL rendering");
RNA_def_property_update(prop, NC_SCENE|NA_EDITED, NULL);
/* obstacle simulation */
prop= RNA_def_property(srna, "obstacle_simulation", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "obstacleSimulation");
RNA_def_property_enum_items(prop, obstacle_simulation_items);
RNA_def_property_ui_text(prop, "Obstacle simulation", "Simulation used for obstacle avoidance in the game engine");
RNA_def_property_update(prop, NC_SCENE, NULL);
}
static void rna_def_scene_render_layer(BlenderRNA *brna)

View File

@ -2647,7 +2647,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
for ( i=0;i<objectlist->GetCount();i++)
{
KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i));
if (gameobj->IsDynamic())
struct Object* blenderobject = gameobj->GetBlenderObject();
if (blenderobject->gameflag & OB_HASOBSTACLE)
{
obssimulation->AddObstacleForObj(gameobj);
}

View File

@ -36,8 +36,11 @@
#include "KX_NavMeshObject.h"
#include "KX_PythonInit.h"
#include "DNA_object_types.h"
#include "math.h"
#define M_PI 3.14159265358979323846
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
int sweepCircleCircle(const MT_Vector3& pos0, const MT_Scalar r0, const MT_Vector2& v,
const MT_Vector3& pos1, const MT_Scalar r1,
@ -168,7 +171,7 @@ void KX_ObstacleSimulation::AddObstacleForObj(KX_GameObject* gameobj)
struct Object* blenderobject = gameobj->GetBlenderObject();
obstacle->m_type = KX_OBSTACLE_OBJ;
obstacle->m_shape = KX_OBSTACLE_CIRCLE;
obstacle->m_rad = blenderobject->inertia; //.todo use radius of collision shape bound sphere
obstacle->m_rad = blenderobject->obstacleRad;
obstacle->m_gameObj = gameobj;
}
@ -235,12 +238,21 @@ void KX_ObstacleSimulation::AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_N
void KX_ObstacleSimulation::DrawObstacles()
{
static const MT_Vector3 bluecolor(0,0,1);
static const MT_Vector3 normal(0.,0.,1.);
static const int SECTORS_NUM = 32;
for (size_t i=0; i<m_obstacles.size(); i++)
{
if (m_obstacles[i]->m_shape==KX_OBSTACLE_SEGMENT)
{
KX_RasterizerDrawDebugLine(m_obstacles[i]->m_pos, m_obstacles[i]->m_pos2, bluecolor);
}
/*
else if (m_obstacles[i]->m_shape==KX_OBSTACLE_CIRCLE)
{
KX_RasterizerDrawDebugCircle(m_obstacles[i]->m_pos, m_obstacles[i]->m_rad, bluecolor,
normal.normalized(), SECTORS_NUM);
}*/
}
}

View File

@ -211,7 +211,15 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
m_bucketmanager=new RAS_BucketManager();
m_obstacleSimulation = new KX_ObstacleSimulationTOI;//KX_ObstacleSimulation;
switch (scene->gm.obstacleSimulation)
{
case OBSTSIMULATION_TOI:
m_obstacleSimulation = new KX_ObstacleSimulationTOI;
break;
default:
m_obstacleSimulation = NULL;
}
#ifndef DISABLE_PYTHON
m_attr_dict = PyDict_New(); /* new ref */
@ -1468,7 +1476,8 @@ void KX_Scene::LogicBeginFrame(double curtime)
}
//prepare obstacle simulation for new frame
m_obstacleSimulation->UpdateObstacles();
if (m_obstacleSimulation)
m_obstacleSimulation->UpdateObstacles();
m_logicmgr->BeginFrame(curtime, 1.0/KX_KetsjiEngine::GetTicRate());
}
@ -1899,9 +1908,11 @@ PyMethodDef KX_Scene::Methods[] = {
KX_PYMETHODTABLE(KX_Scene, replace),
KX_PYMETHODTABLE(KX_Scene, suspend),
KX_PYMETHODTABLE(KX_Scene, resume),
KX_PYMETHODTABLE(KX_Scene, drawObstacleSimulation),
/* dict style access */
KX_PYMETHODTABLE(KX_Scene, get),
{NULL,NULL} //Sentinel
};
@ -2225,6 +2236,16 @@ KX_PYMETHODDEF_DOC(KX_Scene, resume,
Py_RETURN_NONE;
}
KX_PYMETHODDEF_DOC(KX_Scene, drawObstacleSimulation,
"drawObstacleSimulation()\n"
"Draw debug visualization of obstacle simulation.\n")
{
if (GetObstacleSimulation())
GetObstacleSimulation()->DrawObstacles();
Py_RETURN_NONE;
}
/* Matches python dict.get(key, [default]) */
KX_PYMETHODDEF_DOC(KX_Scene, get, "")
{

View File

@ -558,6 +558,7 @@ public:
KX_PYMETHOD_DOC(KX_Scene, suspend);
KX_PYMETHOD_DOC(KX_Scene, resume);
KX_PYMETHOD_DOC(KX_Scene, get);
KX_PYMETHOD_DOC(KX_Scene, drawObstacleSimulation);
/* attributes */
static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);