纳金网
标题:
Flash3D学习——Sandy学习笔记 [6]
[打印本页]
作者:
.
时间:
2012-8-23 11:27
标题:
Flash3D学习——Sandy学习笔记 [6]
总看这个立方体的确让人乏味,咱们接下来换个形状。参考官方例子试试圆锥体(Cone)和多面体(Hedra)。
这个例子中将两个实例合并在一个组里,并通过键盘控制组的移动,实现两个物体的联动效果。
代码:
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;
public function fuxi() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//创建一个摄像机
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 );
//创建实时侦听
addEventListener( Event.ENTER_FRAME, enterFrameHandler );
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
}
var box = new Box("box", 100, 100, 100);
var myCone = new Cone("myCone", 50, 100);
var myHedra = new Hedra( "myHedra", 80, 60, 60);
var tg:TransformGroup;
var Plane
lane3D;
public function createScene() {
var g:Group = new Group();
//在场景画一个坐标定位点
Plane = new Plane3D("Texture", 300, 300);
var myXLine
ine3D = new Line3D( "x-coord", new Point3D( -20, 0, 0), new Point3D( 20, 0, 0 ));
var myYLine
ine3D = new Line3D( "y-coord", new Point3D(0, -20, 0), new Point3D( 0, 20, 0 ));
var myZLine
ine3D = new Line3D( "z-coord", new Point3D(0, 0, -20), new Point3D( 0, 0, 20 ));
//创建一个新组
tg = new TransformGroup('myGroup');
//定义圆锥体和多面体的坐标
myCone.x = -160;
myCone.z = 150;
myHedra.x = 90;
//复习一下为物体着色吧
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 );
myCone.appearance = app;
myHedra.appearance = app;
//将两个物体放进新的组里
tg.addChild(myCone);
tg.addChild(myHedra);
g.addChild(tg);
g.addChild(myXLine);
g.addChild(myYLine);
g.addChild(myZLine);
//g.addChild( myCone );
//g.addChild( myHedra );
return g;
}
public function enterFrameHandler(_evt:Event) {
//box.rotateX = mouseX;
//box.rotateY = mouseY;
scene.render();
}
private function keyPressed(event:KeyboardEvent):void {
switch(event.keyCode) {
case Keyboard.UP:
tg.y +=2;
break;
case Keyboard.DOWN:
tg.y -=2;
break;
case Keyboard.RIGHT:
tg.roll +=2;
break;
case Keyboard.LEFT:
tg.roll -=2;
break;
}
}
}
}
效果:
作者:
她。
时间:
2012-11-2 09:24
作者:
她。
时间:
2012-11-2 09:24
学习了
作者:
Steven
时间:
2012-11-16 21:05
不错,学习了~~~~
作者:
fgdf#dfg
时间:
2013-2-18 16:00
过来好好学习过来好好学习
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5