| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | packagekr.tibyte{    importflash.display.Bitmap;    importflash.display.BitmapData;    importflash.display.Shape;    importflash.display.Sprite;    importflash.events.Event;    importflash.events.MouseEvent;    importflash.geom.Point;    importflash.geom.Vector3D;        /**     * ...     * @author     */    publicclassMain extendsSprite    {                [Embed(source="../../sample1.png")]        privatevarSampleImage1:Class;        [Embed(source="../../sample2.png")]        privatevarSampleImage2:Class;                privatevar_bitmaps:Vector.<Bitmap> = newVector.<Bitmap>(IMG_NUM);        privatevar_imgArr:Vector.<Sprite> = newVector.<Sprite>(IMG_NUM);        privatevar_imgWidth:int= 120;        privatevar_imgHeight:int= 80;        privatevar_r:Number; //회전반경        privatevar_yaw:Number= 0;        privatevar_container:Sprite = newSprite();                privateconstIMG_NUM:int= 6;        privateconstTHETA:Number= 0.003*3/180*Math.PI; //회전각속도        privateconstMARGIN:int= 20; //이미지 간격                publicfunctionMain():void        {                        for(vari:int= 0; i<IMG_NUM; i++)            {                if(Math.random()>0.6)                    _bitmaps[i] = newSampleImage1();                else                    _bitmaps[i] = newSampleImage2();                                _bitmaps[i].x = -_bitmaps[i].width/2-MARGIN;                _bitmaps[i].y = -_bitmaps[i].height/2;                _imgArr[i] = newSprite();                _imgArr[i].addChild(_bitmaps[i]);                _imgArr[i].width = _imgWidth;                _imgArr[i].height = _imgHeight;                _container.addChild(_imgArr[i]);            }            //회전반경을 이미지크기+마진값에 딱 맞게 설정            _r = (_imgWidth+2*MARGIN)/(2*Math.tan(Math.PI/IMG_NUM));                        _container.x = 200;            _container.y = 150;            this.transform.perspectiveProjection.projectionCenter = newPoint(_container.x, _container.y);            addChild(_container);                        stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);            stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);        }                privatefunctionmouseMoveHandler($evt:MouseEvent):void        {                        varold:Point = this.transform.perspectiveProjection.projectionCenter;            old.y = stage.mouseY;            root.transform.perspectiveProjection.projectionCenter = old;                }                privatefunctionenterFrameHandler($evt:Event):void        {                        //마우스로 회전제어            _yaw += THETA*(stage.mouseX-stage.stageWidth/2);                        display();                }                        privatefunctiondisplay():void        {            varangle:Number;            for(vari:int= 0; i<IMG_NUM; i++)            {                angle = _yaw+i*2*Math.PI/IMG_NUM;                _imgArr[i].x = _r*Math.cos(angle);                _imgArr[i].z = _r*Math.sin(angle);                                //angle과 수직이 되도록 rotationY 를 설정                _imgArr[i].rotationY = (180/Math.PI)*-1*(Math.PI/2+angle);                                                /* //rotationY 대신 transform속성으로 회전하기                   _imgArr[i].transform.matrix3D.pointAt(new Vector3D(),Vector3D.Z_AXIS, new Vector3D(0, -1, 0));                 */            }                        //다시 그리기            varseq:Vector.<int> = genSequence(IMG_NUM);            seq.sort(compare);                        _container.removeChildren();            for(i = 0; i<IMG_NUM; i++)            {                _container.addChild(_imgArr[seq[i]]);            }                                //z소팅을 위한 비교함수            functioncompare($a:int, $b:int):Number            {                if(_imgArr[$a].z>_imgArr[$b].z)                    return-1;                elseif(_imgArr[$a].z==_imgArr[$b].z)                    return0;                else                    return1;            }        }                privatefunctiongenSequence($n:int):Vector.<int>        {            vararr:Vector.<int> = newVector.<int>($n);            for(vari:int= 0; i<$n; i++) {                arr[i] = i;            }            returnarr.concat();        }    }} | 
[flash] 3D 회전메뉴
2013. 11. 9. 00:40