bullet rigid body rotation around Y axis :|

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

bullet rigid body rotation around Y axis :|

Post by serengeor »

Using IrrBP(tough I got this happening also in bullet).
How do I properly rotate rigid body around its Y axis?

Using this:

Code: Select all

rigid->setRotation(rigid->getRotation()+irr::core::vector3df(0.0f,1.0f,0.0f));
The body flips wierdly to the other side(the side of the body becomes bottom or sth simillar) after about full circle and than rotates normaly (tough its flipper wrong way).

What could be the problem?

P.S. yeah I'm newb at 3d maths.
Working on game: Marrbles (Currently stopped).
SG57
Posts: 66
Joined: Fri May 18, 2007 5:51 am

Post by SG57 »

The idea is your Irrlicht node is connected to your bullet 'body'. So you should alter your bullet 'body' in your simulation to get your irrlicht node to do as you like.

And so, I believe you aren't supposed to directly set physics components after the initial setup stage for the simulation, so you cant just rotate the bullet body's rotation directly. It's a taboo to do so, but if you're trying to, say, cap the velocity of an object, you have no choice.

In your case, if you are trying to rotate it, I'd say you need to look into an 'addAngularVelocity' function and use the Y-component of the vector you give it as the speed to rotate bullet body. I suppose addTorque you could achieve the same thing.
__________________________________
...you'll never know what it's like, living your whole life in a dream...
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Than I guess I'll need a character controller :(
Working on game: Marrbles (Currently stopped).
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: bullet rigid body rotation around Y axis :|

Post by randomMesh »

serengeor wrote:How do I properly rotate rigid body around its Y axis?
You'd apply a torque

Code: Select all

void Player::turn(const bool left)
{
   if (!this->body)
      return;

   static const btScalar turnSpeed = 5.0;

   this->body->activate();
   this->body->applyTorque(btVector3(0, left ? -turnSpeed : turnSpeed, 0));
}
"Whoops..."
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: bullet rigid body rotation around Y axis :|

Post by serengeor »

randomMesh wrote:
serengeor wrote:How do I properly rotate rigid body around its Y axis?
You'd apply a torque

Code: Select all

void Player::turn(const bool left)
{
   if (!this->body)
      return;

   static const btScalar turnSpeed = 5.0;

   this->body->activate();
   this->body->applyTorque(btVector3(0, left ? -turnSpeed : turnSpeed, 0));
}
Doesn't work, the body activates but it doesn't rotate.
Working on game: Marrbles (Currently stopped).
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: bullet rigid body rotation around Y axis :|

Post by randomMesh »

serengeor wrote:Doesn't work, the body activates but it doesn't rotate.
Works for me, maybe your body's too heavy or something. Try to increase turnSpeed.
"Whoops..."
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

body weight 1 turnspeed 1000, no effect :shock:

EDIT: ok somehow got this working tough torque isn't what I would like to use to rotate my player as I want it to be controlled by mouse like First person game.
Working on game: Marrbles (Currently stopped).
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Post by cobra »

Serengeor:

In one of my FPS controller tests with irrBullet, I found it worked pretty well to use the Irrlicht FPS camera for basically all movement as the head. Even rotation around the Y axis.

Then a force is applied on the body in the direction the camera is pointing (except its X rotation).


Here's the input handler for it (the code is not entirely finished, as you can see, but the movement part works):

Code: Select all

void IPlayerBase::handleInput()
{
    if(isOnGround() && !Game->IsKeyDown(KEY_SPACE))
    {
        if(Game->IsKeyDown(KEY_KEY_W) || Game->IsKeyDown(KEY_KEY_S) ||
        Game->IsKeyDown(KEY_KEY_A) || Game->IsKeyDown(KEY_KEY_D))
        {
            isMoving = true;
            vector3df velocity(0,0,0);
            vector3df localForward(0,0,0);
            const matrix4& mat = device->getSceneManager()->getActiveCamera()->getAbsoluteTransformation();
            f32 MoveSpeed = 0.01f;

            if(Game->IsKeyDown(KEY_KEY_W))
            {
                localForward.Z = MoveSpeed;
                if(Game->IsKeyDown(KEY_LSHIFT))
                {
                    localForward.Z*=2.5;
                    weapon->setRotation(vector3df(30,-40,0));
                }

                else
                    weapon->setRotation(vector3df(0,0,0));
            }

            if(Game->IsKeyDown(KEY_KEY_S))
                localForward.Z = -MoveSpeed;

            if(Game->IsKeyDown(KEY_KEY_A))
                localForward.X = -MoveSpeed;

            if(Game->IsKeyDown(KEY_KEY_D))
                localForward.X = MoveSpeed;

            mat.rotateVect(velocity, localForward);
            velocity.Y = 0.0f;


            body->setLinearVelocity(velocity*2000);
        }

        else
        {
            isMoving = false;
            weapon->setRotation(vector3df(0,0,0));
        }

        if(Game->IsKeyDown(KEY_KEY_Q))
        {
            leanLeft = true;
            leanRight = false;
        }

        else if(Game->IsKeyDown(KEY_KEY_E))
        {
            leanRight = true;
            leanLeft = false;
        }
    }

    if(Game->IsKeyDown(KEY_SPACE) && isOnGround())
    {
        body->applyCentralImpulse(vector3df(0,0.2,0));
    }

    if(isLeftMouseDown && (device->getTimer()->getTime() >= lastShot+shotDelay))
        fireWeapon();
}
Josiah Hartzell
Image
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Actually here you don't rotate any dynamic rigid body, you just apply force in the direction camera is facing, or am I blind?
Working on game: Marrbles (Currently stopped).
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Post by cobra »

Yes, with my above code you just apply a force in the direction the camera is facing.

I don't think there's any sense in rotating a perfectly symmetrical capsule when you can simply apply the force in the direction the camera is pointing (make sure you set velocity.Y to 0 so it doesn't apply any upward or downward force).
Josiah Hartzell
Image
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

well I agree, capsule rotation would be unnecessary, but I'm not using capsule, its a Box.
I'm making bounding box collision for my object.
Working on game: Marrbles (Currently stopped).
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Got it to work, I had to call

Code: Select all

/**SAMPLE CODE**/
btTransform trans=body->getCenterOfMassTransform();
btQuaternion quat;
quat.setEuler(irr::core::DEGTORAD*x,irr::core::DEGTORAD*y,irr::core::DEGTORAD*z);
trans.setRotation(quat);
body->setCenterOfMassTransform(trans);
Working on game: Marrbles (Currently stopped).
Post Reply