[Bf-blender-cvs] [1bf87fa] master: BGE: TrackTo actuator: increasing up & track axis options

Jorge Bernal noreply at git.blender.org
Tue Jul 15 03:31:41 CEST 2014


Commit: 1bf87fa26c6763ef282ec39b07b678723a7f389b
Author: Jorge Bernal
Date:   Mon Jul 14 17:36:56 2014 -0700
https://developer.blender.org/rB1bf87fa26c6763ef282ec39b07b678723a7f389b

BGE: TrackTo actuator: increasing up & track axis options

This is related to Task T34861 to increase up & track axis options for TrackTo actuator. I've just added it to differential to facilitate an easier review.

With the patch applied you can select X, Y and Z axis for the Up axis, and X, Y, Z, -X, -Y and -Z for the track axis.

Related to the implementation I have used the algorithm from Trackto constrain placed in constrain.c but adapted to be used with MOTO library.

The wiki docs are here (http://wiki.blender.org/index.php/User:Lordloki/Doc:2.6/Manual/Game_Engine/Logic/Actuators/Edit_Object#Trackto_Actuator).

Test file is here: {F97623}

I have also uploaded 2 screenshots showing the UI modifications to the TrackTo actuator:

{F91992} {F91990}

Reviewers: moguri, dfelinto

Reviewed By: moguri

CC: Genome36

Differential Revision: https://developer.blender.org/D565

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

M	doc/python_api/rst/bge.logic.rst
M	doc/python_api/rst/bge_types/bge.types.KX_TrackToActuator.rst
M	intern/moto/include/MT_Matrix3x3.h
M	intern/moto/include/MT_Vector3.h
M	intern/moto/include/MT_Vector3.inl
M	release/scripts/startup/bl_ui/properties_object.py
M	source/blender/blenkernel/BKE_blender.h
M	source/blender/blenkernel/intern/sca.c
M	source/blender/blenloader/intern/versioning_270.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/Ketsji/KX_PythonInit.cpp
M	source/gameengine/Ketsji/KX_TrackToActuator.cpp
M	source/gameengine/Ketsji/KX_TrackToActuator.h

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

diff --git a/doc/python_api/rst/bge.logic.rst b/doc/python_api/rst/bge.logic.rst
index 4e0d317..d901a4e 100644
--- a/doc/python_api/rst/bge.logic.rst
+++ b/doc/python_api/rst/bge.logic.rst
@@ -868,6 +868,23 @@ See :class:`bge.types.KX_SteeringActuator.behavior`
 
    :value: 3
 
+.. _logic-trackto-actuator:
+
+-----------------
+TrackTo Actuator
+-----------------
+
+See :class:`bge.types.KX_TrackToActuator`
+
+.. data:: KX_TRACK_UPAXIS_POS_X
+.. data:: KX_TRACK_UPAXIS_POS_Y
+.. data:: KX_TRACK_UPAXIS_POS_Z
+.. data:: KX_TRACK_TRAXIS_POS_X
+.. data:: KX_TRACK_TRAXIS_POS_Y
+.. data:: KX_TRACK_TRAXIS_POS_Z
+.. data:: KX_TRACK_TRAXIS_NEG_X
+.. data:: KX_TRACK_TRAXIS_NEG_Y
+.. data:: KX_TRACK_TRAXIS_NEG_Z
 
 =======
 Various
diff --git a/doc/python_api/rst/bge_types/bge.types.KX_TrackToActuator.rst b/doc/python_api/rst/bge_types/bge.types.KX_TrackToActuator.rst
index 070243c..5b5c5d0 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_TrackToActuator.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_TrackToActuator.rst
@@ -37,3 +37,25 @@ base class --- :class:`SCA_IActuator`
 
       :type: boolean
 
+   .. attribute:: upAxis
+
+      The axis that points upward.
+
+      :type: integer from 0 to 2
+
+      * KX_TRACK_UPAXIS_POS_X
+      * KX_TRACK_UPAXIS_POS_Y
+      * KX_TRACK_UPAXIS_POS_Z
+
+   .. attribute:: trackAxis
+
+      The axis that points to the target object.
+
+      :type: integer from 0 to 5
+
+      * KX_TRACK_TRAXIS_POS_X
+      * KX_TRACK_TRAXIS_POS_Y
+      * KX_TRACK_TRAXIS_POS_Z
+      * KX_TRACK_TRAXIS_NEG_X
+      * KX_TRACK_TRAXIS_NEG_Y
+      * KX_TRACK_TRAXIS_NEG_Z
diff --git a/intern/moto/include/MT_Matrix3x3.h b/intern/moto/include/MT_Matrix3x3.h
index 6d709fa..17dd533 100644
--- a/intern/moto/include/MT_Matrix3x3.h
+++ b/intern/moto/include/MT_Matrix3x3.h
@@ -84,11 +84,18 @@ public:
 	MT_Vector3 getColumn(int i) const {
 		return MT_Vector3(m_el[0][i], m_el[1][i], m_el[2][i]);
 	}
+
 	void setColumn(int i, const MT_Vector3& v) {
 		m_el[0][i] = v[0];
 		m_el[1][i] = v[1];
 		m_el[2][i] = v[2];
 	}
+
+	void setRow(int i, const MT_Vector3& v) {
+		m_el[i][0] = v[0];
+		m_el[i][1] = v[1];
+		m_el[i][2] = v[2];
+	}
     
     void setValue(const float *m) {
         m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++; m++;
diff --git a/intern/moto/include/MT_Vector3.h b/intern/moto/include/MT_Vector3.h
index 83c53a1..b06f345 100644
--- a/intern/moto/include/MT_Vector3.h
+++ b/intern/moto/include/MT_Vector3.h
@@ -75,7 +75,7 @@ public:
     void        normalize();
     MT_Vector3  normalized() const;
 	MT_Vector3  safe_normalized() const;
-	
+	MT_Vector3  safe_normalized_vec(MT_Vector3 vecnormalized) const;
 
     void        scale(MT_Scalar x, MT_Scalar y, MT_Scalar z); 
     MT_Vector3  scaled(MT_Scalar x, MT_Scalar y, MT_Scalar z) const; 
diff --git a/intern/moto/include/MT_Vector3.inl b/intern/moto/include/MT_Vector3.inl
index b17ef47..09c92c6 100644
--- a/intern/moto/include/MT_Vector3.inl
+++ b/intern/moto/include/MT_Vector3.inl
@@ -77,6 +77,13 @@ GEN_INLINE MT_Vector3 MT_Vector3::safe_normalized() const {
         *this / len; 
 }
 
+GEN_INLINE MT_Vector3 MT_Vector3::safe_normalized_vec(MT_Vector3 vecnormalized) const {
+	MT_Scalar len = length();
+	return MT_fuzzyZero(len) ?
+        vecnormalized :
+        *this / len;
+}
+
 GEN_INLINE void MT_Vector3::scale(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz) {
     m_co[0] *= xx; m_co[1] *= yy; m_co[2] *= zz;
 }
diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 6b7e7b4..9d95889 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -301,10 +301,11 @@ class OBJECT_PT_relations_extras(ObjectButtonsPanel, Panel):
 
         split = layout.split()
 
-        col = split.column()
-        col.label(text="Tracking Axes:")
-        col.prop(ob, "track_axis", text="Axis")
-        col.prop(ob, "up_axis", text="Up Axis")
+        if context.scene.render.engine != 'BLENDER_GAME':
+            col = split.column()
+            col.label(text="Tracking Axes:")
+            col.prop(ob, "track_axis", text="Axis")
+            col.prop(ob, "up_axis", text="Up Axis")
 
         col = split.column()
         col.prop(ob, "use_slow_parent")
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 0af45a1..19fa60f 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         271
-#define BLENDER_SUBVERSION      1
+#define BLENDER_SUBVERSION      2
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      270
 #define BLENDER_MINSUBVERSION   5
diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c
index 1310162..4be7534 100644
--- a/source/blender/blenkernel/intern/sca.c
+++ b/source/blender/blenkernel/intern/sca.c
@@ -392,6 +392,7 @@ void init_actuator(bActuator *act)
 	bSteeringActuator *sta;
 	bArmatureActuator *arma;
 	bMouseActuator *ma;
+	bEditObjectActuator *eoa;
 	
 	if (act->data) MEM_freeN(act->data);
 	act->data= NULL;
@@ -430,6 +431,9 @@ void init_actuator(bActuator *act)
 		break;
 	case ACT_EDIT_OBJECT:
 		act->data= MEM_callocN(sizeof(bEditObjectActuator), "editobact");
+		eoa = act->data;
+		eoa->upflag= ACT_TRACK_UP_Z;
+		eoa->trackflag= ACT_TRACK_TRAXIS_Y;
 		break;
 	case ACT_CONSTRAINT:
 		act->data= MEM_callocN(sizeof(bConstraintActuator), "cons act");
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 103f9b7..dde16c8 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -42,6 +42,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_linestyle_types.h"
+#include "DNA_actuator_types.h"
 
 #include "DNA_genfile.h"
 
@@ -310,6 +311,29 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 		}
 	}
 
+	if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
+		/* init up & track axis property of trackto actuators */
+		Object *ob;
+
+		for (ob = main->object.first; ob; ob = ob->id.next) {
+			bActuator *act;
+			for (act = ob->actuators.first; act; act = act->next) {
+				if (act->type == ACT_EDIT_OBJECT) {
+					bEditObjectActuator *eoact = act->data;
+					eoact->trackflag = ob->trackflag;
+					/* if trackflag is pointing +-Z axis then upflag should point Y axis.
+					 * Rest of trackflag cases, upflag should be point z axis */
+					if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
+						eoact->upflag = 1;
+					}
+					else {
+						eoact->upflag = 2;
+					}
+				}
+			}
+		}
+	}
+
 	if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
 		Scene *scene;
 		for (scene = main->scene.first; scene; scene = scene->id.next) {
diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c
index b52d6265..c3a3dda 100644
--- a/source/blender/editors/space_logic/logic_window.c
+++ b/source/blender/editors/space_logic/logic_window.c
@@ -1720,6 +1720,12 @@ static void draw_actuator_edit_object(uiLayout *layout, PointerRNA *ptr)
 			sub = uiLayoutSplit(split, 0.7f, false);
 			uiItemR(sub, ptr, "time", 0, NULL, ICON_NONE);
 			uiItemR(sub, ptr, "use_3d_tracking", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
+
+			row = uiLayoutRow(layout, false);
+			uiItemR(row, ptr, "up_axis", 0, NULL, ICON_NONE);
+
+			row = uiLayoutRow(layout, false);
+			uiItemR(row, ptr, "track_axis", 0, NULL, ICON_NONE);
 			break;
 		case ACT_EDOB_DYNAMICS:
 			if (ob->type != OB_MESH) {
diff --git a/source/blender/makesdna/DNA_actuator_types.h b/source/blender/makesdna/DNA_actuator_types.h
index 5ab799a..7698d67 100644
--- a/source/blender/makesdna/DNA_actuator_types.h
+++ b/source/blender/makesdna/DNA_actuator_types.h
@@ -97,6 +97,8 @@ typedef struct bEditObjectActuator {
 	float mass;
 	short localflag; /* flag for the lin & ang. vel: apply locally   */
 	short dyn_operation;
+	short upflag, trackflag; /* flag for up axis and track axis */
+	int pad;
 } bEditObjectActuator;
 
 typedef struct bSceneActuator {
@@ -439,6 +441,19 @@ typedef struct bActuator {
 /* editObjectActuator->flag */
 #define ACT_TRACK_3D			1
 
+/* editObjectActuator->upflag */
+#define ACT_TRACK_UP_X			0
+#define ACT_TRACK_UP_Y			1
+#define ACT_TRACK_UP_Z			2
+
+/* editObjectActuator->trackflag */
+#define ACT_TRACK_TRAXIS_X			0
+#define ACT_TRACK_TRAXIS_Y			1
+#define ACT_TRACK_TRAXIS_Z			2
+#define ACT_TRACK_TRAXIS_NEGX		3
+#define ACT_TRACK_TRAXIS_NEGY		4
+#define ACT_TRACK_TRAXIS_NEGZ		5
+
 /* editObjectActuator->flag for replace mesh actuator */
 #define ACT_EDOB_REPLACE_MESH_NOGFX		2 /* use for replace mesh actuator */
 #define ACT_EDOB_REPLACE_MESH_PHYS		4
diff --git a/source/blender/makesrna/intern/rna_actuator.c b/source/blender/makesrna/intern/rna_actuator.c
index 62e681d..9d26978 100644
--- a/source/blender/makesrna/intern/rna_actuator.c
+++ b/source/blender/makesrna/intern/rna_actuator.c
@@ -1369,6 +1369,23 @@ static void rna_def_edit_object_actuator(BlenderRNA *brna)
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static EnumPropertyItem prop_track_axis_items[] = {
+		{ACT_TRACK_TRAXIS_X, "TRACKAXISX", 0, "X axis", ""},
+		{ACT_TRACK_TRAXIS_Y, "TRACKAXISY", 0, "Y axis", ""},
+		{ACT_TRACK_TRAXIS_Z, "TRACKAXISZ", 0, "Z axis", ""},
+		{ACT_TRACK_TRAXIS_NEGX, "TRACKAXISNEGX", 0, "-X axis", ""},
+		{ACT_TRACK_TRAXIS_NEGY, "TRACKAXISNEGY", 0, "-Y axis", ""},
+		{ACT_TRACK_TRAXIS_NEGZ, "TRACKAXISNEGZ", 0, "-Z axis", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
+	static EnumPropertyItem prop_up_axis_items[] = {
+		{ACT_TRACK_UP_X, "UPAXISX", 0, "X axis", ""},
+		{ACT_TRACK_UP_Y, "UPAXISY", 0, "Y axis", ""},
+		{ACT_TRACK_UP_Z, "UPAXISZ", 0, "Z axis", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	srna = RNA_def_struct(brna, "EditObjectActuator", "Actuator");
 	RNA_def_struct_ui_text(srna, "Edit Obje

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list