flash on 2012-9-17
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/AtuC
*/
package {
import flash.ui.Keyboard;
import flash.text.TextField;
import flash.display.BlendMode;
import flash.display.BitmapData;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.Sprite;
import alternativ7.engine3d.containers.*;
import alternativ7.engine3d.core.*;
import alternativ7.engine3d.objects.*;
import alternativ7.engine3d.objects.Mesh;
import alternativ7.engine3d.primitives.*;
import alternativ7.engine3d.materials.*;
import alternativ7.types.*;
import alternativ7.*;
import alternativ7.engine3d.lights.*;
import alternativ7.engine3d.objects.Mesh;
public class FlashTest extends Sprite {
public var cam:Camera3D;
public var cont:Object3DContainer = new ConflictContainer();
public var pmesh:Box;
public var deb:TextField;
public var vx:Number = 0;
public var vy:Number = 0;
public var vz:Number = 0;
public function FlashTest()
{
// write as3 code here..
cam = new Camera3D();
cam.view = new View(450,450);
cam.z = -1000;
addChild(cam.view);
cont.addChild(cam);
deb = new TextField();
addChild(deb);
deb.text = Alternativa3D.version;
var p:Plane;
p = new Plane(1000, 1000, 8, 8);
p.setMaterialToAllFaces( new FillMaterial(0x4F3010,0.8,1,0) );
p.rotationX = 1.57;
p.y = 200;
p.sorting = 2;
cont.addChild(p);
pmesh = new Box(20,20,20);
pmesh.setMaterialToAllFaces( new FillMaterial(0x0000FF,1,1,0) );
cont.addChild(pmesh);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
stage.addEventListener(KeyboardEvent.KEY_DOWN, kdown);
stage.addEventListener(KeyboardEvent.KEY_UP, kup);
}//ctor
public var hx:Number = 1;
public var hz:Number = 1;
public var pa:Number = 0;
public function onEnter(e:Event):void
{
hx = Math.cos(pa);
hz = Math.sin(pa);
if (vecKey[Keyboard.LEFT]) { pa += 0.05;}
if (vecKey[Keyboard.RIGHT]) { pa -= 0.05;}
//if (vecKey[Keyboard.LEFT]) { vx += hx; vz += hz;}
//if (vecKey[Keyboard.RIGHT]) { vx -= hx; vz -= hz;}
if (vecKey[Keyboard.UP]) { vx += hx; vz += hz;}
if (vecKey[Keyboard.DOWN]) { vx -= hx; vz -= hz;}
vy += 0.2;
vx *= 0.91;
vz *= 0.91;
pmesh.x += vx;
pmesh.y += vy;
pmesh.z += vz;
pmesh.rotationY = 1.57 + -pa;
//cam.rotationY = pa;
if (vy>0 && pmesh.y >= 190) { pmesh.y = 190;vy = 0; }
var tx:Number;
var ty:Number;
tx = pmesh.x + Math.cos(pa+3.1415) * 350;
ty = pmesh.z + Math.sin(pa+3.1415) * 350;
var dx:Number;
var dz:Number;
var a:Number;
var k:Number;
dx = tx - cam.x;
dz = ty - cam.z;
var nx:Number;
var nz:Number;
var mag:Number;
mag = Math.sqrt(dx*dx+dz*dz);
if (mag == 0) { mag = 0.0000001;}
nx = dx/mag;
nz = dz/mag;
cam.x += nx * 0.1 * (mag - 20);
cam.z += nz * 0.1 * (mag - 20);
cam.y = 100;
cam.rotationY = 1.57+ -Math.atan2(pmesh.z-cam.z, pmesh.x-cam.x);
cam.render();
}//onenter
public var vecKey:Vector.<Boolean> = new Vector.<Boolean>(1024,false);
public function kdown(e:KeyboardEvent):void
{
vecKey[e.keyCode] = true;
}//kdown
public function kup(e:KeyboardEvent):void
{
vecKey[e.keyCode] = false;
}//kup
}//flashtest
}//package