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;
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);
_imgArr[i].rotationY = (
180
/Math.PI)*-
1
*(Math.PI/
2
+angle);
}
var
seq:Vector.<
int
> = genSequence(IMG_NUM);
seq.sort(compare);
_container.removeChildren();
for
(i =
0
; i<IMG_NUM; i++)
{
_container.addChild(_imgArr[seq[i]]);
}
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();
}
}
}