I am building a solar system application where a planet rotates around a star.
SHORT INTRO: To store the orbit points I have a simple vector std::vector where Point3D is a simple struct containing 3 double values for x, y, z coords. This vector contains 10’000 values of 3D points in space which define an elipse around a sun. I also have std::vector to contain speeds at every single point, so another vector of 10’000 values. Generated elipse (a vector of 10’000 values) is densily populated closer to the sun than it is further from the sun which in itself (from mathematical or scientific point of view) correct. I have checked on how to generate orbital points and orbital speeds. Objects that move towards the central body (i.e. in this case a planet moving towards sun) are increasing it’s speed, and objects that move away from the central body decrease in speed.
PROBLEM: The problem I am facing is that to render this I am using a simple FOR loop that iterates all the 10’000 points. Since every iteration (from the computational part) takes the same amount of time it makes it look like when the planet is closer to the sun it moves way slower than when it is futrther away. This is a code that I use to render the application:
void SolarSystemVTKInteractor::Step()
{
const std::unordered_map<int, StellarSystem::Planet>& planetMap = m_solarSystemModel.GetPlanetsMap();
// Check needed to ensure that during planet addition or deletion there was enough time to create planet object and planet sphere
if (m_planetSpheresMap.size() != planetMap.size())
{
return;
}
static const std::unordered_map<int, double>& planetsRotationDegrees = m_solarSystemModel.GetPlanetsRotationDegrees();
for (auto& [id, planet] : planetMap)
{
int stepIterator = planetMap.at(id).GetStepIterator();
Physics::Point3D nextOrbitalPoint = planet.GetOrbitalPoints().at(stepIterator);
m_planetSpheresMap.at(id).MoveActor(
nextOrbitalPoint.x / StellarSystem::DISTANCE_MULTIPLIER,
nextOrbitalPoint.y / StellarSystem::DISTANCE_MULTIPLIER,
nextOrbitalPoint.z / StellarSystem::DISTANCE_MULTIPLIER
);
m_planetSpheresMap.at(id).RotateActor(planetsRotationDegrees.at(id));
m_solarSystemModel.Step();
}
}
How can I fix the rendering part so that I could visually see that the objects moving towards the sun are increasing it’s speed and those that are moving away from it are decreasing in speed?
Any kind of answer is appreciated.
8