Search code examples
c++game-physicsvisual-c++-2010bulletphysics

getGravity not working?


I am new to c++ as well as game development. I coded a function using bullet physics which returns the gravity of the world and it seems to be not working. It always returns 0. Though, I've initialized the world, solver, dispatcher, broadphase and collision configuration.

Here's the code:

void _setGravity(btScalar gravity) //sets the gravity of the world
{
    if(gravity > 0.f)
        gravity = -gravity;
    _dynamicsWorld->setGravity(btVector3(0, gravity, 0));
}

btScalar _getGravity(void) //returns the gravity of the world
{
return ((btScalar*)_dynamicsWorld->getGravity());
}

Is there something that I am doing wrong ?

Thank you.


Solution

  • The getGravity function returns a btVector3 by value, so you need to use resulting vectors getY to get the gravity:

    return _dynamicsWorld->getGravity().getY();