Five3D Solar System
May 29th, 2009
This movie requires Flash Player 9
A simple Five3D example. There are a lot of ways this could be accomplished.
My approach for the display order of the planets was to create a duplicate of every planet, one displaying in front of the sun and the other behind it. Based on the each planets rotationX property I set which of the planets two planets should be visible.
Using a mask would be a much easier and simpler solution, but I could not get it to work properly with the Sprite3D objects.
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import five3D.display.Scene3D;
import five3D.display.Sprite3D;
import flash.filters.GlowFilter;
public class SolarSystem extends Sprite
{
private var _scene:Scene3D;
private var _solarSystem:Sprite3D;
private var _solarSystemDarkSide:Sprite3D;
private var _planets:Array = [];
private var _planetsDarkside:Array = [];
private var _sun:Sprite3D;
private var _sunSize:Number = 50;
private var _orbits:Array = [];
private var _orbitsDarkside:Array;
///////Numbers are not based on much free to adjust them
private var _orbitSpeeds:Array = [25,19,11,9,5.6,4.5,2.5,1];
private var _planetDistance:Array = [15,22,30,37,55,85,115,140];
private var _planetSize:Array = [2.5,5,5,3.5,10,7,6.5,5.5];
private var _planetColors:Array = [0x99CC99,0x993300,0x336699,0x999900,0x996633,0x999933,0x0099CC,0x99CCCC];
private var _planetSizeRadio:Number = 3;
private var _planetDistanceRatio:Number = 3;
private var _filters:Array = [new GlowFilter()];
public function SolarSystem()
{
_scene = new Scene3D();
_scene.viewDistance = 450;
_scene.x = stage.stageWidth / 2;
_scene.y = stage.stageHeight / 2;
_scene.scaleX = _scene.scaleY = 0.4;
addChild(_scene);
_solarSystemDarkSide = new Sprite3D();
_scene.addChild(_solarSystemDarkSide);
_solarSystem = new Sprite3D();
_scene.addChild(_solarSystem);
_sun = new Sprite3D();
_sun.graphics3D.beginFill(0xCCCC00);
_sun.graphics3D.drawCircle(0,0,_sunSize);
_filters[0].blurX = _filters[0].blurY = 19;
_filters[0].color = 0xCCCC00;
_sun.filters = _filters;
_solarSystem.addChild(_sun);
addPlanets();
_solarSystem.addEventListener(Event.ENTER_FRAME,orbit);
_solarSystem.rotationZ = 110;
_solarSystemDarkSide.rotationZ = 110;
}
private function orbit(e:Event):void
{
for(var i:int = 0; i < _orbits.length; i++)
{
_orbits[i].rotationX -= _orbitSpeeds[i] * 0.1;
_orbitsDarkside[i].rotationX -= _orbitSpeeds[i] * 0.1;
_planets[i].rotationX += _orbitSpeeds[i] * 0.1;
_planetsDarkside[i].rotationX += _orbitSpeeds[i] * 0.1;
////////////determines which orbit is visible
if(_orbits[i].rotationX < 180 &amp;&amp; _orbits[i].rotationX > 0)
{
_orbits[i].alpha = 0;
_orbitsDarkside[i].alpha = 1;
}else{
_orbits[i].alpha = 1;
_orbitsDarkside[i].alpha = 0;
}
}
}
private function addPlanets():void
{
_orbitsDarkside = new Array(_planetDistance.length);
for(var i:int = 0; i < _planetDistance.length; i++)
{
var orbit:Sprite3D = new Sprite3D();
var planet:Sprite3D = new Sprite3D();
var orbitDarkside:Sprite3D = new Sprite3D();
var planetDarkside:Sprite3D = new Sprite3D();
planet.graphics3D.beginFill(_planetColors[i]);
planet.graphics3D.drawCircle(0,0,(_planetSize[i] / 2) * _planetSizeRadio);
planet.y = _sunSize / 2 + _planetDistance[i] * _planetDistanceRatio;
planetDarkside.graphics3D.beginFill(_planetColors[i]);
planetDarkside.graphics3D.drawCircle(0,0,(_planetSize[i] / 2) * _planetSizeRadio);
planetDarkside.y = _sunSize / 2 + _planetDistance[i] * _planetDistanceRatio;
_filters[0].color = _planetColors[i];
_filters[0].blurX = _filters[0].blurY = 6;
planet.filters = _filters;
planetDarkside.filters = _filters;
orbit.addChild(planet);
_solarSystem.addChild(orbit);
_planets.push(planet);
_orbits.push(orbit);
orbitDarkside.addChild(planetDarkside);
_solarSystemDarkSide.addChild(orbitDarkside);
_orbitsDarkside[_orbitsDarkside.length - (_orbitsDarkside.length - i)] = orbitDarkside;
_planetsDarkside[_orbitsDarkside.length - (_orbitsDarkside.length - i)] = planetDarkside;
}
}
}
}