Your initial conditions should be
vec2 sun(0.0,0.0);
vec2 earth(10.0,0.0);
vec2 speedVector = vec2(-earthToSun.y, earthToSun.x);
That looks good. However, there are two problems with your equations.
The position of your earth should change over time like this:
vec2 earthToSun = normalize(sun - earth);
earth = earth + earthToSun; // no speedVector added here
Note that I did not add speedVector
to earth in the update code. What you did there is accelerate your earth throughout your simulation.
Your normalize
function will have to normalize by the squared distance. I am not sure how you implemented that. F = g m1 m2 / r ^ 2. I suspect that your normalize
only devides by r, not r ^ 2. Check https://en.wikipedia.org/wiki/Gravitational_constant for reference
Your earth will not necessarily go in a circle. Most likely it will be an elliptical orbit. Also make sure to choose a small enough step size. Per iteration, earth
should change only by a small fraction of its distance to the sun, or otherwise you will accumulate obvious integration errors.