Added an UpdateTransform callback from SceneGraph -> Physics.
Profiling revealed that the SceneGraph updated every physics object, whether it moved or not, even though the physics object was at the right place. This would cause SOLID to go and update its bounding boxes, overlap tests etc. This callback handles the special case (parented objects) where the physics scene needs to be informed of changes to the scenegraph. Added Python attributes (mass, parent, visible, position, orientation, scaling) to the KX_GameObject module. Make KX_GameObject use the KX_PyMath Python <-> Moto conversion.
This commit is contained in:
@@ -55,6 +55,8 @@
|
||||
#include "KX_ClientObjectInfo.h"
|
||||
#include "RAS_BucketManager.h"
|
||||
|
||||
#include "KX_PyMath.h"
|
||||
|
||||
// This file defines relationships between parents and children
|
||||
// in the game engine.
|
||||
|
||||
@@ -303,11 +305,13 @@ void KX_GameObject::UpdateNonDynas()
|
||||
void KX_GameObject::UpdateTransform()
|
||||
{
|
||||
if (m_pPhysicsController1)
|
||||
{
|
||||
m_pPhysicsController1->SetSumoTransform(false);
|
||||
}
|
||||
}
|
||||
|
||||
void KX_GameObject::UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene)
|
||||
{
|
||||
((KX_GameObject*)gameobj)->UpdateTransform();
|
||||
}
|
||||
|
||||
|
||||
void KX_GameObject::SetDebugColor(unsigned int bgra)
|
||||
@@ -408,7 +412,7 @@ KX_GameObject::MarkVisible(
|
||||
* determined on this level. Maybe change this to mesh level
|
||||
* later on? */
|
||||
|
||||
double* fl = GetOpenGLMatrix();
|
||||
double* fl = GetOpenGLMatrixPtr()->getPointer();
|
||||
for (size_t i=0;i<m_meshes.size();i++)
|
||||
{
|
||||
m_meshes[i]->MarkVisible(fl,this,visible,m_bUseObjectColor,m_objectColor);
|
||||
@@ -422,7 +426,7 @@ KX_GameObject::MarkVisible(
|
||||
void
|
||||
)
|
||||
{
|
||||
double* fl = GetOpenGLMatrix();
|
||||
double* fl = GetOpenGLMatrixPtr()->getPointer();
|
||||
for (size_t i=0;i<m_meshes.size();i++)
|
||||
{
|
||||
m_meshes[i]->MarkVisible(fl,
|
||||
@@ -603,10 +607,10 @@ PyMethodDef KX_GameObject::Methods[] = {
|
||||
{"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS},
|
||||
{"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_VARARGS},
|
||||
{"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_VARARGS},
|
||||
{"getLinearVelocity", (PyCFunction) KX_GameObject::sPyGetLinearVelocity, METH_VARARGS},
|
||||
{"getVelocity", (PyCFunction) KX_GameObject::sPyGetVelocity, METH_VARARGS},
|
||||
{"getOrientation", (PyCFunction) KX_GameObject::sPyGetOrientation, METH_VARARGS},
|
||||
{"setOrientation", (PyCFunction) KX_GameObject::sPySetOrientation, METH_VARARGS},
|
||||
{"getLinearVelocity", (PyCFunction) KX_GameObject::sPyGetLinearVelocity, METH_VARARGS},
|
||||
{"getVelocity", (PyCFunction) KX_GameObject::sPyGetVelocity, METH_VARARGS},
|
||||
{"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_VARARGS},
|
||||
{"getReactionForce", (PyCFunction) KX_GameObject::sPyGetReactionForce, METH_VARARGS},
|
||||
{"applyImpulse", (PyCFunction) KX_GameObject::sPyApplyImpulse, METH_VARARGS},
|
||||
@@ -654,17 +658,7 @@ PyObject* KX_GameObject::PyGetPosition(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
MT_Point3 pos = NodeGetWorldPosition();
|
||||
|
||||
PyObject* resultlist = PyList_New(3);
|
||||
int index;
|
||||
for (index=0;index<3;index++)
|
||||
{
|
||||
PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
|
||||
}
|
||||
|
||||
return resultlist;
|
||||
|
||||
return PyObjectFromMT_Point3(NodeGetWorldPosition());
|
||||
}
|
||||
|
||||
|
||||
@@ -702,9 +696,101 @@ PyParentObject KX_GameObject::Parents[] = {
|
||||
|
||||
PyObject* KX_GameObject::_getattr(const STR_String& attr)
|
||||
{
|
||||
if (m_pPhysicsController1)
|
||||
{
|
||||
if (attr == "mass")
|
||||
return PyFloat_FromDouble(GetPhysicsController()->GetMass());
|
||||
}
|
||||
|
||||
if (attr == "parent")
|
||||
{
|
||||
KX_GameObject* parent = GetParent();
|
||||
if (parent)
|
||||
return parent;
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
if (attr == "visible")
|
||||
return PyInt_FromLong(m_bVisible);
|
||||
|
||||
if (attr == "position")
|
||||
return PyObjectFromMT_Point3(NodeGetWorldPosition());
|
||||
|
||||
if (attr == "orientation")
|
||||
return PyObjectFromMT_Matrix3x3(NodeGetWorldOrientation());
|
||||
|
||||
if (attr == "scaling")
|
||||
return PyObjectFromMT_Vector3(NodeGetWorldScaling());
|
||||
|
||||
_getattr_up(SCA_IObject);
|
||||
}
|
||||
|
||||
int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr method
|
||||
{
|
||||
if (attr == "mass")
|
||||
return 1;
|
||||
|
||||
if (attr == "parent")
|
||||
return 1;
|
||||
|
||||
if (PyInt_Check(value))
|
||||
{
|
||||
int val = PyInt_AsLong(value);
|
||||
if (attr == "visible")
|
||||
{
|
||||
SetVisible(val != 0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (PySequence_Check(value))
|
||||
{
|
||||
if (attr == "orientation")
|
||||
{
|
||||
MT_Matrix3x3 rot;
|
||||
if (PyObject_IsMT_Matrix(value, 3))
|
||||
{
|
||||
rot = MT_Matrix3x3FromPyObject(value);
|
||||
NodeSetLocalOrientation(rot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PySequence_Size(value) == 4)
|
||||
{
|
||||
MT_Quaternion qrot = MT_QuaternionFromPyList(value);
|
||||
rot.setRotation(qrot);
|
||||
NodeSetLocalOrientation(rot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PySequence_Size(value) == 3)
|
||||
{
|
||||
MT_Vector3 erot = MT_Vector3FromPyList(value);
|
||||
rot.setEuler(erot);
|
||||
NodeSetLocalOrientation(rot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (attr == "position")
|
||||
{
|
||||
MT_Point3 pos(MT_Point3FromPyList(value));
|
||||
NodeSetLocalPosition(pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (attr == "scaling")
|
||||
{
|
||||
MT_Vector3 scale(MT_Vector3FromPyList(value));
|
||||
NodeSetLocalScale(scale);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return SCA_IObject::_setattr(attr, value);
|
||||
}
|
||||
|
||||
|
||||
PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self,
|
||||
@@ -712,16 +798,7 @@ PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self,
|
||||
PyObject* kwds)
|
||||
{
|
||||
// only can get the velocity if we have a physics object connected to us...
|
||||
MT_Vector3 velocity = GetLinearVelocity();
|
||||
|
||||
PyObject* resultlist = PyList_New(3);
|
||||
int index;
|
||||
for (index=0;index<3;index++)
|
||||
{
|
||||
PyList_SetItem(resultlist,index,PyFloat_FromDouble(velocity[index]));
|
||||
}
|
||||
|
||||
return resultlist;
|
||||
return PyObjectFromMT_Vector3( GetLinearVelocity());
|
||||
}
|
||||
|
||||
|
||||
@@ -756,66 +833,19 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* self,
|
||||
MT_Point3 point(0.0,0.0,0.0);
|
||||
|
||||
|
||||
MT_Point3 pos;
|
||||
PyObject* pylist;
|
||||
bool error = false;
|
||||
|
||||
int len = PyTuple_Size(args);
|
||||
|
||||
if ((len > 0) && PyArg_ParseTuple(args,"O",&pylist))
|
||||
PyObject* pypos = NULL;
|
||||
if (PyArg_ParseTuple(args, "|O", &pypos))
|
||||
{
|
||||
if (pylist->ob_type == &CListValue::Type)
|
||||
{
|
||||
CListValue* listval = (CListValue*) pylist;
|
||||
if (listval->GetCount() == 3)
|
||||
{
|
||||
int index;
|
||||
for (index=0;index<3;index++)
|
||||
{
|
||||
pos[index] = listval->GetValue(index)->GetNumber();
|
||||
}
|
||||
} else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
|
||||
// assert the list is long enough...
|
||||
int numitems = PyList_Size(pylist);
|
||||
if (numitems == 3)
|
||||
{
|
||||
int index;
|
||||
for (index=0;index<3;index++)
|
||||
{
|
||||
pos[index] = PyFloat_AsDouble(PyList_GetItem(pylist,index));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!error)
|
||||
point = pos;
|
||||
if (pypos)
|
||||
point = MT_Point3FromPyList(pypos);
|
||||
}
|
||||
|
||||
|
||||
if (m_pPhysicsController1)
|
||||
{
|
||||
velocity = m_pPhysicsController1->GetVelocity(point);
|
||||
}
|
||||
|
||||
PyObject* resultlist = PyList_New(3);
|
||||
int index;
|
||||
for (index=0;index<3;index++)
|
||||
{
|
||||
PyList_SetItem(resultlist,index,PyFloat_FromDouble(velocity[index]));
|
||||
}
|
||||
|
||||
return resultlist;
|
||||
return PyObjectFromMT_Vector3(velocity);
|
||||
}
|
||||
|
||||
|
||||
@@ -842,18 +872,7 @@ PyObject* KX_GameObject::PyGetReactionForce(PyObject* self,
|
||||
PyObject* kwds)
|
||||
{
|
||||
// only can get the velocity if we have a physics object connected to us...
|
||||
|
||||
MT_Vector3 reaction_force = GetPhysicsController()->getReactionForce();
|
||||
|
||||
PyObject* resultlist = PyList_New(3);
|
||||
int index;
|
||||
for (index=0;index<3;index++)
|
||||
{
|
||||
PyList_SetItem(resultlist,index,
|
||||
PyFloat_FromDouble(reaction_force[index]));
|
||||
}
|
||||
|
||||
return resultlist;
|
||||
return PyObjectFromMT_Vector3(GetPhysicsController()->getReactionForce());
|
||||
}
|
||||
|
||||
|
||||
@@ -897,12 +916,16 @@ PyObject* KX_GameObject::PyGetMesh(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
if (m_meshes.size() > 0)
|
||||
{
|
||||
KX_MeshProxy* meshproxy = new KX_MeshProxy(m_meshes[0]);
|
||||
return meshproxy;
|
||||
}
|
||||
int mesh = 0;
|
||||
|
||||
if (PyArg_ParseTuple(args, "|i", &mesh))
|
||||
{
|
||||
if (mesh < m_meshes.size() && mesh >= 0)
|
||||
{
|
||||
KX_MeshProxy* meshproxy = new KX_MeshProxy(m_meshes[mesh]);
|
||||
return meshproxy;
|
||||
}
|
||||
}
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
@@ -913,11 +936,15 @@ PyObject* KX_GameObject::PyApplyImpulse(PyObject* self,
|
||||
PyObject* kwds)
|
||||
{
|
||||
|
||||
MT_Point3 attach(0, 1, 0);
|
||||
MT_Vector3 impulse(1, 0, 0);
|
||||
|
||||
if (ConvertPythonVectorArgs(args,attach,impulse))
|
||||
PyObject* pyattach;
|
||||
PyObject* pyimpulse;
|
||||
|
||||
if (PyArg_ParseTuple(args, "OO", &pyattach, &pyimpulse))
|
||||
{
|
||||
MT_Point3 attach(MT_Point3FromPyList(pyattach));
|
||||
MT_Vector3 impulse(MT_Vector3FromPyList(pyimpulse));
|
||||
|
||||
if (m_pPhysicsController1)
|
||||
{
|
||||
m_pPhysicsController1->applyImpulse(attach, impulse);
|
||||
@@ -975,27 +1002,8 @@ PyObject* KX_GameObject::PyGetOrientation(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) //keywords
|
||||
{
|
||||
// do the conversion of a C++ matrix to a python list
|
||||
|
||||
PyObject* resultlist = PyList_New(3);
|
||||
|
||||
|
||||
int row,col;
|
||||
const MT_Matrix3x3& orient = NodeGetWorldOrientation();
|
||||
|
||||
for (row=0;row<3;row++)
|
||||
{
|
||||
PyObject* veclist = PyList_New(3);
|
||||
|
||||
for (col=0;col<3;col++)
|
||||
{
|
||||
const MT_Scalar fl = orient[row][col];
|
||||
PyList_SetItem(veclist,col,PyFloat_FromDouble(fl));
|
||||
}
|
||||
PyList_SetItem(resultlist,row,veclist);
|
||||
|
||||
}
|
||||
return resultlist;
|
||||
return PyObjectFromMT_Matrix3x3(orient);
|
||||
}
|
||||
|
||||
|
||||
@@ -1004,68 +1012,33 @@ PyObject* KX_GameObject::PySetOrientation(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
MT_Matrix3x3 matrix;
|
||||
|
||||
PyObject* pylist;
|
||||
bool error = false;
|
||||
int row,col;
|
||||
|
||||
PyArg_ParseTuple(args,"O",&pylist);
|
||||
|
||||
if (pylist->ob_type == &CListValue::Type)
|
||||
MT_Matrix3x3 matrix;
|
||||
if (PyObject_IsMT_Matrix(pylist, 3))
|
||||
{
|
||||
CListValue* listval = (CListValue*) pylist;
|
||||
if (listval->GetCount() == 3)
|
||||
{
|
||||
for (row=0;row<3;row++) // each row has a 3-vector [x,y,z]
|
||||
{
|
||||
CListValue* vecval = (CListValue*)listval->GetValue(row);
|
||||
for (col=0;col<3;col++)
|
||||
{
|
||||
matrix[row][col] = vecval->GetValue(col)->GetNumber();
|
||||
matrix = MT_Matrix3x3FromPyObject(pylist);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!PyErr_Occurred())
|
||||
{
|
||||
error = true;
|
||||
NodeSetLocalOrientation(matrix);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// assert the list is long enough...
|
||||
int numitems = PyList_Size(pylist);
|
||||
if (numitems == 3)
|
||||
{
|
||||
for (row=0;row<3;row++) // each row has a 3-vector [x,y,z]
|
||||
{
|
||||
|
||||
PyObject* veclist = PyList_GetItem(pylist,row); // here we have a vector3 list
|
||||
for (col=0;col<3;col++)
|
||||
{
|
||||
matrix[row][col] = PyFloat_AsDouble(PyList_GetItem(veclist,col));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
if (!error)
|
||||
MT_Quaternion quat = MT_QuaternionFromPyList(pylist);
|
||||
if (!PyErr_Occurred())
|
||||
{
|
||||
if (m_pPhysicsController1)
|
||||
{
|
||||
m_pPhysicsController1->setOrientation(matrix.getRotation());
|
||||
}
|
||||
matrix.setRotation(quat);
|
||||
NodeSetLocalOrientation(matrix);
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1075,16 +1048,13 @@ PyObject* KX_GameObject::PySetPosition(PyObject* self,
|
||||
PyObject* kwds)
|
||||
{
|
||||
// make a general function for this, it's needed many times
|
||||
|
||||
MT_Point3 pos = ConvertPythonVectorArg(args);
|
||||
if (this->m_pPhysicsController1)
|
||||
PyObject *pypos;
|
||||
if (PyArg_ParseTuple(args, "O", &pypos))
|
||||
{
|
||||
this->m_pPhysicsController1->setPosition(pos);
|
||||
MT_Point3 pos = MT_Point3FromPyList(pypos);
|
||||
NodeSetLocalPosition(pos);
|
||||
}
|
||||
NodeSetLocalPosition(pos);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* KX_GameObject::PyGetPhysicsId(PyObject* self,
|
||||
|
||||
@@ -419,6 +419,8 @@ public:
|
||||
UpdateTransform(
|
||||
);
|
||||
|
||||
static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene);
|
||||
|
||||
/**
|
||||
* Only update the transform if it's a non-dynamic object
|
||||
*/
|
||||
@@ -573,6 +575,13 @@ public:
|
||||
const STR_String& attr
|
||||
);
|
||||
|
||||
virtual
|
||||
int
|
||||
_setattr(
|
||||
const STR_String& attr,
|
||||
PyObject *value
|
||||
); // _setattr method
|
||||
|
||||
PyObject*
|
||||
PySetPosition(
|
||||
PyObject* self,
|
||||
|
||||
@@ -50,7 +50,7 @@ New(
|
||||
return new KX_NormalParentRelation();
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
KX_NormalParentRelation::
|
||||
UpdateChildCoordinates(
|
||||
SG_Spatial * child,
|
||||
@@ -82,6 +82,7 @@ UpdateChildCoordinates(
|
||||
|
||||
child_w_pos = p_world_pos + p_world_scale *
|
||||
(p_world_rotation * child_pos);
|
||||
|
||||
} else {
|
||||
|
||||
child_w_scale = child_scale;
|
||||
@@ -92,6 +93,8 @@ UpdateChildCoordinates(
|
||||
child->SetWorldScale(child_w_scale);
|
||||
child->SetWorldPosition(child_w_pos);
|
||||
child->SetWorldOrientation(child_w_rotation);
|
||||
|
||||
return parent != NULL;
|
||||
}
|
||||
|
||||
SG_ParentRelation *
|
||||
@@ -130,7 +133,7 @@ New(
|
||||
* Method inherited from KX_ParentRelation
|
||||
*/
|
||||
|
||||
void
|
||||
bool
|
||||
KX_VertexParentRelation::
|
||||
UpdateChildCoordinates(
|
||||
SG_Spatial * child,
|
||||
@@ -161,7 +164,6 @@ UpdateChildCoordinates(
|
||||
child_w_scale = child_scale;
|
||||
child_w_rotation = child_rotation;
|
||||
child_w_pos = p_world_pos + child_pos;
|
||||
|
||||
} else {
|
||||
|
||||
child_w_scale = child_scale;
|
||||
@@ -172,6 +174,8 @@ UpdateChildCoordinates(
|
||||
child->SetWorldScale(child_w_scale);
|
||||
child->SetWorldPosition(child_w_pos);
|
||||
child->SetWorldOrientation(child_w_rotation);
|
||||
|
||||
return parent != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,7 +219,7 @@ New(
|
||||
* Method inherited from KX_ParentRelation
|
||||
*/
|
||||
|
||||
void
|
||||
bool
|
||||
KX_SlowParentRelation::
|
||||
UpdateChildCoordinates(
|
||||
SG_Spatial * child,
|
||||
@@ -280,6 +284,8 @@ UpdateChildCoordinates(
|
||||
child_w_rotation[1][i] = (m_relax * child_w_rotation[1][i] + child_n_rotation[1][i]) * weight;
|
||||
child_w_rotation[2][i] = (m_relax * child_w_rotation[2][i] + child_n_rotation[2][i]) * weight;
|
||||
}
|
||||
|
||||
//FIXME: update physics controller.
|
||||
} else {
|
||||
child_w_scale = child_n_scale;
|
||||
child_w_pos = child_n_pos;
|
||||
@@ -297,6 +303,8 @@ UpdateChildCoordinates(
|
||||
child->SetWorldScale(child_w_scale);
|
||||
child->SetWorldPosition(child_w_pos);
|
||||
child->SetWorldOrientation(child_w_rotation);
|
||||
|
||||
return parent != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,7 +69,7 @@ public :
|
||||
* Method inherited from KX_ParentRelation
|
||||
*/
|
||||
|
||||
void
|
||||
bool
|
||||
UpdateChildCoordinates(
|
||||
SG_Spatial * child,
|
||||
const SG_Spatial * parent
|
||||
@@ -113,7 +113,7 @@ public :
|
||||
* Method inherited from KX_ParentRelation
|
||||
*/
|
||||
|
||||
void
|
||||
bool
|
||||
UpdateChildCoordinates(
|
||||
SG_Spatial * child,
|
||||
const SG_Spatial * parent
|
||||
@@ -158,7 +158,7 @@ public :
|
||||
* Method inherited from KX_ParentRelation
|
||||
*/
|
||||
|
||||
void
|
||||
bool
|
||||
UpdateChildCoordinates(
|
||||
SG_Spatial * child,
|
||||
const SG_Spatial * parent
|
||||
|
||||
@@ -85,7 +85,6 @@ void KX_SumoPhysicsController::ApplyForce(const MT_Vector3& force,bool local)
|
||||
bool KX_SumoPhysicsController::Update(double time)
|
||||
{
|
||||
return SynchronizeMotionStates(time);
|
||||
|
||||
}
|
||||
|
||||
void KX_SumoPhysicsController::SetSimulatedTime(double time)
|
||||
|
||||
@@ -85,38 +85,12 @@ float SumoPhysicsController::getMass()
|
||||
|
||||
bool SumoPhysicsController::SynchronizeMotionStates(float time)
|
||||
{
|
||||
|
||||
if (m_bFirstTime)
|
||||
{
|
||||
setSumoTransform(false);
|
||||
setSumoTransform(!m_bFirstTime);
|
||||
m_bFirstTime = false;
|
||||
}
|
||||
|
||||
if (!m_bDyna)
|
||||
{
|
||||
if (m_sumoObj)
|
||||
{
|
||||
MT_Point3 pos;
|
||||
GetWorldPosition(pos);
|
||||
|
||||
m_sumoObj->setPosition(pos);
|
||||
if (m_bDyna)
|
||||
{
|
||||
m_sumoObj->setScaling(MT_Vector3(1,1,1));
|
||||
} else
|
||||
{
|
||||
MT_Vector3 scaling;
|
||||
GetWorldScaling(scaling);
|
||||
m_sumoObj->setScaling(scaling);
|
||||
}
|
||||
MT_Matrix3x3 orn;
|
||||
GetWorldOrientation(orn);
|
||||
m_sumoObj->setOrientation(orn.getRotation());
|
||||
m_sumoObj->calcXform();
|
||||
}
|
||||
}
|
||||
return false; // physics object are not part of
|
||||
// hierarchy, or ignore it ??
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -132,6 +132,17 @@ ActivateDestructionCallback(
|
||||
|
||||
void
|
||||
SG_IObject::
|
||||
ActivateUpdateTransformCallback(
|
||||
){
|
||||
if (m_callbacks.m_updatefunc)
|
||||
{
|
||||
// Call client provided update func.
|
||||
m_callbacks.m_updatefunc(this, m_SGclientObject, m_SGclientInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SG_IObject::
|
||||
SetControllerTime(
|
||||
double time
|
||||
){
|
||||
|
||||
@@ -51,6 +51,12 @@ typedef void* (*SG_DestructionNewCallback)(
|
||||
void* clientinfo
|
||||
);
|
||||
|
||||
typedef void (*SG_UpdateTransformCallback)(
|
||||
SG_IObject* sgobject,
|
||||
void* clientobj,
|
||||
void* clientinfo
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* SG_Callbacks hold 2 call backs to the outside world.
|
||||
@@ -72,21 +78,25 @@ struct SG_Callbacks
|
||||
SG_Callbacks(
|
||||
):
|
||||
m_replicafunc(NULL),
|
||||
m_destructionfunc(NULL)
|
||||
m_destructionfunc(NULL),
|
||||
m_updatefunc(NULL)
|
||||
{
|
||||
};
|
||||
|
||||
SG_Callbacks(
|
||||
SG_ReplicationNewCallback repfunc,
|
||||
SG_DestructionNewCallback destructfunc
|
||||
SG_DestructionNewCallback destructfunc,
|
||||
SG_UpdateTransformCallback updatefunc
|
||||
):
|
||||
m_replicafunc(repfunc),
|
||||
m_destructionfunc(destructfunc)
|
||||
m_destructionfunc(destructfunc),
|
||||
m_updatefunc(updatefunc)
|
||||
{
|
||||
};
|
||||
|
||||
SG_ReplicationNewCallback m_replicafunc;
|
||||
SG_DestructionNewCallback m_destructionfunc;
|
||||
SG_UpdateTransformCallback m_updatefunc;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -202,6 +212,10 @@ protected :
|
||||
|
||||
void
|
||||
ActivateDestructionCallback(
|
||||
);
|
||||
|
||||
void
|
||||
ActivateUpdateTransformCallback(
|
||||
);
|
||||
|
||||
SG_IObject(
|
||||
|
||||
@@ -186,7 +186,8 @@ void SG_Node::RemoveChild(SG_Node* child)
|
||||
|
||||
void SG_Node::UpdateWorldData(double time)
|
||||
{
|
||||
UpdateSpatialData(GetSGParent(),time);
|
||||
if (UpdateSpatialData(GetSGParent(),time))
|
||||
ActivateUpdateTransformCallback();
|
||||
|
||||
// update children's worlddata
|
||||
for (NodeList::iterator it = m_children.begin();it!=m_children.end();++it)
|
||||
|
||||
@@ -188,8 +188,6 @@ public:
|
||||
Destruct(
|
||||
);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void
|
||||
|
||||
@@ -69,7 +69,7 @@ public :
|
||||
*/
|
||||
|
||||
virtual
|
||||
void
|
||||
bool
|
||||
UpdateChildCoordinates(
|
||||
SG_Spatial * child,
|
||||
const SG_Spatial * parent
|
||||
|
||||
@@ -103,7 +103,7 @@ SetParentRelation(
|
||||
*/
|
||||
|
||||
|
||||
void
|
||||
bool
|
||||
SG_Spatial::
|
||||
UpdateSpatialData(
|
||||
const SG_Spatial *parent,
|
||||
@@ -128,17 +128,16 @@ UpdateSpatialData(
|
||||
// our world coordinates.
|
||||
|
||||
if (!bComputesWorldTransform)
|
||||
{
|
||||
ComputeWorldTransforms(parent);
|
||||
}
|
||||
bComputesWorldTransform = ComputeWorldTransforms(parent);
|
||||
|
||||
return bComputesWorldTransform;
|
||||
}
|
||||
|
||||
void SG_Spatial::ComputeWorldTransforms(const SG_Spatial *parent)
|
||||
bool SG_Spatial::ComputeWorldTransforms(const SG_Spatial *parent)
|
||||
{
|
||||
m_parent_relation->UpdateChildCoordinates(this,parent);
|
||||
return m_parent_relation->UpdateChildCoordinates(this,parent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Position and translation methods
|
||||
*/
|
||||
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
|
||||
MT_Transform GetWorldTransform() const;
|
||||
|
||||
void ComputeWorldTransforms( const SG_Spatial *parent);
|
||||
bool ComputeWorldTransforms( const SG_Spatial *parent);
|
||||
|
||||
/**
|
||||
* Bounding box functions.
|
||||
@@ -217,7 +217,7 @@ protected:
|
||||
* any controllers to update this object.
|
||||
*/
|
||||
|
||||
void
|
||||
bool
|
||||
UpdateSpatialData(
|
||||
const SG_Spatial *parent,
|
||||
double time
|
||||
|
||||
Reference in New Issue
Block a user