資源描述:
《flash制作3d類動畫的教程》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、繼續(xù)上次的學(xué)習(xí),接下來要試試攝像機(jī)的移動了。這里需要涉及幾個概念,攝像機(jī)的坐標(biāo)(x,y,z)和視覺角度(LookAt)攝像機(jī)的位置可以使用(x,y,z)來定位;視覺角度可以定義如何通過窗口來看場景。lookAt(p_nX:Number,p_nY:Number,p_nZ:Number)如:lookAt(0,0,0);//可以理解為通過攝像機(jī)的位置看場景。攝像機(jī)的移動方式比較有意思,如果直接修改x、y、z坐標(biāo),視覺效果會與現(xiàn)實看到的情況相同;而tilt、pan則是與場景平行移動;roll是以z軸移動,通過攝像機(jī)視野看上去是攝像機(jī)的旋轉(zhuǎn)效果。額外說一下Lin
2、e3D是在場景中繪制了線段,這里用做參考線,代碼不難理解我就不過多解釋了。代碼如下:package{importflash.display.Sprite;importflash.events.*;importflash.ui.*;importflash.display.Bitmap;importflash.display.BitmapData;importflash.display.Loader;importflash.net.URLRequest;importsandy.core.Scene3D;importsandy.core.scenegraph
3、.*;importsandy.primitive.*;importsandy.materials.*;importsandy.materials.attributes.*;importsandy.core.data.*;/***...*@authorever5u*/publicclassfuxiextendsSprite{privatevarscene:Scene3D;privatevarcamera:Camera3D;publicfunctionfuxi(){//創(chuàng)建一個攝像機(jī)camera=newCamera3D(300,300);camera.x=
4、100;camera.y=100;camera.z=-300;camera.lookAt(0,0,0);//創(chuàng)建一個Groupvarroot:Group=createScene();//創(chuàng)建場景scene=newScene3D("scene",this,camera,root);//創(chuàng)建實時偵聽addEventListener(Event.ENTER_FRAME,enterFrameHandler);stage.addEventListener(KeyboardEvent.KEY_DOWN,keyPressed);}varbox=newBox("box
5、",100,100,100);varPlane:Plane3D;publicfunctioncreateScene(){varg:Group=newGroup();//在場景畫一個坐標(biāo)定位點Plane=newPlane3D("Texture",300,300);varmyXLine:Line3D=newLine3D("x-coord",newPoint3D(-20,0,0),newPoint3D(20,0,0));varmyYLine:Line3D=newLine3D("y-coord",newPoint3D(0,-20,0),newPoint3D(0
6、,20,0));varmyZLine:Line3D=newLine3D("z-coord",newPoint3D(0,0,-20),newPoint3D(0,0,20));g.addChild(myXLine);g.addChild(myYLine);g.addChild(myZLine);g.addChild(box);returng;}publicfunctionenterFrameHandler(_evt:Event){box.rotateX=mouseX;box.rotateY=mouseY;scene.render();}publicfunc
7、tionkeyPressed(_evt:KeyboardEvent):void{switch(_evt.keyCode){caseKeyboard.UP:camera.tilt+=2;//camera.y-=2;break;caseKeyboard.DOWN:camera.tilt-=2;//camera.y+=2;break;caseKeyboard.RIGHT:camera.pan-=2;//camera.x+=2;break;caseKeyboard.LEFT:camera.pan+=2;//camera.x-=2;break;caseKeybo
8、ard.CONTROL:camera.roll+=2;break;caseKeyboard.P