Revision: 38166
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38166
Author:   kupoman
Date:     2011-07-06 19:31:05 +0000 (Wed, 06 Jul 2011)
Log Message:
-----------
Adding a worldScale attribute to KX_GameObject. This attribute scales the 
object independently of its parent's scale.

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:00:40 UTC (rev 38165)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.cpp       
2011-07-06 19:31:05 UTC (rev 38166)
@@ -1064,6 +1064,36 @@
        }
 }
 
+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())
@@ -1525,7 +1555,7 @@
        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("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),
@@ -2017,6 +2047,18 @@
 #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

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:00:40 UTC (rev 38165)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_GameObject.h 
2011-07-06 19:31:05 UTC (rev 38166)
@@ -404,6 +404,7 @@
        void    NodeSetGlobalOrientation(const MT_Matrix3x3& rot        );
 
        void    NodeSetLocalScale(      const MT_Vector3& scale );
+       void    NodeSetWorldScale(      const MT_Vector3& scale );
 
        void    NodeSetRelativeScale(   const MT_Vector3& scale );
 
@@ -881,6 +882,7 @@
        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_worldLinearVelocity(void *self_v, 
const KX_PYATTRIBUTE_DEF *attrdef);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to