纳金网
标题:
Flash3D学习——Sandy学习笔记 [8]
[打印本页]
作者:
.
时间:
2012-8-23 11:38
标题:
Flash3D学习——Sandy学习笔记 [8]
天啊,又有了一个新的概念了,光源
光源也是可以移动的,可以实现物体不同位置的反光效果。
先预习一下,setDirection
setDirection(x:Number, y:Number, z:Number):void
参数:
x:Number — 光源的X坐标
y:Number — 光源的Y坐标
Z:Number — 光源的Z坐标
为了使光的效果更明显,这里用球型(Sphere)。
使用键盘的上、下、左、右、Page UP、Page Down键来控制光源坐标。
代码:
package
{
import flash.display.Sprite;
import flash.events.*;
import flash.ui.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import sandy.core.Scene3D;
import sandy.core.scenegraph.*;
import sandy.primitive.*;
import sandy.materials.*;
import sandy.materials.attributes.*;
import sandy.core.data.*;
/**
* ...
* @author ever5u
*/
public class fuxi extends Sprite
{
private var scene:Scene3D;
private var camera:Camera3D;
private var lightX = 0;
private var lightY = 0;
private var lightZ = 10;
public function fuxi() {
//创建一个摄像机
camera = new Camera3D(300, 300);
camera.x = 100;
camera.y = 100;
camera.z = -300;
camera.lookAt(0,0,0);
//创建一个 Group
var root:Group = createScene();
//创建场景
scene = new Scene3D( "scene", this, camera, root );
scene.light.setDirection(lightX, lightY, lightZ);
//创建实时侦听
addEventListener( Event.ENTER_FRAME, enterFrameHandler );
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
}
//这次用个球型
var mySphere:Sphere = new Sphere( "theSphere", 80, 32, 24);
public function createScene() {
var g:Group = new Group();
//复习一下为物体着色吧
var materialAttr:MaterialAttributes = new MaterialAttributes(
new LineAttributes( 0.5, 0x2111BB, 0.4 ),
new LightAttributes( ***e, 0.1)
);
var material:Material = new ColorMaterial( 0xFFCC33, 1, materialAttr );
material.lightingEnable = ***e;
var app:Appearance = new Appearance( material );
mySphere.appearance = app;
g.addChild( mySphere );
return g;
}
public function enterFrameHandler(_evt:Event) {
mySphere.pan += 1;
scene.render();
}
private function keyPressed(event:KeyboardEvent):void {
switch(event.keyCode) {
case Keyboard.PAGE_DOWN:
scene.light.setPower(scene.light.getPower() - 5);
break;
case Keyboard.PAGE_UP:
scene.light.setPower(scene.light.getPower() + 5);
break;
case Keyboard.UP:
lightY+=10;
scene.light.setDirection(lightX, lightY, lightZ);
break;
case Keyboard.DOWN:
lightY-=10;
scene.light.setDirection(lightX, lightY, lightZ);
break;
case Keyboard.RIGHT:
lightX+=10;
scene.light.setDirection(lightX, lightY, lightZ);
break;
case Keyboard.LEFT:
lightX-=10;
scene.light.setDirection(lightX, lightY, lightZ);
break;
}
}
}
}
效果:
【出处:蓝色理想】
作者:
她。
时间:
2012-11-2 09:25
欢迎光临 纳金网 (http://wwww.narkii.com/club/)
Powered by Discuz! X2.5