Index: source/gameengine/Ketsji/KX_GameObject.cpp =================================================================== --- source/gameengine/Ketsji/KX_GameObject.cpp (revisión: 14651) +++ source/gameengine/Ketsji/KX_GameObject.cpp (copia de trabajo) @@ -579,18 +579,42 @@ m_objectColor = rgbavec; } +void KX_GameObject::AlignToNormal(const MT_Vector3& normal) +{ + MT_Matrix3x3 orimat; + MT_Vector3 ori,z,x,y; + orimat = GetSGNode()->GetWorldOrientation(); + ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]); + z = normal; + x = ori.cross(z); + y = z.cross(x); + orimat = MT_Matrix3x3( x[0],y[0],z[0], + x[1],y[1],z[1], + x[2],y[2],z[2]); + NodeSetLocalOrientation(orimat); +} - -MT_Vector3 KX_GameObject::GetLinearVelocity() +MT_Vector3 KX_GameObject::GetLinearVelocity(bool local) { MT_Vector3 velocity(0.0,0.0,0.0); - + MT_Matrix3x3 ori, locvel; + int i, j; if (m_pPhysicsController1) { velocity = m_pPhysicsController1->GetLinearVelocity(); + + if (local) + { + ori = GetSGNode()->GetWorldOrientation(); + + for(i=0; i < 3; i++) + for(j=0; j < 3; j++) + locvel[i][j]= velocity[i]*ori[i][j]; + for(i=0; i < 3; i++) + velocity[i] = locvel[0][i] + locvel[1][i] + locvel[2][i]; + } } - return velocity; - + return velocity; } @@ -711,6 +735,7 @@ PyMethodDef KX_GameObject::Methods[] = { {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS}, + {"alignToNormal",(PyCFunction) KX_GameObject::sPyAlignToNormal, METH_VARARGS}, {"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_VARARGS}, {"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_VARARGS}, {"getOrientation", (PyCFunction) KX_GameObject::sPyGetOrientation, METH_VARARGS}, @@ -948,7 +973,15 @@ PyObject* kwds) { // only can get the velocity if we have a physics object connected to us... - return PyObjectFrom(GetLinearVelocity()); + int local = 0; + if (PyArg_ParseTuple(args,"|i",&local)) + { + return PyObjectFrom(GetLinearVelocity((local!=0))); + } + else + { + return NULL; + } } @@ -1234,8 +1267,24 @@ return NULL; } +PyObject* KX_GameObject::PyAlignToNormal(PyObject* self, + PyObject* args, + PyObject* kwds) +{ + PyObject* pynormal; + + if (PyArg_ParseTuple(args,"O",&pynormal)) + { + MT_Vector3 normal; + if (PyVecTo(pynormal, normal)) + { + AlignToNormal(normal); + Py_Return; + } + } + return NULL; +} - PyObject* KX_GameObject::PySetPosition(PyObject* self, PyObject* args, PyObject* kwds) Index: source/gameengine/Ketsji/KX_GameObject.h =================================================================== --- source/gameengine/Ketsji/KX_GameObject.h (revisión: 14651) +++ source/gameengine/Ketsji/KX_GameObject.h (copia de trabajo) @@ -252,11 +252,20 @@ /** * Return the linear velocity of the game object. */ - MT_Vector3 + MT_Vector3 GetLinearVelocity( + bool local=false ); /** + * Align the object to a given normal. + */ + void + AlignToNormal( + const MT_Vector3& normal + ); + + /** * Quick'n'dirty obcolor ipo stuff */ @@ -644,6 +653,7 @@ KX_PYMETHOD(KX_GameObject,GetOrientation); KX_PYMETHOD(KX_GameObject,SetOrientation); KX_PYMETHOD(KX_GameObject,SetVisible); + KX_PYMETHOD(KX_GameObject,AlignToNormal); KX_PYMETHOD(KX_GameObject,SuspendDynamics); KX_PYMETHOD(KX_GameObject,RestoreDynamics); KX_PYMETHOD(KX_GameObject,EnableRigidBody); Index: source/gameengine/PyDoc/KX_GameObject.py =================================================================== --- source/gameengine/PyDoc/KX_GameObject.py (revisión: 14651) +++ source/gameengine/PyDoc/KX_GameObject.py (copia de trabajo) @@ -51,6 +51,13 @@ @type orn: 3x3 rotation matrix, or Quaternion. @param orn: a rotation matrix specifying the new rotation. """ + def alignToNormal(normal): + """ + Aligns the game object's Z axis along the given normal. + + @type normal: 3d vector. + @param normal: a normal vector to align the object. + """ def getOrientation(): """ Gets the game object's orientation. @@ -58,15 +65,16 @@ @rtype: 3x3 rotation matrix @return: The game object's rotation matrix """ - def getLinearVelocity(): + def getLinearVelocity(local): """ Gets the game object's linear velocity. This method returns the game object's velocity through it's centre of mass, ie no angular velocity component. - cf getVelocity() - + @type local: boolean + @param local: - False: you get the "global" velocity ie: relative to world orientation. + - True: you get the "local" velocity ie: relative to object orientation. @rtype: list [vx, vy, vz] @return: the object's linear velocity. """ @@ -138,6 +146,9 @@ def setParent(parent): """ Sets this object's parent. + + @type parent: L{KX_GameObject} + @param parent: new parent object. """ def removeParent(): """