Closed johndpope closed 7 years ago
the app needs some way to correlate an earth date / and the current cycle / rotations.
note this reference code base nests earth inside a seasonal title sphere.
seasonalTilt.addChildNode(earth)
so above - we can dynamically call
func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
updateSeasonTilt(node: earth!) // we don't know the date or do we?
}
already covered with axialTilt
let radianTilt = planet.axialTilt / 360 * 2*Float.pi
aPlanetNode.rotation = SCNVector4Make(0, 0, 1, radianTilt)
beginRotation(planet: planet, node: aPlanetNode, multiplier: 1)
func beginRotation(planet: Planet, node: SCNNode, multiplier: Double) {
// cleanup just in case
node.removeAction(forKey: "rotation")
// Normalize to Earth's rotation (earth is now 1 second)
let normalizedRotationDuration = planet.rotationDuration / Planet.earth.rotationDuration / multiplier
let action = SCNAction.createSpinAction(duration: normalizedRotationDuration)
node.runAction(action, forKey: "rotation")
}
https://github.com/johndpope/SwiftGlobe/blob/master/SwiftGlobe/SwiftGlobe.swift#L167