纳金网
标题:
Flash3D学习——Sandy学习笔记 [7]
[打印本页]
作者:
.
时间:
2012-8-23 11:32
标题:
Flash3D学习——Sandy学习笔记 [7]
刚才实现了将两个实例放进一个组里,可以实现联动的效果,那么单独的实例能否单独定义呢?
当然可以。
下面将两个实例,以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 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;
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;
}
}
}
}
效果:
http://www.blueidea.com/articleimg/2009/11/7221/Sandy_6.swf
作者:
她。
时间:
2012-11-2 09:25
作者:
难骑
时间:
2012-11-2 14:33
提示:
作者被禁止或删除 内容自动屏蔽
作者:
.
时间:
2012-11-8 21:26
这是一个好帖子,大家快来围观!!
作者:
89684598
时间:
2014-2-22 12:41
感谢分享!!!
欢迎光临 纳金网 (http://wwww.narkii.com/club/)
Powered by Discuz! X2.5