经过我一天的努力总算是弄好了哈哈虽然很菜但是总算弄出个东西了这个是以x轴为中心点转动暂时没有加进交互。Code1package2{3 经过我一天的努力 总算是弄好了 哈哈 虽然很菜但是总算
经过我一天的努力 总算是弄好了 哈哈 虽然很菜但是总算弄出个东西了这个是以x轴为中心点转动暂时没有加进交互。
Code 1 package 2 { 3 import __AS3__.vec.Vector; 4 5 import flash.display.Bitmap; 6 import flash.display.Sprite; 7 import flash.display.StageAlign; 8 import flash.display.StageScaleMode; 9 import flash.display.TriangleCulling; 10 import flash.events.Event; 11 12 [SWF(backgroundColor0x000000, width800, height800)] 13 public class ImageSphere1 extends Sprite 14 { 15 [Embed(source"map.jpg")] 16 private var ImageClass:Class; 17 18 private var vertices:Vector. new Vector.(); 19 private var indices:Vector. new Vector.(); 20 private var uvtData:Vector. new Vector.(); 21 private var bitmap:Bitmap; 22 private var sprite:Sprite; 23 private var centerZ:int 500; 24 private var cols:int 20; 25 private var rows:int 20; 26 private var focalLength:Number 1000; 27 private var radius:Number 200; 28 private var offset:int 0; 29 private var zSaver:Array[]; 30 private var xSaver:Array[]; 31 private var ySaver:Array[]; 32 private var DAngle:Number .02; 33 public function ImageSphere1() 34 { 35 stage.align StageAlign.TOP_LEFT; 36 stage.scaleMode StageScaleMode.NO_SCALE; 37 38 sprite new Sprite(); 39 sprite.x 400; 40 sprite.y 400; 41 addChild(sprite); 42 43 bitmap new ImageClass() as Bitmap; 44 makeTriangles(); 45 46 47 } 48 49 private function onEnterFrame(event:Event):void 50 { 51 draws(); 52 } 53 54 55 private function makeTriangles():void 56 { vertices.length 0; 57 uvtData.length 0; 58 var zpos:Number 0; 59 var ypos:Number 0; 60 var xpos:Number 0; 61 for(var i:int 0; i < rows; i) 62 { 63 for(var j:int 0; j < cols; j) 64 { 65 if(i < rows - 1 j, 68 i * cols j 1, 69 (i 1) * cols j); 70 71 indices.push(i * cols j 1, 72 (i 1) * cols j 1, 73 (i 1) * cols j); 74 75 } 76 77 var angle:Number Math.PI *2/ (rows - 1) * j; 78 var dR:Number2*radius/(rows-1); 79 var scale:Number 0; 80 81 ypos radius-i*dR; 82 ySaver.push(ypos); 83 84 zpos Math.cos(angle)*Math.sqrt(radius*radius-ypos*ypos); 85 zSaver.push(zpos); 86 87 xpos Math.sin(angle)*Math.sqrt(radius*radius-ypos*ypos); 88 xSaver.push(xpos); 89 90 scale focalLength / (focalLength zpos centerZ); 91 vertices.push(xpos * scale, ypos * scale); 92 93 uvtData.push(j / (cols - 1), i / (rows - 1)); 94 uvtData.push(scale); 95 96 97 }//for 98 }//for 99 100 sprite.graphics.clear();101 102 103 sprite.graphics.lineStyle(1, 5, .8);104 //graphics.beginFill(0xFF8F05);105 sprite.graphics.drawTriangles(vertices, indices, uvtData);106 trace("ini is:",vertices);107 addEventListener(Event.ENTER_FRAME, onEnterFrame);108 }//f ends109 110 private function draws():void111 { 112 113 offset;114 if(offset>1) {115 116 offset0;117 vertices.length 0;118 119 120 121 for(var i:int 0; i < zSaver.length; i)122 {123 124 125 ySaver[i] Math.cos(DAngle)*ySaver[i]-Math.sin(DAngle)*zSaver[i];126 127 zSaver[i] Math.cos(DAngle)*zSaver[i]Math.sin(DAngle)*ySaver[i];128 129 var scale:Number focalLength / (focalLength zSaver[i] centerZ);130 vertices.push(xSaver[i] * scale, ySaver[i] * scale); 131 if(i*32