[Bf-committers] Cool BGE patches

Jonathan-David SCHRODER myselfhimself at free.fr
Tue May 6 10:33:47 CEST 2008


Hi
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.
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 ?

I'd propose to have the given function signature instead: noReturn
alignAxisToVector(str objectAxisName, bool localOrGlobal, vector
vectorToAlignGivenObjectAxisTo)
where objectAxisName is "+/-X/Y/Z" and the rest I'll let you guess.

What do you think ?

Jonathan

On Tue, May 6, 2008 at 2:47 AM, José Ignacio Romero <jose.cyborg at gmail.com>
wrote:

> 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:
> https://projects.blender.org/tracker/index.php?func=detail&aid=10492&group_id=9&atid=127
> )
>
> --
> Q:      What is purple and concord the world?
> A:      Alexander the Grape.
>
>
> 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():
>                """
>
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
>
>


-- 
http://www.jaxtr.com/myselfhimself
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-committers/attachments/20080506/9c3af3ee/attachment-0001.htm 


More information about the Bf-committers mailing list