Skip to content

Instantly share code, notes, and snippets.

@mosra
Created September 13, 2012 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosra/3718006 to your computer and use it in GitHub Desktop.
Save mosra/3718006 to your computer and use it in GitHub Desktop.
void RigidBodyGroup::physicsStep(GLfloat timeDelta) {
for(RigidBody* body: bodies) {
/* Compute force at current position */
body->force = _gravity;
body->physicsStep();
GLfloat accelerationHalfTimeDelta = (body->force/(body->_mass*2))*timeDelta;
/* New position */
body->transformation()[3].setXyz(body->transformation()[3].xyz() + (body->velocity + accelerationHalfTimeDelta)*timeDelta);
/* Compute force at new position */
body->force = _gravity;
body->physicsStep();
/* New velocity */
body->velocity += accelerationHalfTimeDelta + (body->force/(body->_mass*2))*timeDelta;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment