WHOO!
I have been working on this myself on my own project
I will help you out.
--------- Your Code -------------
D3DXVECTOR3 dir = planet.pos - star.pos;
float d = D3DXVec3Length(&dir);
float dt = (float)period * timescale;
D3DXVec3Normalize(&dir, &dir);
planet.acc *= 0.0f;
planet.acc = -g*(star.mass)/(d*d)*dir;
planet.pos += planet.vel*dt + planet.acc*.5f*dt*dt;
planet.vel += planet.acc*dt;
My code is very similar but does not use the vector from D3DX.
First I calculate force:
for i in PlanetList:
ydist = (sun.x - i.y)
xdist = (sun.y - i.x)
i.allforce = (grav * sun.mass * i.mass)/(ydist**2+xdist**2)
if math.sqrt(ydist*ydist+xdist*xdist) > (i.rads + sun.rads): # Make sure the circles are not in each other.
i.yforce = i.yforce + math.sin(math.atan2(ydist, xdist))*i.allforce
i.xforce = i.xforce + math.cos(math.atan2(ydist, xdist))*i.allforce
Then I apply that force per object to move the objects.
def move(self, yforce, xforce):
if self.mass == 0:
self.mass = 0.00001
self.time = self.time + 0.1
self.yspd = self.yspd + (yforce/self.mass)
self.xspd = self.xspd + (xforce/self.mass)
self.y = self.y + (self.yspd) + (0.5 * (yforce/self.mass)*.1**2)
self.x = self.x + (self.xspd) + (0.5 * (xforce/self.mass)*.1**2)
works pretty well for me. Good luck