Test Cube
♥0 |
Line 93 |
Modified 2011-10-04 04:53:44 |
MIT License
archived:2017-03-20 16:29:40
ActionScript3 source code
/**
* Copyright Andras ( http://wonderfl.net/user/Andras )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qymI
*/
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class TerKocka extends Sprite
{
private var PontLista:Array
private var FeluletLista:Array
private var FszElt:Number
private var MszElt:Number
public function TerKocka():void
{
terkepetElkeszit()
FszElt = 0
MszElt = 0
render3()
x = stage.stageWidth/2
y = stage.stageHeight/2
stage.addEventListener(MouseEvent.MOUSE_MOVE, mMove)
}
private function mMove(e:MouseEvent):void
{
FszElt = mouseX / stage.stageWidth * (Math.PI * 2)
MszElt = mouseY / stage.stageHeight * (Math.PI * 2)
render3()
e.updateAfterEvent()
}
private function terkepetElkeszit():void
{
PontLista = []
PontLista.push([-1, 1,-1])
PontLista.push([ 1, 1,-1])
PontLista.push([ 1, 1, 1])
PontLista.push([-1, 1, 1])
PontLista.push([-1,-1,-1])
PontLista.push([ 1,-1,-1])
PontLista.push([ 1,-1, 1])
PontLista.push([-1,-1, 1])
FeluletLista = []
FeluletLista.push([0, 3, 7, 4])
FeluletLista.push([3, 2, 6, 7])
FeluletLista.push([5, 6, 7, 4])
FeluletLista.push([0, 1, 2, 3])
FeluletLista.push([0, 1, 5, 4])
FeluletLista.push([1, 2, 6, 5])
}
private function render3():void
{
var a_szP:Array = []
var vAtf:Number
var fAtf:Number
var vSz:Number
var fSz:Number
var xt:Number
var yt:Number
var zt:Number
var kameraTav:Number = 300
for (var i:uint = 0; i < PontLista.length; i++)
{
xt = PontLista[i][0]
yt = PontLista[i][1]
zt = PontLista[i][2]
vAtf = Math.sqrt(xt * xt + zt * zt)
vSz = Math.atan2(xt, zt) - FszElt
xt = Math.sin(vSz) * vAtf
zt = Math.cos(vSz) * vAtf
fAtf = Math.sqrt(yt * yt + zt * zt)
fSz = Math.atan2(yt, zt) + MszElt
yt = Math.sin(fSz) * fAtf
zt = Math.cos(fSz) * fAtf
zt += 4
xt *= kameraTav / zt
yt *= kameraTav / zt
a_szP.push([xt, yt])
}
graphics.clear()
graphics.beginFill(0x333333)
graphics.drawRect(-300,-300, 600, 600)
for (i = 0; i < FeluletLista.length; i++)
{
graphics.beginFill(int(0x33aa45), .2 + i/20)
for (var j:uint = 0; j < FeluletLista[i].length; j++)
{
if (!j)
{ graphics.moveTo(a_szP[FeluletLista[i][j]][0], a_szP[FeluletLista[i][j]][1]) }
else
{ graphics.lineTo(a_szP[FeluletLista[i][j]][0], a_szP[FeluletLista[i][j]][1]) }
}
graphics.endFill()
}
}
}
}