cucumber merge: world scaling + video texture constants
authorDalai Felinto <dfelinto@gmail.com>
Sun, 22 Jan 2012 03:21:28 +0000 (03:21 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Sun, 22 Jan 2012 03:21:28 +0000 (03:21 +0000)
revisions: 38166,38167,38177,38179,38180,38187,38242

To be implemented after merge:
1) add pydocs(rst) for the video texture new defines
2) see if a NodeSetLocalMatrix would fit well

#43439 by kupoman
Changing the worldTransform and localTransform python attributes to use BLI_math to simplify the code

#38242 by kupoman
Adding the constants SOURCE_ERROR, SOURCE_EMPTY, SOURCE_READY, SOURCE_PLAYING, SOURCE_STOPPED to the video texture module. Updates to the documentation will follow after a merge with trunk

#38187 by kupoman
Updates to the documentation to reflect that worldScale is now writable, and added localTransform and worldTransform to KX_GameObject.

#38180 by kupoman
The Transform attribute of KX_GameObject was based on world space data. I converted that one to worldTransform, and added a localTransform for local space transform information.

#38179 by kupoman
Fixed the transform attribute of KX_GameObject's set method to properly deal with negative scaling.

#38177 by kupoman
Updated the transform property on KX_GameObject so that it is now read/write, and added the corresponding set method. Also simplified the get method by calling GetOpenGLMatrix instead of making the matrix myself.

#38167 by kupoman
Adding a read only transform attribute to KX_GameObject that returns a 4x4 matrix representing the object's transformations.

#38166 by kupoman
Adding a worldScale attribute to KX_GameObject. This attribute scales the object independently of its parent's scale.

doc/python_api/rst/bge.types.rst
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/VideoTexture/blendVideoTex.cpp

index f97c95babc9a958fe518eac8a1d40a12bb687ff8..bb3ac004d5155f2ceca218d10802d931d67d7724 100644 (file)
@@ -980,7 +980,7 @@ Game Types (bge.types)
 
    .. attribute:: worldScale
 
-      The object's world scaling factor. Read-only. [sx, sy, sz]
+      The object's world scaling factor. [sx, sy, sz]
 
       :type: :class:`mathutils.Vector`
 
@@ -995,6 +995,18 @@ Game Types (bge.types)
       The object's world position. [x, y, z]
 
       :type: :class:`mathutils.Vector`
+
+   .. attribute:: localTransform
+
+      The object's local space transform matrix. 4x4 Matrix.
+
+      :type: :class:`mathutils.Matrix`
+
+   .. attribute:: worldTransform
+
+      The object's world space transform matrix. 4x4 Matrix.
+
+      :type: :class:`mathutils.Matrix`
          
    .. attribute:: localLinearVelocity
       
index 18b8c0d533d776c5e90c036d08f752c7600d80b6..023c3dcbfc972747e8acbc34bfaab0703e5047a1 100644 (file)
@@ -1153,6 +1153,36 @@ void KX_GameObject::NodeSetRelativeScale(const MT_Vector3& scale)
        }
 }
 
+void KX_GameObject::NodeSetWorldScale(const MT_Vector3& scale)
+{
+       if (!GetSGNode())
+               return;
+       SG_Node* parent = GetSGNode()->GetSGParent();
+       if (parent != NULL)
+       {
+               // Make sure the objects have some scale
+               MT_Vector3 p_scale = parent->GetWorldScaling();
+               if (fabs(p_scale[0]) < FLT_EPSILON || 
+                       fabs(p_scale[1]) < FLT_EPSILON || 
+                       fabs(p_scale[2]) < FLT_EPSILON)
+               { 
+                       return; 
+               }
+
+               MT_Vector3 *local = new MT_Vector3(scale);
+
+               p_scale[0] = 1/p_scale[0];
+               p_scale[1] = 1/p_scale[1];
+               p_scale[2] = 1/p_scale[2];
+
+               NodeSetLocalScale(scale * p_scale);
+       }
+       else
+       {
+               NodeSetLocalScale(scale);
+       }
+}
+
 void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans)
 {
        if (!GetSGNode())
@@ -1620,7 +1650,9 @@ PyAttributeDef KX_GameObject::Attributes[] = {
        KX_PYATTRIBUTE_RW_FUNCTION("localPosition",     KX_GameObject, pyattr_get_localPosition,        pyattr_set_localPosition),
        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_RO_FUNCTION("worldScale",        KX_GameObject, pyattr_get_worldScaling),
+       KX_PYATTRIBUTE_RW_FUNCTION("worldScale",        KX_GameObject, pyattr_get_worldScaling, pyattr_set_worldScaling),
+       KX_PYATTRIBUTE_RW_FUNCTION("localTransform",            KX_GameObject, pyattr_get_localTransform, pyattr_set_localTransform),
+       KX_PYATTRIBUTE_RW_FUNCTION("worldTransform",            KX_GameObject, pyattr_get_worldTransform, pyattr_set_worldTransform),
        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),
@@ -2112,6 +2144,18 @@ PyObject* KX_GameObject::pyattr_get_worldScaling(void *self_v, const KX_PYATTRIB
 #endif
 }
 
+int KX_GameObject::pyattr_set_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
+       MT_Vector3 scale;
+       if (!PyVecTo(value, scale))
+               return PY_SET_ATTR_FAIL;
+
+       self->NodeSetWorldScale(scale);
+       self->NodeUpdateGS(0.f);
+       return PY_SET_ATTR_SUCCESS;
+}
+
 PyObject* KX_GameObject::pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 #ifdef USE_MATHUTILS
@@ -2134,6 +2178,85 @@ int KX_GameObject::pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DE
        return PY_SET_ATTR_SUCCESS;
 }
 
+PyObject* KX_GameObject::pyattr_get_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+       KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+
+       double *mat = MT_CmMatrix4x4().getPointer();
+
+       MT_Transform trans;
+       
+       trans.setOrigin(self->GetSGNode()->GetLocalPosition());
+       trans.setBasis(self->GetSGNode()->GetLocalOrientation());
+       
+       MT_Vector3 scaling = self->GetSGNode()->GetLocalScale();
+       trans.scale(scaling[0], scaling[1], scaling[2]);
+
+       trans.getValue(mat);
+
+       return PyObjectFrom(MT_Matrix4x4(mat));
+}
+
+int KX_GameObject::pyattr_set_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+       KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+       MT_Matrix4x4 temp;
+       if (!PyMatTo(value, temp))
+               return PY_SET_ATTR_FAIL;
+
+       float transform[4][4];
+       float loc[3], size[3];
+       float rot[3][3];
+       MT_Matrix3x3 orientation;
+
+       temp.getValue(*transform);
+       mat4_to_loc_rot_size(loc, rot, size, transform);
+
+       self->NodeSetLocalPosition(MT_Point3(loc));
+
+       //MT_Matrix3x3's constructor expects a 4x4 matrix
+       orientation = MT_Matrix3x3();
+       orientation.setValue3x3(*rot);
+       self->NodeSetLocalOrientation(orientation);
+
+       self->NodeSetLocalScale(MT_Vector3(size));
+
+       return PY_SET_ATTR_SUCCESS;
+}
+
+PyObject* KX_GameObject::pyattr_get_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+       KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+
+       return PyObjectFrom(MT_Matrix4x4(self->GetOpenGLMatrix()));
+}
+
+int KX_GameObject::pyattr_set_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+       KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+       MT_Matrix4x4 temp;
+       if (!PyMatTo(value, temp))
+               return PY_SET_ATTR_FAIL;
+
+       float transform[4][4];
+       float loc[3], size[3];
+       float rot[3][3];
+       MT_Matrix3x3 orientation;
+
+       temp.getValue(*transform);
+       mat4_to_loc_rot_size(loc, rot, size, transform);
+
+       self->NodeSetWorldPosition(MT_Point3(loc));
+
+       //MT_Matrix3x3's constructor expects a 4x4 matrix
+       orientation = MT_Matrix3x3();
+       orientation.setValue3x3(*rot);
+       self->NodeSetGlobalOrientation(orientation);
+
+       self->NodeSetWorldScale(MT_Vector3(size));
+
+       return PY_SET_ATTR_SUCCESS;
+}
 
 PyObject* KX_GameObject::pyattr_get_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
index cc078e96e643bd6b02f09c9f59d91e4ca3bf80f1..a35e6f1b2cd0d571db49a4d3469d8fae5e7a2038 100644 (file)
@@ -475,6 +475,7 @@ public:
        void    NodeSetGlobalOrientation(const MT_Matrix3x3& rot        );
 
        void    NodeSetLocalScale(      const MT_Vector3& scale );
+       void    NodeSetWorldScale(      const MT_Vector3& scale );
 
        void    NodeSetRelativeScale(   const MT_Vector3& scale );
 
@@ -968,8 +969,13 @@ public:
        static PyObject*        pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static int                      pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
        static PyObject*        pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       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_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
        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);
index abfd0ed49b7d4e098124293a071804718d48f379..8410e9350d005dede1bb63cfa791d890f31bd836 100644 (file)
@@ -38,6 +38,7 @@ http://www.gnu.org/copyleft/lesser.txt.
 //#include "TexPlayerGL.h"
 
 #include "ImageBase.h"
+#include "VideoBase.h"
 #include "FilterBase.h"
 #include "Texture.h"
 
@@ -208,6 +209,11 @@ PyObject* initVideoTexture(void)
 
        Py_INCREF(&TextureType);
        PyModule_AddObject(m, (char*)"Texture", (PyObject*)&TextureType);
+       PyModule_AddIntConstant(m, (char*)"SOURCE_ERROR", SourceError);
+       PyModule_AddIntConstant(m, (char*)"SOURCE_EMPTY", SourceEmpty);
+       PyModule_AddIntConstant(m, (char*)"SOURCE_READY", SourceReady);
+       PyModule_AddIntConstant(m, (char*)"SOURCE_PLAYING", SourcePlaying);
+       PyModule_AddIntConstant(m, (char*)"SOURCE_STOPPED", SourceStopped);
        
        // init last error description
        Exception::m_lastError = "";