diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2012-01-22 07:21:28 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2012-01-22 07:21:28 +0400 |
commit | 6964b5a6c48f2fab19b4ce5a52ba23525a5f05eb (patch) | |
tree | 0384f726655f145874d4bab056cb9740c1f44d65 | |
parent | f45a8105eedc93ba8c4284f85e7e29f3eaeeb510 (diff) |
cucumber merge: world scaling + video texture constants
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.
-rw-r--r-- | doc/python_api/rst/bge.types.rst | 14 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 125 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 6 | ||||
-rw-r--r-- | source/gameengine/VideoTexture/blendVideoTex.cpp | 6 |
4 files changed, 149 insertions, 2 deletions
diff --git a/doc/python_api/rst/bge.types.rst b/doc/python_api/rst/bge.types.rst index f97c95babc9..bb3ac004d51 100644 --- a/doc/python_api/rst/bge.types.rst +++ b/doc/python_api/rst/bge.types.rst @@ -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 diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 18b8c0d533d..023c3dcbfc9 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -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) { diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index cc078e96e64..a35e6f1b2cd 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -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); diff --git a/source/gameengine/VideoTexture/blendVideoTex.cpp b/source/gameengine/VideoTexture/blendVideoTex.cpp index abfd0ed49b7..8410e9350d0 100644 --- a/source/gameengine/VideoTexture/blendVideoTex.cpp +++ b/source/gameengine/VideoTexture/blendVideoTex.cpp @@ -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 = ""; |