diff options
author | Jorge Bernal <jbernalmartinez@gmail.com> | 2014-06-26 02:47:30 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2014-06-26 02:47:37 +0400 |
commit | 7d99a4ded9d3d24c24ea2d5bcc488469cf60fa4a (patch) | |
tree | f56a5cb74013a4e0520e668570e9fe9f6d1d4a6a /source/blender | |
parent | 11d1fea2850dd4071268034b133c924ce6396df9 (diff) |
BGE: New Mouse Actuator
Disclaimer: The author of this patch is Geoffrey Gollmer (gomer). I only updated the patch to the current git master status, reworked several parts to fit well with current coding style and applied several fixes.
This actuator allows users to show/hide the mouse cursor using logic bricks, as well as control object rotation with a mouse in the BGE.
The mouse rotation is flexible enough to allow any type of mouse look, as well as banking for flight controls.
{F94520}
{F91859}
Blend file for testing Mouse actuator (with default parameters and crosshair): {F94920}
Reviewers: moguri
Reviewed By: moguri
CC: gomer, lordodin
Differential Revision: https://developer.blender.org/D559
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/sca.c | 10 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 3 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_logic/logic_window.c | 68 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_actuator_types.h | 31 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_actuator.c | 131 |
6 files changed, 246 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index b0b64cac802..1310162483e 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -391,6 +391,7 @@ void init_actuator(bActuator *act) bSoundActuator *sa; bSteeringActuator *sta; bArmatureActuator *arma; + bMouseActuator *ma; if (act->data) MEM_freeN(act->data); act->data= NULL; @@ -477,6 +478,15 @@ void init_actuator(bActuator *act) sta->flag = ACT_STEERING_AUTOMATICFACING; sta->facingaxis = 1; break; + case ACT_MOUSE: + ma = act->data = MEM_callocN(sizeof( bMouseActuator ), "mouse act"); + ma->flag = ACT_MOUSE_VISIBLE|ACT_MOUSE_USE_AXIS_X|ACT_MOUSE_USE_AXIS_Y|ACT_MOUSE_RESET_X|ACT_MOUSE_RESET_Y|ACT_MOUSE_LOCAL_Y; + ma->sensitivity[0] = ma->sensitivity[1] = 2.f; + ma->object_axis[0] = ACT_MOUSE_OBJECT_AXIS_Z; + ma->object_axis[1] = ACT_MOUSE_OBJECT_AXIS_X; + ma->limit_y[0] = DEG2RADF(-90.0f); + ma->limit_y[1] = DEG2RADF(90.0f); + break; default: ; /* this is very severe... I cannot make any memory for this */ /* logic brick... */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index b0edb41f96d..91753158d02 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4450,6 +4450,9 @@ static void lib_link_object(FileData *fd, Main *main) steeringa->target = newlibadr(fd, ob->id.lib, steeringa->target); steeringa->navmesh = newlibadr(fd, ob->id.lib, steeringa->navmesh); } + else if(act->type == ACT_MOUSE) { + /* bMouseActuator *moa= act->data; */ + } } { diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 45139789f1e..a0198a687a2 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1237,6 +1237,9 @@ static void write_actuators(WriteData *wd, ListBase *lb) case ACT_STEERING: writestruct(wd, DATA, "bSteeringActuator", 1, act->data); break; + case ACT_MOUSE: + writestruct(wd, DATA, "bMouseActuator", 1, act->data); + break; default: ; /* error: don't know how to write this file */ } diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c index 7f0fadc07ef..b52d6265800 100644 --- a/source/blender/editors/space_logic/logic_window.c +++ b/source/blender/editors/space_logic/logic_window.c @@ -519,6 +519,8 @@ static const char *actuator_name(int type) return N_("Armature"); case ACT_STEERING: return N_("Steering"); + case ACT_MOUSE: + return N_("Mouse"); } return N_("Unknown"); } @@ -2177,6 +2179,68 @@ static void draw_actuator_steering(uiLayout *layout, PointerRNA *ptr) } } +static void draw_actuator_mouse(uiLayout *layout, PointerRNA *ptr) +{ + uiLayout *row, *col, *subcol, *split, *subsplit; + + uiItemR(layout, ptr, "mode", 0, NULL, 0); + + switch (RNA_enum_get(ptr, "mode")) { + case ACT_MOUSE_VISIBILITY: + row = uiLayoutRow(layout, 0); + uiItemR(row, ptr, "visible", UI_ITEM_R_TOGGLE, NULL, 0); + break; + + case ACT_MOUSE_LOOK: + /* X axis */ + row = uiLayoutRow(layout, 0); + col = uiLayoutColumn(row, 1); + + uiItemR(col, ptr, "use_axis_x", UI_ITEM_R_TOGGLE, NULL, 0); + + subcol = uiLayoutColumn(col, 1); + uiLayoutSetActive(subcol, RNA_boolean_get(ptr, "use_axis_x")==1); + uiItemR(subcol, ptr, "sensitivity_x", 0, NULL, 0); + uiItemR(subcol, ptr, "threshold_x", 0, NULL, 0); + + uiItemR(subcol, ptr, "min_x", 0, NULL, 0); + uiItemR(subcol, ptr, "max_x", 0, NULL, 0); + + uiItemR(subcol, ptr, "object_axis_x", 0, NULL, 0); + + /* Y Axis */ + col = uiLayoutColumn(row, 1); + + uiItemR(col, ptr, "use_axis_y", UI_ITEM_R_TOGGLE, NULL, 0); + + subcol = uiLayoutColumn(col, 1); + uiLayoutSetActive(subcol, RNA_boolean_get(ptr, "use_axis_y")==1); + uiItemR(subcol, ptr, "sensitivity_y", 0, NULL, 0); + uiItemR(subcol, ptr, "threshold_y", 0, NULL, 0); + + uiItemR(subcol, ptr, "min_y", 0, NULL, 0); + uiItemR(subcol, ptr, "max_y", 0, NULL, 0); + + uiItemR(subcol, ptr, "object_axis_y", 0, NULL, 0); + + /* Lower options */ + row = uiLayoutRow(layout, 0); + split = uiLayoutSplit(row, 0.5, 0); + + subsplit = uiLayoutSplit(split, 0.5, 1); + uiLayoutSetActive(subsplit, RNA_boolean_get(ptr, "use_axis_x")==1); + uiItemR(subsplit, ptr, "local_x", UI_ITEM_R_TOGGLE, NULL, 0); + uiItemR(subsplit, ptr, "reset_x", UI_ITEM_R_TOGGLE, NULL, 0); + + subsplit = uiLayoutSplit(split, 0.5, 1); + uiLayoutSetActive(subsplit, RNA_boolean_get(ptr, "use_axis_y")==1); + uiItemR(subsplit, ptr, "local_y", UI_ITEM_R_TOGGLE, NULL, 0); + uiItemR(subsplit, ptr, "reset_y", UI_ITEM_R_TOGGLE, NULL, 0); + + break; + } +} + static void draw_brick_actuator(uiLayout *layout, PointerRNA *ptr, bContext *C) { uiLayout *box; @@ -2241,6 +2305,10 @@ static void draw_brick_actuator(uiLayout *layout, PointerRNA *ptr, bContext *C) break; case ACT_STEERING: draw_actuator_steering(box, ptr); + break; + case ACT_MOUSE: + draw_actuator_mouse(box, ptr); + break; } } diff --git a/source/blender/makesdna/DNA_actuator_types.h b/source/blender/makesdna/DNA_actuator_types.h index 99f0c999a29..5ab799a75e5 100644 --- a/source/blender/makesdna/DNA_actuator_types.h +++ b/source/blender/makesdna/DNA_actuator_types.h @@ -245,6 +245,18 @@ typedef struct bSteeringActuator { struct Object *navmesh; } bSteeringActuator; +typedef struct bMouseActuator { + short type; /* 0=Visibility, 1=Look */ + short flag; + + int object_axis[2]; + float threshold[2]; + float sensitivity[2]; + float limit_x[2]; + float limit_y[2]; +} bMouseActuator; + + typedef struct bActuator { struct bActuator *next, *prev, *mynew; short type; @@ -314,6 +326,7 @@ typedef struct bActuator { #define ACT_STATE 22 #define ACT_ARMATURE 23 #define ACT_STEERING 24 +#define ACT_MOUSE 25 /* actuator flag */ #define ACT_SHOW 1 @@ -542,4 +555,22 @@ typedef struct bActuator { #define ACT_STEERING_AUTOMATICFACING 4 #define ACT_STEERING_NORMALUP 8 +/* mouseactuator->type */ +#define ACT_MOUSE_VISIBILITY 0 +#define ACT_MOUSE_LOOK 1 + +/* mouseactuator->flag */ +#define ACT_MOUSE_VISIBLE (1 << 0) +#define ACT_MOUSE_USE_AXIS_X (1 << 1) +#define ACT_MOUSE_USE_AXIS_Y (1 << 2) +#define ACT_MOUSE_RESET_X (1 << 3) +#define ACT_MOUSE_RESET_Y (1 << 4) +#define ACT_MOUSE_LOCAL_X (1 << 5) +#define ACT_MOUSE_LOCAL_Y (1 << 6) + +/* mouseactuator->object_axis */ +#define ACT_MOUSE_OBJECT_AXIS_X 0 +#define ACT_MOUSE_OBJECT_AXIS_Y 1 +#define ACT_MOUSE_OBJECT_AXIS_Z 2 + #endif /* __DNA_ACTUATOR_TYPES_H__ */ diff --git a/source/blender/makesrna/intern/rna_actuator.c b/source/blender/makesrna/intern/rna_actuator.c index fd04fb46cf1..3cc530ec368 100644 --- a/source/blender/makesrna/intern/rna_actuator.c +++ b/source/blender/makesrna/intern/rna_actuator.c @@ -55,6 +55,7 @@ static EnumPropertyItem actuator_type_items[] = { {ACT_2DFILTER, "FILTER_2D", 0, "Filter 2D", ""}, {ACT_GAME, "GAME", 0, "Game", ""}, {ACT_MESSAGE, "MESSAGE", 0, "Message", ""}, + {ACT_MOUSE, "MOUSE", 0, "Mouse", ""}, {ACT_OBJECT, "MOTION", 0, "Motion", ""}, {ACT_PARENT, "PARENT", 0, "Parent", ""}, {ACT_PROPERTY, "PROPERTY", 0, "Property", ""}, @@ -110,6 +111,8 @@ static StructRNA *rna_Actuator_refine(struct PointerRNA *ptr) return &RNA_ArmatureActuator; case ACT_STEERING: return &RNA_SteeringActuator; + case ACT_MOUSE: + return &RNA_MouseActuator; default: return &RNA_Actuator; } @@ -459,6 +462,7 @@ EnumPropertyItem *rna_Actuator_type_itemf(bContext *C, PointerRNA *ptr, Property RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_2DFILTER); RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_GAME); RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_MESSAGE); + RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_MOUSE); RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_OBJECT); RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_PARENT); RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_PROPERTY); @@ -2038,6 +2042,132 @@ static void rna_def_steering_actuator(BlenderRNA *brna) RNA_def_property_update(prop, NC_LOGIC, NULL); } +static void rna_def_mouse_actuator(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + static EnumPropertyItem prop_type_items[] = { + {ACT_MOUSE_VISIBILITY, "VISIBILITY", 0, "Visibility", ""}, + {ACT_MOUSE_LOOK, "LOOK", 0, "Look", ""}, + {0, NULL, 0, NULL, NULL} + }; + + static EnumPropertyItem prop_object_axis_items[] = { + {ACT_MOUSE_OBJECT_AXIS_X, "OBJECT_AXIS_X", 0, "X Axis", ""}, + {ACT_MOUSE_OBJECT_AXIS_Y, "OBJECT_AXIS_Y", 0, "Y Axis", ""}, + {ACT_MOUSE_OBJECT_AXIS_Z, "OBJECT_AXIS_Z", 0, "Z Axis", ""}, + {0, NULL, 0, NULL, NULL} + }; + + srna = RNA_def_struct(brna, "MouseActuator", "Actuator"); + RNA_def_struct_ui_text(srna, "Mouse Actuator", "Actuator to .."); + RNA_def_struct_sdna_from(srna, "bMouseActuator", "data"); + + prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "type"); + RNA_def_property_enum_items(prop, prop_type_items); + RNA_def_property_ui_text(prop, "Mode", ""); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + /* Visibility */ + prop = RNA_def_property(srna, "visible", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_VISIBLE); + RNA_def_property_ui_text(prop, "Visible", "Make mouse cursor visible"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + /* Mouse Look */ + prop = RNA_def_property(srna, "use_axis_x", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_USE_AXIS_X); + RNA_def_property_ui_text(prop, "Use X Axis", "Calculate mouse movement on the X axis"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "use_axis_y", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_USE_AXIS_Y); + RNA_def_property_ui_text(prop, "Use Y Axis", "Calculate mouse movement on the Y axis"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "reset_x", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_RESET_X); + RNA_def_property_ui_text(prop, "Reset", "Reset the cursor's X position to the center of the screen space after calculating"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "reset_y", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_RESET_Y); + RNA_def_property_ui_text(prop, "Reset", "Reset the cursor's Y position to the center of the screen space after calculating"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "local_x", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_LOCAL_X); + RNA_def_property_ui_text(prop, "Local", "Apply rotation locally"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "local_y", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_LOCAL_Y); + RNA_def_property_ui_text(prop, "Local", "Apply rotation locally"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "threshold_x", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "threshold[0]"); + RNA_def_property_ui_range(prop, 0, 0.5, 1, 3); + RNA_def_property_ui_text(prop, "Threshold", "The amount of X motion before mouse movement will register"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "threshold_y", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "threshold[1]"); + RNA_def_property_ui_range(prop, 0, 0.5, 1, 3); + RNA_def_property_ui_text(prop, "Threshold", "The amount of Y motion before mouse movement will register"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "object_axis_x", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "object_axis[0]"); + RNA_def_property_enum_items(prop, prop_object_axis_items); + RNA_def_property_ui_text(prop, "Obj Axis", "Local object axis mouse movement in the X direction will apply to"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "object_axis_y", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "object_axis[1]"); + RNA_def_property_enum_items(prop, prop_object_axis_items); + RNA_def_property_ui_text(prop, "Obj Axis", "The object axis mouse movement in the Y direction will apply to"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "sensitivity_x", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "sensitivity[0]"); + RNA_def_property_ui_range(prop, -100.0, 100.0, 0.2, 3); + RNA_def_property_ui_text(prop, "Sensitivity", "Set the sensitivity of the X axis"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "sensitivity_y", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "sensitivity[1]"); + RNA_def_property_ui_range(prop, -100.0, 100.0, 0.2, 3); + RNA_def_property_ui_text(prop, "Sensitivity", "Set the sensitivity of the Y axis"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "min_x", PROP_FLOAT, PROP_ANGLE); + RNA_def_property_float_sdna(prop, NULL, "limit_x[0]"); + RNA_def_property_ui_range(prop, DEG2RADF(-3600.0f), 0.0, 9, 3); + RNA_def_property_ui_text(prop, "min", "The maximum negative rotation allowed by x mouse movement (0 for infinite)"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "max_x", PROP_FLOAT, PROP_ANGLE); + RNA_def_property_float_sdna(prop, NULL, "limit_x[1]"); + RNA_def_property_ui_range(prop, 0.0, DEG2RADF(3600.0f), 9, 3); + RNA_def_property_ui_text(prop, "max", "The maximum positive rotation allowed by x mouse movement (0 for infinite)"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "min_y", PROP_FLOAT, PROP_ANGLE); + RNA_def_property_float_sdna(prop, NULL, "limit_y[0]"); + RNA_def_property_ui_range(prop, DEG2RADF(-3600.0f), 0.0, 9, 3); + RNA_def_property_ui_text(prop, "min", "The maximum negative rotation allowed by y mouse movement (0 for infinite)"); + RNA_def_property_update(prop, NC_LOGIC, NULL); + + prop = RNA_def_property(srna, "max_y", PROP_FLOAT, PROP_ANGLE); + RNA_def_property_float_sdna(prop, NULL, "limit_y[1]"); + RNA_def_property_ui_range(prop, 0.0, DEG2RADF(3600.0f), 9, 3); + RNA_def_property_ui_text(prop, "max", "The maximum positive rotation allowed by y mouse movement (0 for infinite)"); + RNA_def_property_update(prop, NC_LOGIC, NULL); +} + void RNA_def_actuator(BlenderRNA *brna) { rna_def_actuator(brna); @@ -2059,6 +2189,7 @@ void RNA_def_actuator(BlenderRNA *brna) rna_def_state_actuator(brna); rna_def_armature_actuator(brna); rna_def_steering_actuator(brna); + rna_def_mouse_actuator(brna); } #endif |