I am trying to implement a game engine where a character can run and jump on the surface of a planet, with the gravity vector points towards the planet center.
I have managed to calculate the gravity vector towards the planet center with this formula:
Code: Select all
body->getMotionState()->getWorldTransform(trans);
btVector3 n = m_gravityCenter - trans.getOrigin();
n.normalize();
body->setGravity(9.8 * n);
Code: Select all
btVector3 p, q;
p.setValue(-n.getY(), n.getX(), 0);
q = p.cross(n);
btMatrix3x3 basis(
p.getX(), p.getY(), p.getZ(),
n.getX(), n.getY(), n.getZ(),
q.getX(), q.getY(), q.getZ()
);
btTransform objTransform;
body->getMotionState()->getWorldTransform(objTransform);
objTransform.setBasis(basis);
obj->setWorldTransform(objTransform);
I suppose the capsule needs to be rotated according the the basis that is formed by the normal and the tangent plane for the surface of the sphere where collision occurs, but I don't know how to calculate it (I only have the normal e.g. the gravitational vector). I have been searching on the internet and found some information about using btPlaneSpace1(n, p, q) but that produces strange results when used directly, so I only used the part where the vector "p" lies in the x-y plane:
Code: Select all
p.setValue(-n.getY(), n.getX(), 0)
- Does bullet provide a method for that, I have not found anything in the documentation?
PS. The full code can be found at: https://github.com/phoboz/tuxgal/blob/m ... Object.cpp