I am currently making a solar system in Ogre3D. The other planets revolve around the sun perfectly but when I try to revolve the moon around the earth, it revolves at a certain point NEAR earth, not around earth, which makes it intersect with the earth at times.
This is the code for creating the planet's distance from the origin (0,0,0)
Vector3 location = Vector3::ZERO;
float distance = revolverDistance;
location.x = distance; location.z = distance; location.y = 0;
planet->setPosition(location.x, location.y, location.z);
And this is the code for the revolution
Degree planetRevolution = Degree(revolution * evt.timeSinceLastFrame);
Vector3 location = Vector3::ZERO;
location.x = revolver->getPosition().x - revolve->getPosition().x;
location.z = revolver->getPosition().z - revolve->getPosition().z;
float oldX = location.x;
float oldZ = location.z;
float newX = (oldX*Math::Cos(planetRevolution)) + (oldZ*Math::Sin(planetRevolution));
float newZ = (oldX*-Math::Sin(planetRevolution)) + (oldZ*Math::Cos(planetRevolution));
mPlanet->setPosition(newX, mPlanet->getPosition().y, newZ);
- Revolve = A planet (ex. earth)
- Revolver = Another planet that is revolving around another planet (ex. moon)
For variables, I have sunDistance = 0, earthDistance = 150, and moonDistance = 155, all in which are floats.*
I have tried setting float distance = revolveDistance + revolverDistance
, and changing the distance of the moon to 5 but the point of which it revolves just moved slightly further away.
Thank you in advance!
REMINDER (Thank you to one of the people who answered for reminding me): I am not allowed to use the scene hierarchy.