/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/s2DW
*/
package {
import flash.events.Event;
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
deb = new TextField();
deb.width=320; deb.height=240;
deb.mouseEnabled = false;
addChild(deb);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var gt:int = 0;
/*
so this experiment is about
rendering scaled sprites in 3D
without using triangles
(its not doing sorting or clipping, just projection)
*/
public function onEnter(e:Event):void
{
setProjMat(vecProj);
graphics.clear();
graphics.lineStyle(2,0);
var i:int;
var ang:Number;
var ma:Number;
var kx:Number; var ky:Number; var kz:Number;
var num:int;
ma = gt *0.06;
num = 128;
ky = Math.sin(ma) * 32;
for (i = 0; i < num; i++)
{
ang = (6.28/num)*i + (ma*0.1);
kx = Math.cos(ang) * 64;
kz = Math.sin(ang) * 64;
drawSprite(kx,ky,-150 +kz, 16)
}//nexti
ky = Math.sin(ma) * 32;
drawSprite(0,ky,-150, 64)
gt += 1;
}//onenter
public var deb:TextField;
public function drawSprite(ax:Number, ay:Number, az:Number, rad:Number):void
{
var mat:Vector.<Number>;
mat = vecProj;
var m:Number;
var sx:Number; var sy:Number; var w:Number;
var rendw:Number; var rendh:Number;
rendw = 460*0.5;
rendh = 460*0.5;
sx = ax * mat[0] + ay * mat[4] + az * mat[8] + mat[12];
sy = ax * mat[1] + ay * mat[5] + az * mat[9] + mat[13];
w = ax * mat[3] + ay * mat[7] + az * mat[11] + mat[15];
sx /= w; sy /= w;
sx *= rendw; sy *= -rendh;
sx += rendw; sy += rendh;
m = (1/w) * rendh * rad;
//deb.text = " sx "+sx+" sy "+sy+" m "+m;
//graphics.drawRect(sx-m,sy-m,m+m,m+m);
graphics.drawCircle(sx,sy,m);
}//drawsprite
public var vecProj:Vector.<Number> = new Vector.<Number>(16,false);
public function setProjMat(vec:Vector.<Number>,
fovdeg:Number = 60.0, aspect:Number=1.0, nearp:Number = 1.0, farp:Number=1000.0):void
{ var f:Number; var i:int;
for (i = 0; i < 16; i++) { vec[i] = 0.0; }
f = 1.0 / Math.tan( (fovdeg * (3.1415 / 180.0)) * 0.5 );
if (nearp == 0) { nearp = 0.0001; }
if (farp == 0) { farp = 0.0001; }
vec[0] = f / aspect; vec[5] = f;
vec[10] = (farp + nearp) / (nearp - farp);
vec[14] = (2.0 * farp * nearp) / (nearp - farp);
vec[11] = -1.0; vec[15] = 0.0;
}//projmatrix
}//classend
}