/***********************************************\ * Layer 1: earth \***********************************************/ // creates a sphere function createSphere(trianglePathOut:GraphicsTrianglePath, vertices3DOut:Vector., radius:Number = 100, parallels:int = 5, meridians:int = 10):void { if (parallels < 3) parallels = 3; if (meridians < 3) meridians = 3; meridians++; // texture edge meridian duplicated var parallelStops:int = parallels-1; // for determining u var meridianStops:int = meridians-1; // for determining v // local variables var r:Number; // radius var x:Number, y:Number, z:Number; // coordinates var p:int, pi:int, pa:Number; // parallel vars var m:int, mi:int, ma:Number; // meridian vars var u:Number, v:Number; // u, v of uvt var n:int = -1; // vertices index // horizontal for (p=0; p, focal:Number, rotationY:Number):void { // angle calculations for rotation around y var ca:Number = Math.cos(rotationY); var sa:Number = Math.sin(rotationY); var t:Number; var i:int, n:int = vertices3DIn.length; for (i=0; i(), new Vector.(), new Vector.(), TriangleCulling.NEGATIVE); // create a vector of Vector3D objects to store // 3D locations of sphere coordinates var vectors3D:Vector. = new Vector.(); // populate triangles andvectors3D and with // sphere data createSphere(triangles, vectors3D, globeRadius, globeParallels, globeMeridians); // a new GraphicsTrianglePath container using the // same vector data as triangles is created to draw // the backside of the sphere once the darker version // of the bitmap is added to the drawing state var trianglesDark:GraphicsTrianglePath = new GraphicsTrianglePath( triangles.vertices, triangles.indices, triangles.uvtData, TriangleCulling.POSITIVE); // IGraphicsData list of drawing commands, drawing back face // first (dark), followed by front face (light) var globeData:Vector. = Vector.([ new GraphicsStroke(NaN, false, "normal", "none", "round", 3, new GraphicsSolidFill(0xFF0000)), new GraphicsBitmapFill(backFace, null, false, true), trianglesDark, new GraphicsBitmapFill(frontFace, null, false, true), triangles ]); // create globe shape var globe:Shape = new Shape(); globe.x = 275; globe.y = 200; addChild(globe); // rotate globe in frame loop addEventListener(Event.ENTER_FRAME, draw); function draw(event:Event):void { // updates the triangle data used in globeData // applying 3D perspective and rotating around Y transformIn3D(triangles, vectors3D, focal, getTimer()/1000); globe.graphics.clear(); globe.graphics.drawGraphicsData(globeData); } // show outlines when pressing the mouse stage.addEventListener(MouseEvent.MOUSE_DOWN, toggleStroke); stage.addEventListener(MouseEvent.MOUSE_UP, toggleStroke); function toggleStroke(event:MouseEvent):void { GraphicsStroke(globeData[0]).thickness = (event.type == MouseEvent.MOUSE_DOWN) ? 1 : NaN; }