You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when the planets are added - they have a physical body + orbit + moons.
this may help organize adding *all the moons.
credits @henkvanderspek
letmoon=Moon(body:PhyiscalBody.moon,orbit:Orbit.moon)letearth=Planet(body:PhyiscalBody.earth,orbit:Orbit.earth,moons:[moon])structPhyiscalBody{letradius:Floatletcolor:Colorvardiamater:Float{returnradius*2}}structOrbit{letduration:TimeIntervalletaxis:Floatletdistance:Float}structColor{letred:Floatletgreen:Floatletblue:Float}structPlanet{letbody:PhyiscalBodyletorbit:Orbitletmoons:[Moon]}structMoon{letbody:PhyiscalBodyletorbit:Orbit}structSolarSystem{varplanets:[Planet]}privateextensionSCNNode{funcrunOrbit(_orbit:Orbit){iforbit.duration<=0{return}iforbit.distance<=0{return}letdegrees=Float(360.0/orbit.duration)letangle=CGFloat(GLKMathDegreesToRadians(degrees))letrotate=SCNAction.rotateBy(x:0,y:angle,z:0,duration:1.0)letforever=SCNAction.repeatForever(rotate)runAction(forever,forKey:nil)}}privateextensionPhyiscalBody{varnode:SCNNode{letgeometry=SCNSphere(radius:CGFloat(radius))geometry.firstMaterial?.diffuse.contents=UIColor(color:color)geometry.isGeodesic=truereturnSCNNode(geometry:geometry)}}privateextensionPlanet{varnode:SCNNode{letbnode=body.nodebnode.position=SCNVector3Make(0,0,orbit.distance)letcenter=SCNNode()center.rotation=SCNVector4Make(0,0,1,GLKMathDegreesToRadians(orbit.axis))center.addChildNode(bnode)center.runOrbit(orbit)formooninmoons{letn=moon.nodecenter.addChildNode(n)}returncenter}}privateextensionMoon{varnode:SCNNode{
// Merge with duplicate stuff from above
letbnode=body.nodebnode.position=SCNVector3Make(0,0,orbit.distance)letcenter=SCNNode()center.rotation=SCNVector4Make(0,0,1,GLKMathDegreesToRadians(orbit.axis))center.addChildNode(bnode)center.runOrbit(orbit)returncenter}}extensionSolarSystem{varscene:SCNScene{letscene=SCNScene()letcamera=SCNNode.camera()letsun=SCNNode.sun()camera.addChildNode(sun)scene.rootNode.addChildNode(camera)letcenter=SCNNode()forplanetinplanets{center.addChildNode(planet.node)}scene.rootNode.addChildNode(center)returnscene}}
Activity
Add Earth's moon
johndpope commentedon Nov 18, 2017
for consideration - the way this project is structured -
https://github.com/johndpope/PhysicsTest/blob/master/PhysicsTest/ViewController.swift
when the planets are added - they have a physical body + orbit + moons.
this may help organize adding *all the moons.
credits @henkvanderspek