[ActionScript 3.0] AS3 drawing a positive octal body (line)

Source: Internet
Author: User
Tags addchild

Analysis:

Place the octet in a 3D coordinate system whose center coordinates are at the origin (0,0,0) so that the six vertices of the eight-faceted body are located exactly on the X-, y-, and Z-axes of the 3D coordinate system, and the distance from the center of the octet to the six vertices is equal. We can assume that the distance is R, then the coordinates of the six vertices are up (0,-r,0), Down (0,r,0), around: Left (-r,0,0), right (r,0,0), Front (0,0,-r), after (0,0,r).

1  Package2 {3     ImportFlash.display.MovieClip;4     ImportFlash.display.Sprite;5     Importflash.events.Event;6     ImportFlash.geom.Point;7     ImportFlash.geom.Vector3D;8     9     /**Ten * @author Frost.yen One * @e-mail [email protected] A * @create 2015-9-7 pm 5:10:05 -      * -      */ the[SWF (width=" the", height=" the")] -      Public classLineoctahedronextendsSprite -     { -         Private var_facearr:array = []; +         Private var_r: Number= 100;//Center-to-vertex distance -         Private var_focus: Number= 200;//focal length +         Private var_linecontainer:sprite; A         Private var_container:sprite; at         Private var_vertexarr:array = [{x:0,y:_r,z:0},{x:-_r,y:0,z:0},{x:0,y:0,z:_r},{x:_r,y:0,z:0},{x:0,y:0,z:-_r},{x:0,y:-_r,z:0}]; -          Public functionLineoctahedron () -         { - initviews (); - initeventlisteners (); -         } in         Private functionInitviews ():void -         { to_container =NewSprite (); +_linecontainer =NewSprite (); -_container.x = _linecontainer.x = 400; the_CONTAINER.Y = _LINECONTAINER.Y = 300; *              This. AddChild (_container); $              This. AddChild (_linecontainer);Panax Notoginseng createface (); -              the         } +         Private functionIniteventlisteners ():void A         { the              This. AddEventListener (event.enter_frame,onenterframe); +         } -         Private functionOnenterframe (e:event):void $         { $              for(vari:int=0; i<_facearr.length; i++) -             { -_facearr[i].transform.matrix3d.appendrotation ((mousex-_linecontainer.x)/50,vector3d.y_axis); the_facearr[i].transform.matrix3d.appendrotation ((MOUSEY-_LINECONTAINER.Y)/50,vector3d.x_axis); -_facearr[i]. Z = (_facearr[i] AsMovieClip). Transform.getrelativematrix3d (_container). position.z;Wuyi_facearr[i]. X = (_facearr[i] AsMovieClip). Transform.getrelativematrix3d (_container). position.x* (_focus/(_focus+_facearr[i]. Z)); the_facearr[i]. Y = (_facearr[i] AsMovieClip). Transform.getrelativematrix3d (_container). position.y* (_focus/(_focus+_facearr[i]. Z)); -                 //using focus to achieve perspective Wu             } - _linecontainer.graphics.clear (); About_linecontainer.graphics.linestyle (3,0x00ffff); $              for(i = 1;i<=4;i++){ -                 //connect from above to four weeks; -_linecontainer.graphics.moveto (_facearr[0]. X,_facearr[0]. Y); - _linecontainer.graphics.lineto (_facearr[i]. X,_facearr[i]. Y); A                 //connect from below to four weeks; +_linecontainer.graphics.moveto (_facearr[5]. X,_facearr[5]. Y); the _linecontainer.graphics.lineto (_facearr[i]. X,_facearr[i]. Y); -                 //The surrounding vertices are interconnected; $ _linecontainer.graphics.moveto (_facearr[i]. X,_facearr[i]. Y); the_linecontainer.graphics.lineto (_facearr[i!=4?i+1:1]. X,_facearr[i!=4?i+1:1]. Y); the             } the         } the         Private functionCreateface ():void -         { in              for(varI:int = 0;i<6;i++){ the                 varMc:MovieClip=New MovieClip(); the _container.addchild (MC); About _facearr.push (MC); themc.x =_vertexarr[i].x; theMC.Y =_vertexarr[i].y; theMc.z =_vertexarr[i].z; +             } -         } the     }Bayi}

[ActionScript 3.0] AS3 drawing a positive octal body (line)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.