I am attempting to implement the following: a variable (large) number of stars are going to be drawn, which is easy enough, already implemented that. Each star though will have a variable number (< 10) of planets orbiting them, with each planet being constantly in motion regardless of its visibility, but will only be drawn if they are clicked on. What I am concerned with is the actual orbital motion behavior, the code below I am using has two problems:
First is that it is not orbiting at the speed I want it to (want one orbit to take 10 seconds as I said in the comments in my code below) and second is that running the third block of code causes the 'test' planet to complete one orbit, disappear, then the 'other' planet completes one orbit, disappears, and starts again from the beginning. I obviously want them to be visible at the same time, not one and then the other.
class Star : public sf::Sprite
{
private:
void Init(int xCoord,int yCoord)
{
setPosition(xCoord,yCoord);
}
public:
int xPos;
int yPos;
Star(int inX, int inY) : xPos(inX), yPos(inY)
{
Init(xPos,yPos);
}
}
class Celestial : public sf::Sprite
{
public:
void someFun(int radi, Star &parent,sf::RenderWindow &in)
{
double twoPi = 2*Pi;
double orbSpeed = (twoPi*radi) / 10; //divide by '10' because want 10 sec orbit
double s = orbSpeed*0.1; //multiply by '0.1' because want it to move every 0.1 seconds
double increment = s / radi;
double theta = 0.00;
while(theta < twoPi)
{
in.clear();
theta += increment;
if(theta == twoPi)
theta = 0;
double paramX = radi*cos(theta) + parent.xPos;
double paramY = radi*sin(theta) + parent.yPos;
setPosition(paramX,paramY);
in.draw(*this);
in.display();
}
}
}
test.someFun(100,sol,window);
other.someFun(140,sol,window);