forked from: Matrix3Dのテスト

by gaziya forked from Matrix3Dのテスト (diff: 39)
♥0 | Line 51 | Modified 2011-11-05 13:05:38 | MIT License
play

ActionScript3 source code

/**
 * Copyright gaziya ( http://wonderfl.net/user/gaziya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kpea
 */

// forked from gaziya's Matrix3Dのテスト
package {
    import flash.display.Shape;
    import flash.text.TextField;
    import flash.geom.PerspectiveProjection
    import flash.geom.Matrix3D;
    import flash.events.Event;
    import flash.geom.Vector3D;
    import flash.geom.Point;
    import flash.geom.Utils3D
    import flash.display.Sprite;
    [SWF(width=465,height=465,frameRate=30)]
    
    public class FlashTest extends Sprite {
        public function FlashTest() {
            x = stage.stageWidth/2
            y = stage.stageHeight/2
            
            var length:Number = 200
            var points:Vector.<Vector3D> = new Vector.<Vector3D>()            
            points.push(new Vector3D(length,0,0))
            points.push(new Vector3D(-length,0,0))
            points.push(new Vector3D(0,length,0))
            points.push(new Vector3D(0,-length,0))
            points.push(new Vector3D(0,0,length/2))
            
            var shapes:Vector.<Shape> = new Vector.<Shape>()
            for (var i:int; i<points.length; i++) {
                shapes.push(new Shape)
                shapes[i].graphics.beginFill(0xf05000)
                shapes[i].graphics.drawCircle(0,0,30)
                addChild(shapes[i])
            }            
            
            var theta:Number = 0
            var axis:Vector3D// = new Vector3D(1,-0.5,0)                       
            var projection:PerspectiveProjection = new PerspectiveProjection()            
            var proj_matrix:Matrix3D = projection.toMatrix3D()          
           
            addEventListener(Event.ENTER_FRAME, loop)
            function loop(e:Event):void {
                theta += Math.sqrt(mouseX*mouseX+mouseY*mouseY)/35
                theta %= 360
                var matrix:Matrix3D = new Matrix3D()                
                matrix.appendRotation(theta,new Vector3D(mouseX,mouseY,0))                
                matrix.appendTranslation(0,0,length*3)                
                for (var i:int; i<points.length; i++) {
                    var t_point:Vector3D = matrix.transformVector(points[i])
                    var p_point:Vector3D = Utils3D.projectVector(proj_matrix,t_point)
                    shapes[i].x = p_point.x
                    shapes[i].y = p_point.y
                    shapes[i].z = t_point.z / 2
                }
            }    
        }
    }
}

Forked