▼이곳에 플래시가 삽입되어 있습니다. 




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
package kr.tibyte
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import flash.geom.Vector3D;
     
    /**
     * ...
     * @author
     */
    public class Main extends Sprite
    {
         
        [Embed(source="../../sample1.png")]
        private var SampleImage1:Class;
        [Embed(source="../../sample2.png")]
        private var SampleImage2:Class;
         
        private var _bitmaps:Vector.<Bitmap> = new Vector.<Bitmap>(IMG_NUM);
        private var _imgArr:Vector.<Sprite> = new Vector.<Sprite>(IMG_NUM);
        private var _imgWidth:int = 120;
        private var _imgHeight:int = 80;
        private var _r:Number; //회전반경
        private var _yaw:Number = 0;
        private var _container:Sprite = new Sprite();
         
        private const IMG_NUM:int = 6;
        private const THETA:Number = 0.003*3/180*Math.PI; //회전각속도
        private const MARGIN:int = 20; //이미지 간격
         
        public function Main():void
        {
             
            for (var i:int = 0; i<IMG_NUM; i++)
            {
                if (Math.random()>0.6)
                    _bitmaps[i] = new SampleImage1();
                else
                    _bitmaps[i] = new SampleImage2();
                 
                _bitmaps[i].x = -_bitmaps[i].width/2-MARGIN;
                _bitmaps[i].y = -_bitmaps[i].height/2;
                _imgArr[i] = new Sprite();
                _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 = new Point(_container.x, _container.y);
            addChild(_container);
             
            stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
        }
         
        private function mouseMoveHandler($evt:MouseEvent):void
        {
             
            var old:Point = this.transform.perspectiveProjection.projectionCenter;
            old.y = stage.mouseY;
            root.transform.perspectiveProjection.projectionCenter = old;
         
        }
         
        private function enterFrameHandler($evt:Event):void
        {
             
            //마우스로 회전제어
            _yaw += THETA*(stage.mouseX-stage.stageWidth/2);
             
            display();
         
        }
         
 
         
        private function display():void
        {
            var angle:Number;
            for (var i: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));
                 */
            }
             
            //다시 그리기
            var seq:Vector.<int> = genSequence(IMG_NUM);
            seq.sort(compare);
             
            _container.removeChildren();
            for (i = 0; i<IMG_NUM; i++)
            {
                _container.addChild(_imgArr[seq[i]]);
            }
         
             
            //z소팅을 위한 비교함수
            function compare($a:int, $b:int):Number
            {
                if (_imgArr[$a].z>_imgArr[$b].z)
                    return -1;
                else if (_imgArr[$a].z==_imgArr[$b].z)
                    return 0;
                else
                    return 1;
            }
        }
 
         
        private function genSequence($n:int):Vector.<int>
        {
            var arr:Vector.<int> = new Vector.<int>($n);
            for (var i:int = 0; i<$n; i++) {
                arr[i] = i;
            }
            return arr.concat();
        }
    }
}


액션스크립트3.0으로 만든 RGB큐브.



(▼여기에 플래시가 삽입되어 있습니다)




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
import flash.display.Shape;
import flash.geom.Vector3D;
import flash.geom.Matrix3D;
import flash.events.MouseEvent;
 
var scale:int = 160;
var density:int = 10;
var densityCube:int = density*density*density;
var points:Vector.<Shape> = new Vector.<Shape>(densityCube);
var pointsPosition:Vector.<Vector3D> = new Vector.<Vector3D>(densityCube);
var centralPoint:Vector3D = new Vector3D(stage.stageWidth/2, stage.stageHeight/2, scale/2);
var angleSpd:Number = 0;
var mouseAngle:Number = 0;
var mouseDistance:Number = 0;
var mouseSin:Number = 0;
var mouseCos:Number = 1;
 
for(var i_z:int=0; i_z<density; i_z++) {
    for(var i_y:int=0; i_y<density; i_y++) {
        for(var i_x:int=0; i_x<density; i_x++) {
            var index:int = density*density*i_z+density*i_y+i_x;
            var color:uint = int(i_z/density*256)<<16|int(i_y/density*256)<<8|int(i_x/density*256);
            points[index] = new Shape();
            points[index].graphics.beginFill(color);
            points[index].graphics.drawRect(0,0,4,4);
            points[index].graphics.endFill();
             
            pointsPosition[index] = new Vector3D();
            pointsPosition[index].x = centralPoint.x-scale/2 + i_x*scale/(density-1);
            pointsPosition[index].y = centralPoint.y-scale/2 + i_y*scale/(density-1);
            pointsPosition[index].z = centralPoint.z-scale/2 + i_z*scale/(density-1);
             
            points[index].x = pointsPosition[index].x;
            points[index].y = pointsPosition[index].y;
            points[index].z = pointsPosition[index].z;
            addChild(points[index]);
        }
    }
}
 
 
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(evt:Event):void
{
    for(var index:int=0; index<densityCube; index++) {
        pointsPosition[index].x -= centralPoint.x;
        pointsPosition[index].y -= centralPoint.y;
        pointsPosition[index].z -= centralPoint.z;
         
        var old:Vector3D = new Vector3D(pointsPosition[index].x, pointsPosition[index].y, pointsPosition[index].z);
        pointsPosition[index].y = Math.cos(angleSpd*mouseSin)*old.y - Math.sin(angleSpd*mouseSin)*old.z;
        pointsPosition[index].z = Math.sin(angleSpd*mouseSin)*old.y + Math.cos(angleSpd*mouseSin)*old.z;
        old.x=pointsPosition[index].x; old.y=pointsPosition[index].y; old.z=pointsPosition[index].z;
        pointsPosition[index].x = Math.cos(angleSpd*mouseCos)*old.x - Math.sin(angleSpd*mouseCos)*old.z;
        pointsPosition[index].z = Math.sin(angleSpd*mouseCos)*old.x + Math.cos(angleSpd*mouseCos)*old.z;
     
        pointsPosition[index].x += centralPoint.x;
        pointsPosition[index].y += centralPoint.y;
        pointsPosition[index].z += centralPoint.z;
         
        points[index].x = pointsPosition[index].x;
        points[index].y = pointsPosition[index].y;
        points[index].z = pointsPosition[index].z;
    }
 
}
 
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
function mouseMoveHandler(evt:MouseEvent):void
{
    var dx:Number = stage.mouseX-stage.stageWidth/2;
    var dy:Number = stage.mouseY-stage.stageHeight/2;
    mouseDistance = Math.sqrt(dx*dx+dy*dy);
    mouseCos = dx/mouseDistance;
    mouseSin = dy/mouseDistance;
    angleSpd = mouseDistance/2000;
}






===========================================================================================








구의 일부분이 되는 붉게 표시한 원을 구할 때

원의 반지름은 rcos(t)

중심점으로부터의 높이는 rsin(t)



point.z = r*sin(t);

point.x = r*cos(t)*cos(경도);  

point.y = r*cos(t)*sin(경도);


z값은 중심점으로부터의 높이로 두고

x와 y값은 반지름( rcos(t) )에 경도의 코사인값과 사인값을 취하여 곱한다.










+ Recent posts