[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16450] trunk/blender/source/gameengine: BGE bug #17549: fix crash on removeParent() with static mesh.
Benoit Bolsee
benoit.bolsee at online.be
Wed Sep 10 00:40:11 CEST 2008
Revision: 16450
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16450
Author: ben2610
Date: 2008-09-10 00:40:10 +0200 (Wed, 10 Sep 2008)
Log Message:
-----------
BGE bug #17549: fix crash on removeParent() with static mesh. Fix scaling bug on setParent(). Add python setWorldPosition() to allow setting object position in world coordinate regardless if it is a root or a child object.
Modified Paths:
--------------
trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2008-09-09 21:46:19 UTC (rev 16449)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2008-09-09 22:40:10 UTC (rev 16450)
@@ -235,11 +235,12 @@
m_pPhysicsController1->SuspendDynamics(true);
}
// Set us to our new scale, position, and orientation
- scale1[0] = scale1[0]/scale2[0];
- scale1[1] = scale1[1]/scale2[1];
- scale1[2] = scale1[2]/scale2[2];
+ scale2[0] = 1.0/scale2[0];
+ scale2[1] = 1.0/scale2[1];
+ scale2[2] = 1.0/scale2[2];
+ scale1 = scale1 * scale2;
MT_Matrix3x3 invori = obj->NodeGetWorldOrientation().inverse();
- MT_Vector3 newpos = invori*(NodeGetWorldPosition()-obj->NodeGetWorldPosition())*scale1;
+ MT_Vector3 newpos = invori*(NodeGetWorldPosition()-obj->NodeGetWorldPosition())*scale2;
NodeSetLocalScale(scale1);
NodeSetLocalPosition(MT_Point3(newpos[0],newpos[1],newpos[2]));
@@ -914,6 +915,7 @@
PyMethodDef KX_GameObject::Methods[] = {
{"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_NOARGS},
{"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O},
+ {"setWorldPosition", (PyCFunction) KX_GameObject::sPySetWorldPosition, METH_O},
{"getLinearVelocity", (PyCFunction) KX_GameObject::sPyGetLinearVelocity, METH_VARARGS},
{"setLinearVelocity", (PyCFunction) KX_GameObject::sPySetLinearVelocity, METH_VARARGS},
{"getAngularVelocity", (PyCFunction) KX_GameObject::sPyGetAngularVelocity, METH_VARARGS},
@@ -1576,6 +1578,19 @@
return NULL;
}
+PyObject* KX_GameObject::PySetWorldPosition(PyObject* self, PyObject* value)
+{
+ MT_Point3 pos;
+ if (PyVecTo(value, pos))
+ {
+ NodeSetWorldPosition(pos);
+ NodeUpdateGS(0.f,true);
+ Py_RETURN_NONE;
+ }
+
+ return NULL;
+}
+
PyObject* KX_GameObject::PyGetPhysicsId(PyObject* self)
{
KX_IPhysicsController* ctrl = GetPhysicsController();
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2008-09-09 21:46:19 UTC (rev 16449)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2008-09-09 22:40:10 UTC (rev 16450)
@@ -754,6 +754,7 @@
KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition);
KX_PYMETHOD_O(KX_GameObject,SetPosition);
+ KX_PYMETHOD_O(KX_GameObject,SetWorldPosition);
KX_PYMETHOD_VARARGS(KX_GameObject,GetLinearVelocity);
KX_PYMETHOD_VARARGS(KX_GameObject,SetLinearVelocity);
KX_PYMETHOD_VARARGS(KX_GameObject,GetAngularVelocity);
Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp 2008-09-09 21:46:19 UTC (rev 16449)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp 2008-09-09 22:40:10 UTC (rev 16450)
@@ -452,11 +452,12 @@
// this function is used when the collisionning group of a controller is changed
// remove and add the collistioning object
btRigidBody* body = ctrl->GetRigidBody();
- btVector3 inertia;
+ btVector3 inertia(0.0,0.0,0.0);
m_dynamicsWorld->removeCollisionObject(body);
body->setCollisionFlags(newCollisionFlags);
- body->getCollisionShape()->calculateLocalInertia(newMass, inertia);
+ if (newMass)
+ body->getCollisionShape()->calculateLocalInertia(newMass, inertia);
body->setMassProps(newMass, inertia);
m_dynamicsWorld->addCollisionObject(body, newCollisionGroup, newCollisionMask);
// to avoid nasty interaction, we must update the property of the controller as well
Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2008-09-09 21:46:19 UTC (rev 16449)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2008-09-09 22:40:10 UTC (rev 16450)
@@ -58,9 +58,18 @@
"""
def setPosition(pos):
"""
- Sets the game object's position.
+ Sets the game object's position.
+ Global coordinates for root object, local for child objects.
+
@type pos: [x, y, z]
+ @param pos: the new position, in local coordinates.
+ """
+ def setWorldPosition(pos):
+ """
+ Sets the game object's position in world coordinates regardless if the object is root or child.
+
+ @type pos: [x, y, z]
@param pos: the new position, in world coordinates.
"""
def getPosition():
More information about the Bf-blender-cvs
mailing list