Hi everyone,
first post... Well, I've done something with the irrlicht engine and without writing too much it's probably best to watch and quote what I've already written..
I wanted to make it a little more realistic... So I started with implementing real values not arbitrary game-play tuned values... So if you manually feed the formula below with the distance of earth radius you will get a gforce value of 9.79 something... quite close, and I double checked... So what does this tell me...
When my camera is on earth surface a 9.81 m/s^2 force pulls it into direction of its center. Let's say my camera is moving tangential to earth surface with 9.81 m/s, should it stay in orbit ?
Of course not, and a stone travelling at 35,316 Km/h tangential to earth surface on sea level would also not...
but somehow thats what this falsely interpreted picture put into my brain...
I got two more videos uploading...
[ame="http://www.youtube.com/watch?v=X2-GdGju5t0"]YouTube - eccentric[/ame]
They show nice orbits, but the values are wrong...
Anyway in a very unscientific way to say it, my thought was that if something is travelling with the same force forward as it's pulled towards the side, it would be a stable orbit... unfortunatley that is not the case... the length(force) of the velocity vector is nearly always longer, except maybe sometimes in perihelion of a very eccentric orbit, than the force of the pull vector, at least according to my observations.
Well to make it shorter, the real values are not working, I have to set my gravity constant to 6.67428e-7 instead of 6.67428e-11 to get good orbits... And I have no clue why...
I'll post the whole source... and continue... I'n not even able to phrase the question properly...
To give it a try... what I do is adding the pull vector to the velocity vector to and the result of that to my position to get my next position. I assumed that if pull vector and velocity vector had same length and were exactly perpendicular to each other I should find myself in a perfect circular orbit, but I was wrong...
Anyone know why ?
Current source is here...
DOWNLOAD
thx
first post... Well, I've done something with the irrlicht engine and without writing too much it's probably best to watch and quote what I've already written..
So to start with the what I try to achieve...I made a solar system that simulates newtons and keplers laws of motion using the irrlicht 3d engine... The planets position is calculated according to real data using code byStephen R.Schmitt that I ported from zeno to c/c++:
http://home.att.net/~srschmitt/planetorbits.html
Mean Orbital Elements (J2000)
(Epoche = J2000 = 1.5 January 2000)
Planet a(AU) e i[°] Omega[°] ~omega[°] L[°]
--------------------------------------------------------------------------------
Merkur 0.38709893 0.20563069 7.00487 48.33167 77.45645 252.25084
Venus 0.72333199 0.00677323 3.39471 76.68069 131.53298 181.97973
Erde 1.00000011 0.01671022 0.00005 -11.26064 102.94719 100.46435
Mars 1.52366231 0.09341233 1.85061 49.57854 336.04084 355.45332
Jupiter 5.20336301 0.04839266 1.30530 100.55615 14.75385 34.40438
Saturn 9.53707032 0.05415060 2.48446 113.71504 92.43194 49.94432
Uranus 19.19126393 0.04716771 0.76986 74.22988 170.96424 313.23218
Neptun 30.06896348 0.00858587 1.76917 131.72169 44.97135 304.88003
Pluto 39.48168677 0.24880766 17.14175 110.30347 224.06676 238.92881
The scale of the planets is proportional to each other, the distance is 1/100000.
The simulation of gravity however is greatly simplified and follows the following approach... instead of particles think camera, instead of 1 black hole think 9 planets...
The only difference is that I'm checking the gravity pull for 9 planets instead of one black hole (direction and force) and then add all vectors together... vectors with a small length have no effect, that is the same as to say distant planets have a negliable effect...http://www.linuxdevcenter.com/pub/a/linux/2000/09/15/blackhole.html?page=4
The math needed to calculate accurately the motion of objects within a gravity field (in one, two or even three dimensions) is actually quite simple. We'll be using an iterative method to solve what's called the "two body" problem. We simplify the problem even further to assume the smaller particle has no effect on the black hole.
For each moment in time, we update each particle's position based on its current velocity vector. Next, we calculate the square of the distance between our particle and the black hole. We use this as the (possibly scaled) denominator of a gravity constant to find the force of gravity being felt by the particle, thus implementing the inverse-square-law of gravity (and most other forces). The particle's current velocity vector is then updated to include the force of gravity (the vectors are added together). Lastly, we trim a small amount of velocity away from each particle, in order to simulate a slow decay of the orbits.
This simple algorithm produces true orbital dynamics which subscribe to Kepler and Newton's laws, providing the particles don't approach the singularity too closely. As seen in the image above, the orbits are ellipses, as first realized by Johannes Kepler in the early 1600s after studying the orbits of the planets. Newton later came up with his law of universal gravitation, and showed that orbits can also be parabolic or hyperbolic. Both of the latter orbit forms are "open" (the particle escapes), and can appear in our simulation.
I wanted to make it a little more realistic... So I started with implementing real values not arbitrary game-play tuned values... So if you manually feed the formula below with the distance of earth radius you will get a gforce value of 9.79 something... quite close, and I double checked... So what does this tell me...
Code:
void handleG()
{
pull = core::vector3df(0,0,0);
u32 i;
double force = 0;
for(i=0; i<planets.size(); i++)
{
//vector length is strength of gPull
//direction is determined by vector subtraction
core::vector3df planPos = planets[i]->getPosition();
camPos = camera->getPosition();
core::vector3df cam2plan = planPos-camPos;
double pdistance = planPos.getDistanceFrom(camPos);
//distance in meters
double distanceM = pdistance*scaleF*1000;
//force in km/s
//pmass[] is an array with planets mass
gforce = (6.67428e-11*pMass[i]/pow(distanceM,2))/1000;
//force in scale factor of sim
force = gforce/scaleF;
//set Direction Vector's length to pull
cam2plan.setLength(force);
//add the vector for this planet
//to the total gravity vector.
pull += cam2plan;
//printf("%fn",force);
//printf("%f ,%f ,%f ,n",pull.X,pull.Y,pull.Z);
if(i==9){
sunDistanceKM = (pdistance*scaleF);
sunDistanceAU = (sunDistanceKM/149598000.0);
}
}
//pull -= pull/200;
}
Of course not, and a stone travelling at 35,316 Km/h tangential to earth surface on sea level would also not...
but somehow thats what this falsely interpreted picture put into my brain...
I got two more videos uploading...
They show nice orbits, but the values are wrong...
Anyway in a very unscientific way to say it, my thought was that if something is travelling with the same force forward as it's pulled towards the side, it would be a stable orbit... unfortunatley that is not the case... the length(force) of the velocity vector is nearly always longer, except maybe sometimes in perihelion of a very eccentric orbit, than the force of the pull vector, at least according to my observations.
Well to make it shorter, the real values are not working, I have to set my gravity constant to 6.67428e-7 instead of 6.67428e-11 to get good orbits... And I have no clue why...
I'll post the whole source... and continue... I'n not even able to phrase the question properly...
To give it a try... what I do is adding the pull vector to the velocity vector to and the result of that to my position to get my next position. I assumed that if pull vector and velocity vector had same length and were exactly perpendicular to each other I should find myself in a perfect circular orbit, but I was wrong...
Anyone know why ?
Current source is here...
DOWNLOAD
thx