[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38167] branches/soc-2011-cucumber/source/ gameengine/Ketsji: Adding a read only transform attribute to KX_GameObject that returns a 4x4 matrix representing the object 's transformations.

Daniel Stokes kupomail at gmail.com
Wed Jul 6 22:22:35 CEST 2011


Revision: 38167
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38167
Author:   kupoman
Date:     2011-07-06 20:22:35 +0000 (Wed, 06 Jul 2011)
Log Message:
-----------
Adding a read only transform attribute to KX_GameObject that returns a 4x4 matrix representing the object's transformations.

Modified Paths:
--------------
    branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.cpp
    branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.h

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.cpp	2011-07-06 19:31:05 UTC (rev 38166)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.cpp	2011-07-06 20:22:35 UTC (rev 38167)
@@ -1556,6 +1556,7 @@
 	KX_PYATTRIBUTE_RW_FUNCTION("worldPosition",	KX_GameObject, pyattr_get_worldPosition,    pyattr_set_worldPosition),
 	KX_PYATTRIBUTE_RW_FUNCTION("localScale",	KX_GameObject, pyattr_get_localScaling,	pyattr_set_localScaling),
 	KX_PYATTRIBUTE_RW_FUNCTION("worldScale",	KX_GameObject, pyattr_get_worldScaling, pyattr_set_worldScaling),
+	KX_PYATTRIBUTE_RO_FUNCTION("transform",		KX_GameObject, pyattr_get_transform),
 	KX_PYATTRIBUTE_RW_FUNCTION("linearVelocity", KX_GameObject, pyattr_get_localLinearVelocity, pyattr_set_worldLinearVelocity),
 	KX_PYATTRIBUTE_RW_FUNCTION("localLinearVelocity", KX_GameObject, pyattr_get_localLinearVelocity, pyattr_set_localLinearVelocity),
 	KX_PYATTRIBUTE_RW_FUNCTION("worldLinearVelocity", KX_GameObject, pyattr_get_worldLinearVelocity, pyattr_set_worldLinearVelocity),
@@ -2081,7 +2082,24 @@
 	return PY_SET_ATTR_SUCCESS;
 }
 
+PyObject* KX_GameObject::pyattr_get_transform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+	MT_Matrix4x4 *transform = new MT_Matrix4x4();
+	
+	MT_Vector3 translation = self->NodeGetWorldPosition();
+	MT_Matrix3x3 rotation = self->NodeGetWorldOrientation();
+	MT_Vector3 scale = self->NodeGetWorldScaling();
 
+	transform->setValue(
+		rotation[0][0]*scale[0],	rotation[1][0],				rotation[2][0],				translation[0],
+		rotation[0][1],				rotation[1][1]*scale[1],	rotation[2][1],				translation[1],
+		rotation[0][2],				rotation[1][2],				rotation[2][2]*scale[2],	translation[2],
+		0,							0,							0,							1);
+
+	return PyObjectFrom(*transform);
+}
+
 PyObject* KX_GameObject::pyattr_get_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 #ifdef USE_MATHUTILS

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.h	2011-07-06 19:31:05 UTC (rev 38166)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.h	2011-07-06 20:22:35 UTC (rev 38167)
@@ -885,6 +885,7 @@
 	static int			pyattr_set_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static PyObject*	pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static int			pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+	static PyObject*	pyattr_get_transform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static PyObject*	pyattr_get_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 	static int			pyattr_set_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static PyObject*	pyattr_get_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);




More information about the Bf-blender-cvs mailing list