ok I have my gravity equation, how would I go about putting this into speeds? (x and y speeds)...? Maybe the next step would be A = F/M? :confused:
Printable View
ok I have my gravity equation, how would I go about putting this into speeds? (x and y speeds)...? Maybe the next step would be A = F/M? :confused:
'speed' is a scalar quantity (it is just a magnitude), what you are talking about is 'velocity', which is a vector quantity because it has both a magnitude and a direction. It's a minor technical point :)
Yes, I would suggest you go ahead with a = f/m.
ok im doing good, but I'm having trouble using the gravity constant, it's so small....that the computer reads it as 0...
const double grav = (6.7*pow(10,-11));
comes up as 0 when I test it in a messagebox
:(
ok can someone check my math? here's my algorithm:
SetMoons() just draws the moons from the information in each class....Code://get x force
//get radius
xradius = body1.x-body2.x;
xforce = grav*((body1.mass * body2.mass) / (xradius));
xaccel = (xforce / body2.mass);
body2.xspeed = body2.xspeed + xaccel;
body2.x = body2.x + body2.xspeed;
//get y force
//get radius
yradius = body1.y-body2.y;
yforce = (grav * body1.mass * body2.mass) / (yradius);
yaccel = (yforce / body2.mass);
body2.yspeed = body2.yspeed + yaccel;
body2.y = body2.y + body2.yspeed;
SetMoons();
basically I get the force from the equation
F = constant * ((m1*m2)/radius2);
and then put that into A = MF
Accel = body1.mass * force;
and then added accel to the speed....I did this for X and Y....but it doesn't work right
anyone? :(
its not working....the "moon" goes all over the place...
I think your Force formula should be like this:
F = (constant * m1*m2)/radius2;
and you're also not squaring your radius in your code so it should be like:
xforce = (grav* body1.mass * body2.mass) / xradius2;
yforce = (grav * body1.mass * body2.mass) / yradius2;
:cool:
Good job! It looks really amazing!:cool:
BTW, I think there's a bug when closing the window. Perhaps you can stop your loop or timer for drawing when a WM_CLOSE or WM_DESTORY message is sent to your window?
Yeah sorry, while the animation (for loop) is going to make it able to be seen I put some sleep statements in there. Im not too good with animation.
BTW Without the sleep statement it looks really cool..I thnk I added that one into the zip too :cool:
You should create a background thread to do the drawing, else the app can only be closed with Ctrl+Alt+Del. Or use PeekMessage instead of GetMessage and use idle time for drawing.