Here’s my second attempt at getting a planet to revolve… this time I used trig to push it around in a circle, instead of just rotating its container as I did before. Here is the result:
package{importflash.display.Sprite;importflash.events.Event;publicclassThreed2extendsSprite{privatevarcenterX:Number=200;privatevarcenterY:Number=200;privatevarcenterZ:Number=0;privatevarsphere:Sphere;privatevarradius:Number=200;privatevarangle:Number=0;privatevarspeed:Number=0.05;privatevarplanets:Array;publicfunctionThreed2(){init();}privatefunctioninit():void{planets=[];//angle is rotation angle around centreangle=0;//add a planetaddPlanet(0x00ff00,100,200);addEventListener(Event.ENTER_FRAME,function(e:Event):void{revolvePlanets();});}privatefunctionrevolvePlanets():void{for(vari:int=0;i<planets.length;i++){varplanet:Sphere=planets[i];angle+=speed;planet.x=centerX+Math.cos(angle)*radius;planet.z=centerZ+Math.sin(angle)*radius;}}privatefunctionaddPlanet(pcolor:uint=0xff0000,psize:Number=30,orbit:Number=150):void{//create 'planet'varplanet:Sphere=newSphere(psize,pcolor);planet.x=orbit;planet.y=orbit;addChild(planet);planets.push(planet);}}}// Copyright (c) 2008 David Wilhelm// MIT license: http://www.opensource.org/licenses/mit-license.php