I am trying to make a particle simulator using Newtons law of motion in C++.
I use a Vector class and Atom class which is represented by r - position, v - velocity and a - acceleration (im not using BulletPhysicsLibrary right now).
In Atom class I have Update function :
Code: Select all
Update(float dt)
{
r += (v * dt) + (a * 0.5f * dt * dt); // dr = v*dt + 0.5*a*dt^2
v += (a * dt); // dv/dt = a
}
I set dt for about 0.005f or 0.001f.
Now I try to simulate a normal spring using Hooke's Law.
In main program I simply write something like :
Code: Select all
my_atom->r.y = 2; // starting position, so it will get accelerated
while(...)
{
my_atom->a.y = -2*my_atom->r.y; // a = -(k/m)*x .. (-k/m)==-2
my_atom->Update(dt);
}
I think it happends because my dt isnt small enough (should be 0.00000000001 I guess but its not real to use) ?
Can someone help me solve this problem ?