Sphere rotation

skeen
Posts: 24
Joined: Wed Dec 08, 2010 11:59 am

Sphere rotation

Post by skeen »

Okay, so I'm writing this code, where your controlling a sphere; Currently I'm able to move forward and backwards;

Code: Select all

    void HandleDown(Key key)
    {
        switch (key)
        {
            case KEY_w:
                db->ApplyForce(-moveDir.GetNormalize());
                break;
            case KEY_s:
                db->ApplyForce(moveDir.GetNormalize());
                break;
        }
    }
MoveDir is a vector, that holds the current way the sphere is rolling, applyForce, applies force to the center of the Sphere in that direction, thereby boosting or decreasing movement, in the current direction.

Now I'm about to implement turning, that is using 'a' and 'd'; How would I do this, when I have to take into account, that the sphere could be turning on each axis?

I tried vector crossing, and that works, but only if the Sphere is only turning on one axis, that is for a single turn it works.

Update:
I'm now doing the following:

Code: Select all

db->ApplyTorque((db->GetRotation().GetMatrix()*-rel_pos)%force);
And it seems to work, however turning a lot applies massive amount of torque to the sphere, where most of this will just have the sphere turning on a single point, is this the way to go, and then just counteract the angularmomentum?