Does anyone know any c++/opengl sourcecode demos for 2D rigid body physics using runge kutta?
I want to build a physics engine but I need some reference code to understand better how others have implemented this.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a lot of things you have to take care to do this nicely. I will focus on the integrator implementation and what I have found works good for me.
For all the degrees of freedom in your system implement a function to return the accelerations
aas a function of timet, positionsxand velocitiesv. This should operate on arrays or vectors of quantities and not just scalars.After each
RKstep evaluate the acceleration to be ready for the next step. In the loop then do this:Why? Well the standard
RKmethod requires you to make a2xNstate vector, but the derivatives of the fistNelements are equal to the lastNelements. If you split the problem up to twoNstate vectors and simplify a little you will arrive at the above scheme for 2nd orderRK.I have done this and the results are identical to commercial software for a plan system with
N=6degrees of freedom.