Hey all, I'm back with an embarrassing problem. I cannot get lighting to work. I started a new project, and got all the other basic stuff setup correctly, but the lighting wont work. I'd really appreciate help in figuring out what I did wrong, I've been trouble-shooting for a half-hour on this problem... its really brief and simple code.
NOTE: WASD keys and mouse for camera movement.
CODE BELOW:
package {
import away3d.cameras.Camera3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.core.math.Number3D;
import away3d.core.utils.Cast;
import away3d.lights.DirectionalLight3D;
import away3d.materials.BitmapMaterial;
import away3d.materials.ColorMaterial;
import away3d.primitives.Cube;
import flash.display.Bitmap;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import levels.FootballField1;
import flash.display.Sprite;
import flash.events.Event;
[SWF(backgroundColor="#000000", frameRate="60", quality="HIGH",
width="800", height="600")]
public class main extends Sprite
{
//engine variables
private var scene:Scene3D;
private var camera:Camera3D;
private var view:View3D;
private var light:DirectionalLight3D;
private var inMenusFlag:Boolean = false;
public function main()
{
initEngine();
}
private function initEngine():void
{
scene = new Scene3D();
camera = new Camera3D( { zoom:10, focus:100, x:0,
y:100, z:
-300 } );
camera.tilt(30);
view = new View3D({scene:scene, camera:camera});
stage.stageWidth = 800;
view.x = 400;
stage.stageHeight = 600;
view.y = 300;
addChild(view);
light = new DirectionalLight3D({color:0xFFFFFF,
ambient:0.25,
diffuse:0.75, specular:0.9});
light.brightness = 2;
light.x = 1;
light.y = 1;
light.z = -1;
scene.addChild(light);
var cube:Cube = new Cube( { x:0, y:15, width:10,
height:10, depth:
10 } );
cube.ownCanvas = true;
var cubeMat:ColorMaterial = new ColorMaterial(0xFFFFFF);
cube.material = cubeMat;
scene.addChild(cube);
stage.addEventListener(KeyboardEvent.KEY_DOWN,
keyPressedHandler);
addEventListener(Event.ENTER_FRAME, onEnterFrame );
}
private function keyPressedHandler (event:KeyboardEvent):void
{
if (inMenusFlag != true)
{
switch (event.keyCode)
{
case Keyboard.SPACE :
light.lookAt(new Number3D(0, 0,
0));
break;
case Keyboard.PAGE_DOWN :
camera.y -= 2;
break;
case Keyboard.PAGE_UP :
camera.y += 2;
break;
case 68 :
camera.moveRight(2);
break;
case 65 :
camera.moveLeft(2);
break;
case 83 :
camera.moveBackward(2);
break;
case 87 :
camera.moveForward(2);
break;
}
}
}
private function onEnterFrame(e:Event):void
{
if (inMenusFlag != true)
{
if (mouseX >= 700)
{
camera.rotationY += 1;
}
else if (mouseX <= 100)
{
camera.rotationY -= 1;
}
else if (mouseY >= 550)
{
camera.tilt(1);
}
else if (mouseY <= 50)
{
camera.tilt( -1);
}
}
view.render();
}
}
}
