flash on 2012-1-27
import flash.media.Camera;
http://alternativaplatform.com/en/docs/7.7.0/index.html
♥0 |
Line 106 |
Modified 2012-10-23 16:11:52 |
MIT License
archived:2017-03-30 22:58:27
ActionScript3 source code
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/bmvc
*/
package {
import flash.display.BlendMode;
import flash.display.BitmapData;
import flash.events.KeyboardEvent;
import flash.events.Event;
//import flash.media.Camera;
//http://alternativaplatform.com/en/docs/7.7.0/index.html
import alternativ7.engine3d.containers.ConflictContainer;
import alternativ7.engine3d.containers.BSPContainer;
import alternativ7.engine3d.core.Object3DContainer;
import alternativ7.engine3d.core.Camera3D;
import alternativ7.engine3d.core.EllipsoidCollider;
import alternativ7.engine3d.objects.Mesh;
import alternativ7.engine3d.primitives.Plane;
import alternativ7.engine3d.primitives.Box;
import alternativ7.engine3d.primitives.Sphere;
import alternativ7.engine3d.primitives.GeoSphere;
import alternativ7.engine3d.core.View;
import alternativ7.engine3d.materials.Material;
import alternativ7.engine3d.materials.FillMaterial;
import alternativ7.engine3d.materials.TextureMaterial;
import alternativ7.engine3d.materials.NormalMapMaterial;
import alternativ7.engine3d.materials.FlatShadingMaterial;
import alternativ7.engine3d.materials.VertexLightMaterial;
import alternativ7.engine3d.materials.AverageLightMaterial;
import alternativ7.engine3d.materials.SphericalEnvironmentMaterial;
import alternativ7.types.Texture;
import alternativ7.engine3d.lights.AmbientLight;
import alternativ7.engine3d.lights.DirectionalLight;
import alternativ7.engine3d.lights.OmniLight;
import alternativ7.engine3d.lights.SpotLight;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var cam:Camera3D;
public var cont:BSPContainer = new BSPContainer();
public var gBox:Box;
public function FlashTest() {
// write as3 code here..
cam = new Camera3D();
cam.view = new View(500,500);
cam.z = -1000;
addChild(cam.view);
cont.addChild(cam);
var bm:BitmapData;
bm = new BitmapData(64,64,false,0);
bm.noise(123213,0,16,3,true);
var p:Plane;
p = new Plane(1000, 1000, 8, 8);
p.setMaterialToAllFaces( new TextureMaterial( bm ) );
p.rotationX = 1.57;
p.y = 200;
cont.addChild(p);
bm = new BitmapData(64,64,false,0);
bm.noise(123123);
var amb:AmbientLight;
amb = new AmbientLight(0xFF0f0F0f);
cont.addChild(amb);
var light:OmniLight;
light = new OmniLight(0xffff0000,500,1200);
//light.intensity = 1000;
light.x =-400
// light.y = -40
light.z = -400;
cont.addChild(light);
var box:Box;
box = new Box(200,200,200,1,1,1);
//box.x = 400;
// box.setMaterialToAllFaces( new FillMaterial(0) );
// box.setMaterialToAllFaces( new TextureMaterial( bm) );
box.setMaterialToAllFaces( new VertexLightMaterial( bm ) );
//box.setMaterialToAllFaces( new FlatShadingMaterial( bm ) );
box.calculateVerticesNormals();
cont.addChild(box);
gBox = box;
stage.addEventListener(Event.ENTER_FRAME, onEnter);
stage.addEventListener(KeyboardEvent.KEY_DOWN, kdown);
stage.addEventListener(KeyboardEvent.KEY_UP, kup);
}//ctor
public function onEnter(e:Event):void
{
//ref
//http://www.dakmm.com/?p=272
if (cKeyMan.isKeyDown(39) ) { cam.x -= 20;}
if (cKeyMan.isKeyDown(37) ) { cam.x += 20;}
if (cKeyMan.isKeyDown(38) ) { cam.y += 20;}
if (cKeyMan.isKeyDown(40) ) { cam.y -= 20;}
gBox.rotationY += 0.1;
cam.render();
}//onenter
public function kdown(e:KeyboardEvent):void
{
cKeyMan.setKey(e.keyCode, true);
}//kdown
public function kup(e:KeyboardEvent):void
{
cKeyMan.setKey(e.keyCode, false);
}//kup
}//flashtest
}//package
internal class cKeyMan
{
public function cKeyMan() {}//ctor (unused)
public static var vecKey:Vector.<Boolean> = new Vector.<Boolean>(512,true);
public static function setKey(k:int, b:Boolean):void
{
if (k < 0) return;
if (k >= 512) return;
vecKey[k] = b;
}//setkey
public static function isKeyDown(k:int):Boolean
{
if (k < 0) return false;
if (k >= 512) return false;
return vecKey[k];
}//iskey
}//keyman