更新时间
function advanceTime(focusedPlanet) {
if (focusedPlanet === Planets.SOLAR_SYSTEM)
daysPerFrame = daysPerFrameScale * 10
else
daysPerFrame = daysPerFrameScale * planetData[focusedPlanet].period / 100.0
// Advance the time in days
oldTimeD = currTimeD
currTimeD = currTimeD + daysPerFrame
deltaTimeD = currTimeD - oldTimeD
}
重设位置
function positionPlanet(i) {
var planet = planetData[i]
var target = planets[i]
if (i !== Planets.SUN) {
// Calculate the planet orbital elements from the current time in days
var N = (planet.N1 + planet.N2 * currTimeD) * Math.PI / 180
var iPlanet = (planet.i1 + planet.i2 * currTimeD) * Math.PI / 180
var w = (planet.w1 + planet.w2 * currTimeD) * Math.PI / 180
var a = planet.a1 + planet.a2 * currTimeD
var e = planet.e1 + planet.e2 * currTimeD
var M = (planet.M1 + planet.M2 * currTimeD) * Math.PI / 180
var E = M + e * Math.sin(M) * (1.0 + e * Math.cos(M))
var xv = a * (Math.cos(E) - e)
var yv = a * (Math.sqrt(1.0 - e * e) * Math.sin(E))
var v = Math.atan2(yv, xv)
// Calculate the distance (radius)
// TODO: Math.hypot() is ES6 and QML JS is only ES5 currently. A patch to QtQml is
// required to get Math.hypot() to work.
//var r = Math.hypot(xv, yv)
var r = Math.sqrt(Math.pow(xv, 2) + Math.pow(yv, 2))
// From http://www.davidcolarusso.com/astro/
// Modified to compensate for the right handed coordinate system of OpenGL
var xh = r * (Math.cos(N) * Math.cos(v + w)
- Math.sin(N) * Math.sin(v + w) * Math.cos(iPlanet))
var zh = -r * (Math.sin(N) * Math.cos(v + w)
+ Math.cos(N) * Math.sin(v + w) * Math.cos(iPlanet))
var yh = r * (Math.sin(w + v) * Math.sin(iPlanet))
// Apply the position offset from the center of orbit to the bodies
var centerOfOrbit = planet.centerOfOrbit
target.x = planets[centerOfOrbit].x + xh * Planets.auScale
target.y = planets[centerOfOrbit].y + yh * Planets.auScale
target.z = planets[centerOfOrbit].z + zh * Planets.auScale
}
// Calculate the rotation (roll) of the bodies. Tilt does not change.
target.roll += (deltaTimeD / planet.period) * 360 // In degrees
}