[Bf-committers] Cool BGE patches

José Ignacio Romero jose.cyborg at gmail.com
Wed May 7 21:21:53 CEST 2008

> 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
>> )
> 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
Good idea, i expanded the function this way:

void KX_GameObject::AlignAxisToVect(const MT_Vector3& vect, int axis)
    MT_Matrix3x3 orimat;
    MT_Vector3 ori,z,x,y;
    orimat = GetSGNode()->GetWorldOrientation();
    switch (axis)
        case 0: //x axis
            ori = MT_Vector3(orimat[0][2], orimat[1][2], orimat[2][2]);
            x = vect;
            y = ori.cross(z);
            z = x.cross(y);
        case 1: //y axis
            ori = MT_Vector3(orimat[0][0], orimat[1][0], orimat[2][0]);
            y = vect;
            z = ori.cross(y);
            x = y.cross(z);
        case 2: //z axis
            ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]);
            z = vect;
            x = ori.cross(z);
            y = z.cross(x);
    orimat = MT_Matrix3x3(    x[0],y[0],z[0],

to get the negative axes, just invert the input vector, (this can be 
done in the "python integration" function ie: PyAlignAxisToVect())

More information about the Bf-committers mailing list