Well, you didn't ask for minimal, so:
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#include <cmath>
class Particle{
private:
double myMass;
double myRadius;
sf::Shape myShape;
sf::Vector2f myVelocity;
public:
Particle(double newX = 0.f, double newY = 0.f, double newMass = 2.f*3.14159265358979) :
myMass(newMass),
myRadius(newMass/(2.f*3.14159265358979)),
myShape(sf::Shape::Circle(newX, newY, myRadius, sf::Color(255, 255, 255, 255))),
myVelocity(sf::Vector2f(0.f, 0.f)){
}
double GetMass() const{
return myMass;
}
double GetRadius() const{
return myRadius;
}
const sf::Shape *GetShape() const{
return &myShape;
}
sf::Vector2f GetVelocity() const{
return myVelocity;
}
void Move(sf::Vector2f Delta){
myVelocity += Delta;
}
void Update(){
myShape.Move(myVelocity);
}
~Particle(){
}
};
std::vector<Particle> Particles;
sf::RenderWindow Window;
int main(){
Window.Create(sf::VideoMode(512, 512, 32), "Solar System Simulator", sf::Style::Close, sf::ContextSettings(24, 8, 0, 3, 2));
Window.SetFramerateLimit(50);
srand(time(NULL));
for (int i = 0; i < 100; i++){
Particles.push_back(Particle(rand()%512, rand()%512));
}
while (Window.IsOpened()){
sf::Event Event;
while (Window.GetEvent(Event)){
if (Event.Type == sf::Event::Closed || (Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Escape))
Window.Close();
}
Window.Clear();
for (unsigned int s = 0; s != Particles.size(); s++){
for (unsigned int t = s+1; t != Particles.size(); t++){
double DeltaX = Particles.at(t).GetShape()->GetPosition().x - Particles.at(s).GetShape()->GetPosition().x;
std::cout << Particles.at(t).GetShape()->GetPosition().x << '\n';
double DeltaY = Particles.at(t).GetShape()->GetPosition().y - Particles.at(s).GetShape()->GetPosition().y;
double Distance = DeltaX*DeltaX + DeltaY*DeltaY;
double Mass = Particles.at(s).GetMass() * Particles.at(t).GetMass();
double Newtons = (6.67428/100000000000.f)*Mass/Distance;
double Direction = atan2(DeltaY, DeltaX);
Particles.at(s).Move(sf::Vector2f(-cos(Direction)*Newtons/Particles.at(s).GetMass(), -sin(Direction)*Newtons/Particles.at(s).GetMass()));
Particles.at(t).Move(sf::Vector2f(cos(Direction)*Newtons/Particles.at(t).GetMass(), sin(Direction)*Newtons/Particles.at(t).GetMass()));
}
}
for (unsigned int i = 0; i != Particles.size(); i++){
Particles.at(i).Update();
Window.Draw(*Particles.at(i).GetShape());
}
Window.Display();
}
return EXIT_SUCCESS;
}
Stupid particle simulations. I don't see what the problem could be, as I have checked over my code several times, so if it is my fault, it's probably a really dumb mistake.