ThumbWorks / AugmentedSolarSystem

An Augmented reality experience to explore planets in our Solar System
71 stars 25 forks source link

enhancement - planet tilts according to season / date #49

Closed johndpope closed 6 years ago

johndpope commented 6 years ago

https://github.com/johndpope/SwiftGlobe/blob/master/SwiftGlobe/SwiftGlobe.swift#L167

screen shot 2017-11-18 at 9 34 51 am
let kTiltOfEarthsAxisInDegrees = 23.5
let kTiltOfEarthsAxisInRadians = (23.5 * Double.pi) / 180.0

let kSkyboxSize = CGFloat(1000.0)
let kTiltOfEclipticFromGalacticPlaneDegrees = 60.2
let kTiltOfEclipticFromGalacticPlaneRadians = (60.2 * Double.pi) / 180.0

        // tilt it on it's axis (23.5 degrees), varied by the actual day of the year
        // (note that children nodes are correctly tilted with the parents coordinate space)
        let calendar = Calendar(identifier: .gregorian)
        let dayOfYear = Double( calendar.ordinality(of: .day, in: .year, for: Date())! )
        let daysSinceWinterSolstice = remainder(dayOfYear + 10.0, kDaysInAYear)
        let daysSinceWinterSolsticeInRadians = daysSinceWinterSolstice * 2.0 * Double.pi / kDaysInAYear
        let tiltXRadians = -cos( daysSinceWinterSolsticeInRadians) * kTiltOfEarthsAxisInRadians
        //
        seasonalTilt.eulerAngles = SCNVector3(x: tiltXRadians, y: 0.0, z: 0)
        scene.rootNode.addChildNode(seasonalTilt)
johndpope commented 6 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?
    }
johndpope commented 6 years ago

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")
    }