为什么不能绕任意坐标轴旋转呢?
浮云 (2009-01-14 14:51:07)
主要想实现:点击按钮btn1,让cube可以根据whichaxis的值(x或者y)来决定绕哪个轴旋转90度。
我是这样做的:生成一个cube,移动到(100,100,100),把它放在一个container里面,然后转动这个container。
可是以下代码为什么不能实现呢?让他绕x轴转,可是有时却是绕z轴或y轴转。
请帮忙诊断一下啊
主要代码如下:
//object3d
var view:View3D;
var scene:Scene3D;
var cube:Cube;
var container:ObjectContainer3D;
var count:Number=0;
// Create the view
view=new View3D();
addChild(view);
container=new ObjectContainer3D();
view.scene.addChild(container);
cube=new Cube({width:100,height:100,depth:100});
cube.moveTo(100,100,100);
container.addChild(cube);
btn1.addEventListener(MouseEvent.CLICK, dorotate);
view.render();
function dorotatex(e:Event) {
if (count<15) {
container.rotationX+=6;
count++;
view.render();
} else {
removeEventListener(Event.ENTER_FRAME, dorotatex);
}
}
function dorotatey(e:Event) {
if (count<15) {
container.rotationY+=6;
count++;
view.render();
} else {
removeEventListener(Event.ENTER_FRAME, dorotatey);
}
}
function dorotate(e:Event) {
count=0;
if (whichaxis.text=="x") {
addEventListener(Event.ENTER_FRAME, dorotatex);
} else if (whichaxis.text=="y") {
addEventListener(Event.ENTER_FRAME, dorotatey);
}
}