flash.geom.PerspectiveProjectionを使わない遠近法
forked from flash.geom.Utils3Dを使わない投影 (diff: 10)
簡単にできるのに、flash.geom.PerspectiveProjectionを使ったり、遠回りをしたみたい。
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/cjok
*/
// forked from gaziya's flash.geom.Utils3Dを使わない投影
// forked from gaziya's forked from: Matrix3Dのテスト
// forked from gaziya's Matrix3Dのテスト
package {
import flash.display.Shape;
import flash.geom.Matrix3D;
import flash.events.Event;
import flash.geom.Vector3D;
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 = 100
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,20)
addChild(shapes[i])
}
var theta:Number = 0
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))
for (var i:int; i<points.length; i++) {
var v:Vector3D = matrix.transformVector(points[i])
shapes[i].x = v.x
shapes[i].y = v.y
shapes[i].z = v.z
}
}
}
}
}