[ActionScript 3.0] AS3 to draw a tetrahedron (line)

Source: Internet
Author: User
Tags addchild

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-8 a.m. 11:03:11 -      * -      */ the[SWF (width=" the", height=" the")] -      Public classLinetetrahedronextendsSprite -     { -         Private var_facearr:array = []; +         Private var_r: Number= 50;//The projected values of vertices on each axis -         Private var_focus: Number= 200;//focal length +         Private var_linecontainer:sprite; A         Private var_container:sprite; at         Private var_vertexarr:array = [{x:-_r,y:_r,z:-_r},{x:_r,y:_r,z:_r},{x:-_r,y:-_r,z:_r},{x:_r,y:-_r,z:-_r}]; -          Public functionLinetetrahedron () -         { - 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); $_linecontainer.graphics.moveto (_facearr[0]. X,_facearr[0]. Y); -_linecontainer.graphics.lineto (_facearr[1]. X,_facearr[1]. Y); -_linecontainer.graphics.lineto (_facearr[2]. X,_facearr[2]. Y); -_linecontainer.graphics.lineto (_facearr[0]. X,_facearr[0]. Y); A_linecontainer.graphics.lineto (_facearr[3]. X,_facearr[3]. Y); +_linecontainer.graphics.lineto (_facearr[1]. X,_facearr[1]. Y); the_linecontainer.graphics.moveto (_facearr[3]. X,_facearr[3]. Y); -_linecontainer.graphics.lineto (_facearr[2]. X,_facearr[2]. Y); $         } the         Private functionCreateface ():void the         { the              for(varI:int = 0;i<4;i++){ the                 varMc:MovieClip=New MovieClip(); - _container.addchild (MC); in _facearr.push (MC); themc.x =_vertexarr[i].x; theMC.Y =_vertexarr[i].y; AboutMc.z =_vertexarr[i].z; the             } the         } the     } +}

[ActionScript 3.0] AS3 to draw a tetrahedron (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.