1 Package2 {3 ImportFlash.display.Bitmap;4 ImportFlash.display.BitmapData;5 ImportFlash.display.MovieClip;6 ImportFlash.display.Sprite;7 Importflash.display.TriangleCulling;8 Importflash.events.Event;9 ImportFlash.geom.ColorTransform;Ten ImportFlash.geom.Vector3D; One A /** - * @author Frost.yen - * @e-mail [email protected] the * @create 2015-9-11 pm 2:59:18 - * - */ -[SWF (width="1024x768", height="768")] + Public classRingtextureextendsSprite - { +[Embed (source="Test.jpg")] A Private var_img:class; at Private var_bmpd:bitmapdata; - Private var_pointcontainer:sprite; - Private var_graphiccontainer:sprite; - Private var_ringcontainer:sprite; - Private var_pointarr:array = [];//put all points to calculate the 2D projection coordinates for each point - Private var_arr1:array = [];//_ARR1 (two-dimensional number) place all points for setting the drawing order of points in Private var_arr2:array = [];//_ARR2 save each block, including their v,i,u,z - Private var_circle:int=40;//number of circles on the ring to Private var_num:int = 10; + Private var_ang: Number= 360/_circle; - Private var_focus: Number= 500; the Private var_h:int; * Private var_w:int; $ Public functionringtexture ()Panax Notoginseng { - initviews (); the initeventlisteners (); + } A Private functionInitviews ():void the { +_pointcontainer =NewSprite (); -_graphiccontainer =NewSprite (); $_ringcontainer =NewSprite (); $_ringcontainer.x = _graphiccontainer.x = This. stage.stagewidth*0.5; -_ringcontainer.y = _graphiccontainer.y = This. stage.stageheight*0.5; -_ringcontainer.z = 0;//must write, do not think 0 is its default value the_BMPD = (New_img () as Bitmap). BitmapData; -_graphiccontainer.transform.colortransform=NewColorTransform (1,1,1,1,50,50,50);//increase the brightness of a little fill, the picture is drawn in the _graphiccontainerWuyi This. AddChild (_ringcontainer); the This. AddChild (_graphiccontainer); - createring (); Wu } - Private functionIniteventlisteners ():void About { $ This. AddEventListener (event.enter_frame,onenterframe); - } - Private functionOnenterframe (e:event):void{ - _graphiccontainer.graphics.clear (); A_ARR2 = []; + //The total container moves around itself y,x axis with mouse movement the_ringcontainer.transform.matrix3d.prependrotation ((_graphiccontainer.x-mousex)/50,vector3d.y_axis); -_ringcontainer.transform.matrix3d.prependrotation ((MOUSEY-_GRAPHICCONTAINER.Y)/50,vector3d.x_axis); $ for(varI:int = 0;i<_pointarr.length;i++){ the_pointarr[i]. Z= (_pointarr[i] AsMovieClip). Transform.getrelativematrix3d (_graphiccontainer). position.z; the_pointarr[i]. X= (_pointarr[i] AsMovieClip). Transform.getrelativematrix3d (_graphiccontainer). position.x* (_focus/(_focus+_pointarr[i]. Z)); the_pointarr[i]. Y= (_pointarr[i] AsMovieClip). Transform.getrelativematrix3d (_graphiccontainer). position.y* (_focus/(_focus+_pointarr[i]. Z));//Added focal length control, in line with the perspective principle, to find the 2D projection coordinates of 3D points the } - for(i=0;i<_h;i++){ in for(varK:int = 0;k<_w;k++){ the varvertices:vector.< Number>=Vector.< Number> ([_arr1[i][k]. X,_ARR1[I][K]. Y,_ARR1[I+1][K]. X,_ARR1[I+1][K]. Y,_ARR1[I+1][K+1]. X,_ARR1[I+1][K+1]. Y,_ARR1[I][K+1]. X,_ARR1[I][K+1]. Y]);//coordinates the varIndices:vector.<int>=vector.<int> ([0,1,3,1,2,3]);//vertex order of a drawing triangle About varuvtdata:vector.< Number>=Vector.< Number> ([i/_h*2,k/_w*2, (i+1)/_h*2,k/_w*2, (i+1)/_h*2, (k+1)/_w*2,i/_h*2, (k+1)/_W*2]);//scale of Split bitmap theI!=40?_arr2.push ({v:vertices,i:indices,u:uvtdata,z:_arr1[i][k]. Z+_ARR1[I+1][K]. Z+_ARR1[I+1][K+1]. Z+_ARR1[I][K+1]. Z}): 0;//when h==40, if also pressed into the Uvtz, will be two ring draw beginning and end connected,,, Z is the sum of four points z coordinates, used for the subsequent sorting the the } + } -_arr2.sorton ("Z", 18); the for(i = 0;i<_arr2.length;i++){Bayi //_graphiccontainer.graphics.linestyle (1,0xff0000); the _graphiccontainer.graphics.beginbitmapfill (_BMPD); the_graphiccontainer.graphics.drawtriangles (_arr2[i]. V,_arr2[i]. I,_arr2[i]. U,triangleculling.none);//draw a triangle, do not reject the back - _graphiccontainer.graphics.endfill (); - } the } the Private functionCreatering ():void the { the for(varM:int = 0;m<2;m++){ - varSp:sprite =NewSprite ();//ring container for storing MC points the _ringcontainer.addchild (SP); theSp.z = m*160-80; the for(vari:int=0;i<=_circle;i++){94_ARR1[I+M*41] = [];//Two rings Total 82 small circles (0-40,41-81), each small circle has 11 parts, this two-dimensional array coexistence 902 points the for(varJ:int = 0;j<=_num;j++){ the varMc:MovieClip=New MovieClip(); the Sp.addchild (MC);98mc.x= (m==0) 90+15*math.cos (J*2*math.pi/_num): 15*math.cos (J*2*math.pi/_num);//90 instead of 50, it becomes conjoined and is now nested AboutMc.y= (m==0) 15*math.sin (J*2*math.pi/_num): 100+15*math.sin (J*2*math.pi/_num); -mc.z = 0;//when M is 0 o'clock, the circle is flat and the 1 o'clock is placed101 if(m==0){102 //let the coordinate point be distributed on the large circumference103Mc.transform.matrix3D.appendRotation (i*_ang,vector3d.y_axis);104}Else{ theMc.transform.matrix3D.appendRotation (i*_ang,vector3d.x_axis)106 }107 //put all points to get the two-dimensional projection coordinates for each 3d point, storing the dynamic properties X, y108 _pointarr.push (MC);109 //put all points in a two-dimensional array to set the triangle vertices of the drawtriangles the_arr1[i+m*41].push (MC);111 } the }113 the } the_h = _arr1.length-1; the_w = _arr1[0].length-1;//_h number of parallels Max index 81,_w number of meridians Max index117 }118 }119}
[ActionScript 3.0] AS3 3D Double Ring map