Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - RK4 numerical integration (for physics)

Author
Message
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 5th Oct 2012 23:20 Edited at: 13th Mar 2013 21:25
hi there long time no post

I have been doing a car physics game for some time now and i was not satisfied with the lacking accuracy and the annoying habit euler integration has to explode the simulation in your face.

so i googled abit and found a great tutorial on numerical integration using the Runge-Kutta method, but sadly it was for C++ and as C++ has the convenience of methods and such it took me quite a while to decipher as i have no previous experience with anything but DBP.

So i thought to share the deciphered DBP version of the RKĀ¤ numerical integrator.

for those uninitiated in calculus, integration is finding the area under a function ( graph ), this might sound abstract but actually it has millions of uses in physics. Euler integration is for example this : position = position+velocity*change in time this might seem right and it will work fine for platformers and such but for accurate simulation of physics the error of that method is quite too much. SO there we have integrals! but as it is quite difficult to integrate symbolically for all of your problems and solving the primitive function is not necessarily even faster than a good numerical integrator like RK4

So to the point:


THE RK4 function is the only one you have to call in your loop
THE RK4accelleration contains the simulation specific functions, here a dampened spring simulation
THE p and v vectors are position and velocity
THE t# is useless actually
THE dt# is timestep ( delta time )
the function will not return a value, it will change the p vector


this is cryptic i know, but thats because its copied straight from my porgram. IF someone is interested and have failed at deciphering my gibberish code, please ask and i will do my best to ansvear

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-29 10:01:19
Your offset time is: 2024-03-29 10:01:19