Hi<br>concerning alignToNormal(vect), I'm not in the developper team but am Game Engine user and this is cool for me to have this patch integrated ! Now I'd propose something a bit further for this very function.<br>
the behaviour for the current implementation is to align axis Z with a given vector. Now what if we would like to have some other axis than the Z one aligned with a vector ?<br><br>I'd propose to have the given function signature instead: noReturn alignAxisToVector(str objectAxisName, bool localOrGlobal, vector vectorToAlignGivenObjectAxisTo)<br>
where objectAxisName is "+/-X/Y/Z" and the rest I'll let you guess.<br><br>What do you think ?<br><br>Jonathan<br><br><div class="gmail_quote">On Tue, May 6, 2008 at 2:47 AM, José Ignacio Romero <<a href="mailto:jose.cyborg@gmail.com">jose.cyborg@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Here is a patch for Ketsji that improves getLinearVelocity, adding the posibility of getting the local velocity and adds one new function for aligning the object to a given normal vector: allignToNormal(vect) (really useful for f-zero style racing games and others that need realtime slopes) i couldn't separate the functions in two patches, so i send the big patch here. (the getLinearVelocity improvement alone can be found here too: <a href="https://projects.blender.org/tracker/index.php?func=detail&aid=10492&group_id=9&atid=127" target="_blank">https://projects.blender.org/tracker/index.php?func=detail&aid=10492&group_id=9&atid=127</a>)<br>
<font color="#888888">
<br>
-- <br>
Q: What is purple and concord the world?<br>
A: Alexander the Grape.<br>
<br>
</font><br>Index: source/gameengine/Ketsji/KX_GameObject.cpp<br>
===================================================================<br>
--- source/gameengine/Ketsji/KX_GameObject.cpp (revisión: 14651)<br>
+++ source/gameengine/Ketsji/KX_GameObject.cpp (copia de trabajo)<br>
@@ -579,18 +579,42 @@<br>
m_objectColor = rgbavec;<br>
}<br>
<br>
+void KX_GameObject::AlignToNormal(const MT_Vector3& normal)<br>
+{<br>
+ MT_Matrix3x3 orimat;<br>
+ MT_Vector3 ori,z,x,y;<br>
+ orimat = GetSGNode()->GetWorldOrientation();<br>
+ ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]);<br>
+ z = normal;<br>
+ x = ori.cross(z);<br>
+ y = z.cross(x);<br>
+ orimat = MT_Matrix3x3( x[0],y[0],z[0],<br>
+ x[1],y[1],z[1],<br>
+ x[2],y[2],z[2]);<br>
+ NodeSetLocalOrientation(orimat);<br>
+}<br>
<br>
-<br>
-MT_Vector3 KX_GameObject::GetLinearVelocity()<br>
+MT_Vector3 KX_GameObject::GetLinearVelocity(bool local)<br>
{<br>
MT_Vector3 velocity(0.0,0.0,0.0);<br>
-<br>
+ MT_Matrix3x3 ori, locvel;<br>
+ int i, j;<br>
if (m_pPhysicsController1)<br>
{<br>
velocity = m_pPhysicsController1->GetLinearVelocity();<br>
+<br>
+ if (local)<br>
+ {<br>
+ ori = GetSGNode()->GetWorldOrientation();<br>
+<br>
+ for(i=0; i < 3; i++)<br>
+ for(j=0; j < 3; j++)<br>
+ locvel[i][j]= velocity[i]*ori[i][j];<br>
+ for(i=0; i < 3; i++)<br>
+ velocity[i] = locvel[0][i] + locvel[1][i] + locvel[2][i];<br>
+ }<br>
}<br>
- return velocity;<br>
-<br>
+ return velocity;<br>
}<br>
<br>
<br>
@@ -711,6 +735,7 @@<br>
<br>
PyMethodDef KX_GameObject::Methods[] = {<br>
{"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS},<br>
+ {"alignToNormal",(PyCFunction) KX_GameObject::sPyAlignToNormal, METH_VARARGS},<br>
{"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_VARARGS},<br>
{"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_VARARGS},<br>
{"getOrientation", (PyCFunction) KX_GameObject::sPyGetOrientation, METH_VARARGS},<br>
@@ -948,7 +973,15 @@<br>
PyObject* kwds)<br>
{<br>
// only can get the velocity if we have a physics object connected to us...<br>
- return PyObjectFrom(GetLinearVelocity());<br>
+ int local = 0;<br>
+ if (PyArg_ParseTuple(args,"|i",&local))<br>
+ {<br>
+ return PyObjectFrom(GetLinearVelocity((local!=0)));<br>
+ }<br>
+ else<br>
+ {<br>
+ return NULL;<br>
+ }<br>
}<br>
<br>
<br>
@@ -1234,8 +1267,24 @@<br>
return NULL;<br>
}<br>
<br>
+PyObject* KX_GameObject::PyAlignToNormal(PyObject* self,<br>
+ PyObject* args,<br>
+ PyObject* kwds)<br>
+{<br>
+ PyObject* pynormal;<br>
+<br>
+ if (PyArg_ParseTuple(args,"O",&pynormal))<br>
+ {<br>
+ MT_Vector3 normal;<br>
+ if (PyVecTo(pynormal, normal))<br>
+ {<br>
+ AlignToNormal(normal);<br>
+ Py_Return;<br>
+ }<br>
+ }<br>
+ return NULL;<br>
+}<br>
<br>
-<br>
PyObject* KX_GameObject::PySetPosition(PyObject* self,<br>
PyObject* args,<br>
PyObject* kwds)<br>
Index: source/gameengine/Ketsji/KX_GameObject.h<br>
===================================================================<br>
--- source/gameengine/Ketsji/KX_GameObject.h (revisión: 14651)<br>
+++ source/gameengine/Ketsji/KX_GameObject.h (copia de trabajo)<br>
@@ -252,11 +252,20 @@<br>
/**<br>
* Return the linear velocity of the game object.<br>
*/<br>
- MT_Vector3<br>
+ MT_Vector3<br>
GetLinearVelocity(<br>
+ bool local=false<br>
);<br>
<br>
/**<br>
+ * Align the object to a given normal.<br>
+ */<br>
+ void<br>
+ AlignToNormal(<br>
+ const MT_Vector3& normal<br>
+ );<br>
+<br>
+ /**<br>
* Quick'n'dirty obcolor ipo stuff<br>
*/<br>
<br>
@@ -644,6 +653,7 @@<br>
KX_PYMETHOD(KX_GameObject,GetOrientation);<br>
KX_PYMETHOD(KX_GameObject,SetOrientation);<br>
KX_PYMETHOD(KX_GameObject,SetVisible);<br>
+ KX_PYMETHOD(KX_GameObject,AlignToNormal);<br>
KX_PYMETHOD(KX_GameObject,SuspendDynamics);<br>
KX_PYMETHOD(KX_GameObject,RestoreDynamics);<br>
KX_PYMETHOD(KX_GameObject,EnableRigidBody);<br>
Index: source/gameengine/PyDoc/KX_GameObject.py<br>
===================================================================<br>
--- source/gameengine/PyDoc/KX_GameObject.py (revisión: 14651)<br>
+++ source/gameengine/PyDoc/KX_GameObject.py (copia de trabajo)<br>
@@ -51,6 +51,13 @@<br>
@type orn: 3x3 rotation matrix, or Quaternion.<br>
@param orn: a rotation matrix specifying the new rotation.<br>
"""<br>
+ def alignToNormal(normal):<br>
+ """<br>
+ Aligns the game object's Z axis along the given normal.<br>
+<br>
+ @type normal: 3d vector.<br>
+ @param normal: a normal vector to align the object.<br>
+ """<br>
def getOrientation():<br>
"""<br>
Gets the game object's orientation.<br>
@@ -58,15 +65,16 @@<br>
@rtype: 3x3 rotation matrix<br>
@return: The game object's rotation matrix<br>
"""<br>
- def getLinearVelocity():<br>
+ def getLinearVelocity(local):<br>
"""<br>
Gets the game object's linear velocity.<br>
<br>
This method returns the game object's velocity through it's centre of mass,<br>
ie no angular velocity component.<br>
<br>
- cf getVelocity()<br>
-<br>
+ @type local: boolean<br>
+ @param local: - False: you get the "global" velocity ie: relative to world orientation.<br>
+ - True: you get the "local" velocity ie: relative to object orientation.<br>
@rtype: list [vx, vy, vz]<br>
@return: the object's linear velocity.<br>
"""<br>
@@ -138,6 +146,9 @@<br>
def setParent(parent):<br>
"""<br>
Sets this object's parent.<br>
+<br>
+ @type parent: L{KX_GameObject}<br>
+ @param parent: new parent object.<br>
"""<br>
def removeParent():<br>
"""<br>
<br>
<br>_______________________________________________<br>
Bf-committers mailing list<br>
<a href="mailto:Bf-committers@blender.org">Bf-committers@blender.org</a><br>
<a href="http://lists.blender.org/mailman/listinfo/bf-committers" target="_blank">http://lists.blender.org/mailman/listinfo/bf-committers</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.jaxtr.com/myselfhimself">http://www.jaxtr.com/myselfhimself</a>