- 最后登录
- 2018-12-19
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 54706
- 纳金币
- 32328
- 精华
- 41
|
刚才实现了将两个实例放进一个组里,可以实现联动的效果,那么单独的实例能否单独定义呢?
当然可以。
下面将两个实例,以Y轴实现旋转。
这里用到了,pan 属性,实现的是实例沿Y轴旋转。
代码:
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 Planelane3D;
public function createScene() {
var g:Group = new Group();
//在场景画一个坐标定位点
Plane = new Plane3D("Texture", 300, 300);
var myXLineine3D = new Line3D( "x-coord", new Point3D( -20, 0, 0), new Point3D( 20, 0, 0 ));
var myYLineine3D = new Line3D( "y-coord", new Point3D(0, -20, 0), new Point3D( 0, 20, 0 ));
var myZLineine3D = 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;
myHedra.pan += 4;
myCone.pan -= 4;
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;
}
}
}
}
效果:
|
|