Commit: 7d99a4ded9d3d24c24ea2d5bcc488469cf60fa4a
Author: Jorge Bernal
Date:   Wed Jun 25 15:47:30 2014 -0700
https://developer.blender.org/rB7d99a4ded9d3d24c24ea2d5bcc488469cf60fa4a

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

===================================================================

M       doc/python_api/rst/bge.logic.rst
A       doc/python_api/rst/bge_types/bge.types.KX_MouseActuator.rst
M       source/blender/blenkernel/intern/sca.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/writefile.c
M       source/blender/editors/space_logic/logic_window.c
M       source/blender/makesdna/DNA_actuator_types.h
M       source/blender/makesrna/intern/rna_actuator.c
M       source/gameengine/Converter/KX_ConvertActuators.cpp
M       source/gameengine/GameLogic/SCA_IActuator.h
M       source/gameengine/Ketsji/CMakeLists.txt
A       source/gameengine/Ketsji/KX_MouseActuator.cpp
A       source/gameengine/Ketsji/KX_MouseActuator.h
M       source/gameengine/Ketsji/KX_PythonInit.cpp
M       source/gameengine/Ketsji/KX_PythonInitTypes.cpp

===================================================================

diff --git a/doc/python_api/rst/bge.logic.rst b/doc/python_api/rst/bge.logic.rst
index b378064..4e0d317 100644
--- a/doc/python_api/rst/bge.logic.rst
+++ b/doc/python_api/rst/bge.logic.rst
@@ -72,6 +72,7 @@ See the actuator's reference for available methods
    * :class:`~bge.types.KX_CameraActuator`
    * :class:`~bge.types.KX_ConstraintActuator`
    * :class:`~bge.types.KX_GameActuator`
+   * :class:`~bge.types.KX_MouseActuator`
    * :class:`~bge.types.KX_NetworkMessageActuator`
    * :class:`~bge.types.KX_ObjectActuator`
    * :class:`~bge.types.KX_ParentActuator`
@@ -764,6 +765,16 @@ See :class:`bge.types.KX_GameActuator`
 .. data:: KX_GAME_SAVECFG
 .. data:: KX_GAME_LOADCFG
 
+.. _mouse-actuator:
+
+---------------
+Mouse Actuator
+---------------
+
+.. data:: KX_ACT_MOUSE_OBJECT_AXIS_X
+.. data:: KX_ACT_MOUSE_OBJECT_AXIS_Y
+.. data:: KX_ACT_MOUSE_OBJECT_AXIS_Z
+
 ---------------
 Parent Actuator
 ---------------
diff --git a/doc/python_api/rst/bge_types/bge.types.KX_MouseActuator.rst 
b/doc/python_api/rst/bge_types/bge.types.KX_MouseActuator.rst
new file mode 100644
index 0000000..cc3ce49
--- /dev/null
+++ b/doc/python_api/rst/bge_types/bge.types.KX_MouseActuator.rst
@@ -0,0 +1,103 @@
+KX_MouseActuator(SCA_IActuator)
+====================================
+
+.. module:: bge.types
+
+base class --- :class:`SCA_IActuator`
+
+.. class:: KX_MouseActuator(SCA_IActuator)
+
+   The mouse actuator gives control over the visibility of the mouse cursor 
and rotates the parent object according to mouse movement.
+
+   .. method:: reset()
+
+      Undoes the rotation caused by the mouse actuator.
+
+   .. attribute:: visible
+
+      The visibility of the mouse cursor.
+
+      :type: boolean
+
+   .. attribute:: use_axis_x
+
+      Mouse movement along the x axis effects object rotation.
+
+      :type: boolean
+
+   .. attribute:: use_axis_y
+
+      Mouse movement along the y axis effects object rotation.
+
+      :type: boolean
+
+   .. attribute:: threshold
+
+      Amount of movement from the mouse required before rotation is triggered.
+
+      :type: list (vector of 2 floats)
+
+      The values in the list should be between 0.0 and 0.5.
+
+   .. attribute:: reset_x
+
+      Mouse is locked to the center of the screen on the x axis.
+
+      :type: boolean
+
+   .. attribute:: reset_y
+
+      Mouse is locked to the center of the screen on the y axis.
+
+      :type: boolean
+
+   .. attribute:: object_axis
+
+      The object's 3D axis to rotate with the mouse movement. ([x, y])
+
+      :type: list (vector of 2 integers from 0 to 2)
+
+      * KX_ACT_MOUSE_OBJECT_AXIS_X
+      * KX_ACT_MOUSE_OBJECT_AXIS_Y
+      * KX_ACT_MOUSE_OBJECT_AXIS_Z
+
+   .. attribute:: local_x
+
+      Rotation caused by mouse movement along the x axis is local.
+
+      :type: boolean
+
+   .. attribute:: local_y
+
+      Rotation caused by mouse movement along the y axis is local.
+
+      :type: boolean
+
+   .. attribute:: sensitivity
+
+      The amount of rotation caused by mouse movement along the x and y axis.
+
+      :type: list (vector of 2 floats)
+
+      Negative values invert the rotation.
+
+   .. attribute:: limit_x
+
+      The minimum and maximum angle of rotation caused by mouse movement along 
the x axis in degrees.
+      limit_x[0] is minimum, limit_x[1] is maximum.
+
+      :type: list (vector of 2 floats)
+
+   .. attribute:: limit_y
+
+      The minimum and maximum angle of rotation caused by mouse movement along 
the y axis in degrees.
+      limit_y[0] is minimum, limit_y[1] is maximum.
+
+      :type: list (vector of 2 floats)
+
+   .. attribute:: angle
+
+      The current rotational offset caused by the mouse actuator in degrees.
+
+      :type: list (vector of 2 floats)
+
diff --git a/source/blender/blenkernel/intern/sca.c 
b/source/blender/blenkernel/intern/sca.c
index b0b64ca..1310162 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 b0edb41..9175315 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 4513978..a0198a6 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 7f0fadc..b52d6265 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 99f0c99..5ab799a 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_MOUS

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to