- 浏览: 1451214 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (564)
- 算法 (7)
- 流金岁月 (1)
- Javascript (30)
- actionscript (108)
- as3.0 game (14)
- flex (84)
- fms2 (27)
- 正则表达式 (7)
- 开源组件代码(as3.0) (1)
- Pv3d (13)
- Cairngorm (4)
- vbs (54)
- VB程序设计 (26)
- 计算机应用与维护 (4)
- 职场实用穿衣技巧 (3)
- 历史风云 (15)
- 淡泊明志,宁静致远 (12)
- 情感 (26)
- 杂谈 (41)
- 越南风 (14)
- DirectX (9)
- Dev-cpp (11)
- 回望百年 (2)
- 建站经验 (2)
- Python (24)
- 网络赚钱 (4)
- php (2)
- html (1)
- ob0短址网 (1)
- ob0.cn (1)
- wordpress (1)
- pandas logistic (1)
- haxe (1)
- opencv (1)
- 微信小程序 (3)
- vue (3)
- Flutter (1)
最新评论
-
GGGGeek:
第一个函数滚动监听不起作用,onPageScroll可以
微信小程序--搜索框滚动到顶部时悬浮 -
naomibyron:
解决办法:工具 -> 编译选项 -> 编译器 ...
dev-c++中编译含WINSOCK的代码出现错误的解决方法 -
haichuan11:
这个…… 代码不全真的是让人很憋屈的感觉啊
actionScript 3.0 图片裁剪及旋转 -
chenyw101:
老兄能留个QQ号吗?具体的我有些东西想请教下你
用VB制作网站登陆器 -
yantao1943:
貌似有点问题,只派发一次事件啊
使用ActionScript 2.0或ActionScript 3.0处理音频文件的提示点(cue
Papervision3D 教學 part 3.2 -- 子母視窗
想嚐試製作子母視窗的感覺,建立了兩個 Camera3D,但是並無法透過 camera2 看到 scene,然後輸出在另外一個 MC 上,或許有方法可以做到,我還需要找找看。而以下我的作法是,用 camera2 先將 scene 輸出一次,並且立即讀取其 BiemapData 將之繪製到另外一個 MC 子視窗中,然後立刻改以 camera 將 scene 重新輸出一次。程式碼如下:
package {import flash.display.*;import flash.events.*;import flash.utils.*;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*;import org.papervision3d.materials.*;import flash.geom.Rectangle;import flash.geom.Matrix;[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T3step2 extends Sprite{private static var PI:Number = Math.PI;private static var TH:Number = PI / 180;private var container:Sprite;private var scene:Scene3D;private var camera:Camera3D;private var camera2:Camera3D;private var rootNode:DisplayObject3D;private var du:Number = 0;private var photoCount:int = 9;private var movingRadius:int = 1000;private var movingHeight:int = 500;private var timer:Timer;private var childWindowScreen:Sprite;private var bd:BitmapData;private var matrix:Matrix;private var bmp:Bitmap;public function T3step2(){ // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D);}private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = movingHeight; camera.z = -movingRadius; camera.zoom = 10; camera.focus = 100; camera2 = new Camera3D(); camera2.y = movingHeight; camera2.z = -movingRadius; camera2.zoom = 10; camera2.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 3, 3), "ground"); ground.rotationX = -90; var item:DisplayObject3D = new DisplayObject3D(); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:0, z:-50}), "p1"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:90, x:-50}), "p2"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:-90, x:50}), "p3"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:180, z:50}), "p4"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationX:90, y:-50}), "p5"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationX:-90, y:50}), "p6"); item.y = 150; rootNode.addChild(item, "item"); /* timer = new Timer(1000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); */ //子母視窗 var childWindow:Sprite = new Sprite(); addChild(childWindow); var childWindowBorder:Sprite = new Sprite(); childWindow.addChild(childWindowBorder); childWindowBorder.graphics.lineStyle(2, 0xffffff); childWindowBorder.graphics.drawRect(0, 0, 100, 100); childWindowScreen = new Sprite(); childWindow.addChild(childWindowScreen); childWindow.x = 300; childWindow.y = 300;}private function loop3D(event:Event):void{ //物體本身旋轉 var item:DisplayObject3D = rootNode.getChildByName("item"); if(item!=null){ item.rotationX++; item.rotationY++; item.rotationZ++; } //carema2先將畫面記錄下來 scene.renderCamera(camera2); bd = new BitmapData(400, 400, false, 0x0000ff); matrix = new Matrix(); matrix.translate(200, 200); matrix.scale(0.25, 0.25); bd.draw(scene.container, matrix); if(bmp!=null){ childWindowScreen.removeChild(bmp); } bmp = new Bitmap(bd); childWindowScreen.addChild(bmp); bd = null; //改用carema旋轉輸出 du++; if(du==360)du=0; var newX:Number = movingRadius * formatNum(Math.cos(du*TH), 3); var newZ:Number = movingRadius * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.z = newZ; scene.renderCamera(camera);}private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt);}private function onTimer(event:TimerEvent):void{ var item:DisplayObject3D = rootNode.getChildByName("item"); if(item!=null){ var pName:String = "p" + (Math.floor(Math.random()*6)+1); var p:DisplayObject3D = item.getChildByName(pName); if(p!=null){ p.material = new BitmapFileMaterial(getFileName()); } }}private function getFileName():String{ return "http://ben.rb.chang.googlepages.com/photos"+(Math.floor(Math.random()*photoCount)+1)+".JPG";}}}
測試時,不斷搞到瀏覽器當掉,後來我將 onTimer() 時的切換各面向的貼圖部分拿掉,改善了一點點!此外,若是觀察記憶體消耗的話,會發現他很快就衝到頂點,然後只好等 Gabarge Collection(GC) 自己找時間釋放掉,才會稍微順暢幾秒鐘......$%&@#
等到整個瀏覽器關閉後,就恢復正常了!
看效果!
於 6/13/2007 06:35:00 下午 0 意見
標籤: AS3, Flash, Papervision3D
Papervision3D 教學 part 3 -- 建模
先前的練習,我們都是直接以 PaperVision3D 所提供的基本模型 Cube 來建模,然後你會發現我們貼圖時,會將這個 Cube 的六個面都貼成同樣的材質,但是通常我們的模型上每個面有不同的貼圖,所以以下我做的範例,是先建立一個叫做 item 的 DisplayObject3D,然後在這個 DisplayObject3D 中加入六個 Plane 物件,並為這六個 Plane 進行貼圖,然後將這六個 Plane 組合成 Cube 的六個面向。範例中的其他部分之前提過,包含 camera 照圓心座標旋轉,以及透過 Timer 每隔一秒亂數決定這個我們自製 Cube 中其中一面向換貼圖。程式碼如下:
package {import flash.display.*;import flash.events.*;import flash.utils.*;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T3step1 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; private var photoCount:int = 9; private var movingRadius:int = 1000; private var movingHeight:int = 500; private var timer:Timer; public function T3step1() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = movingHeight; camera.z = -movingRadius; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 10, 10), "ground"); ground.rotationX = -90; var item:DisplayObject3D = new DisplayObject3D(); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:0, z:-50}), "p1"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:90, x:-50}), "p2"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:-90, x:50}), "p3"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:180, z:50}), "p4"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationX:90, y:-50}), "p5"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationX:-90, y:50}), "p6"); item.y = 150; rootNode.addChild(item, "item"); timer = new Timer(1000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); } private function loop3D(event:Event):void{ var item:DisplayObject3D = rootNode.getChildByName("item"); if(item!=null){ item.rotationX++; item.rotationY++; item.rotationZ++; } du++; if(du==360)du=0; var newX:Number = movingRadius * formatNum(Math.cos(du*TH), 3); var newZ:Number = movingRadius * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); } private function onTimer(event:TimerEvent):void{ var item:DisplayObject3D = rootNode.getChildByName("item"); if(item!=null){ var pName:String = "p" + (Math.floor(Math.random()*6)+1); var p:DisplayObject3D = item.getChildByName(pName); if(p!=null){ p.material = new BitmapFileMaterial(getFileName()); } } } private function getFileName():String{ return "http://ben.rb.chang.googlepages.com/photos"+(Math.floor(Math.random()*photoCount)+1)+".JPG"; }}}
看效果!
於 6/13/2007 04:22:00 下午 1 意見
標籤: AS3, Flash, Papervision3D
Papervision3D 教學 part 2.3 -- 用外部圖檔做貼圖材質
貼圖材質,除了可以貼純色 (ColorMaterial) 與 BitmapData (BitmapMaterial) 之外,還可以直接拿外部圖檔 (BitmapFileMaterial) 進行貼圖,以下這個範例我就是採用 BitmapFileMaterial 貼圖,並且每隔 3000 微秒就將圖片重新載入貼過!程式碼如下:
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.*;import flash.utils.*;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T2step4 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; private var movingRadius:int = 2000; private var movingHeight:int = 2000; private var photoIdx:int = 1; private var photoCount:int = 9; private var timer:Timer; public function T2step4() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = movingHeight; camera.z = -movingRadius; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 10, 10), "ground"); ground.rotationX = -90; var myCube1:DisplayObject3D = rootNode.addChild(new Cube(new BitmapFileMaterial(getFileName()), 100, 100, 100, 1, 1, 1), "myCube1"); myCube1.y = 50; timer = new Timer(3000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); } private function loop3D(event:Event):void{ /* du++; if(du==360)du=0; */ du = 360 * (this.mouseX / stage.stageWidth); var newX:Number = movingRadius * formatNum(Math.cos(du*TH), 3); var newY:Number = movingHeight; var newZ:Number = movingRadius * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.y = newY; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); } private function onMouseWheel(event:MouseEvent):void{ //event.delta = 3 | -3 movingRadius -= event.delta*10; if(movingRadius<=0)movingRadius=1; movingHeight -= event.delta*10; if(movingHeight<=200)movingHeight=200; } private function onTimer(event:TimerEvent):void{ var myCube1:DisplayObject3D = rootNode.getChildByName("myCube1"); myCube1.material = new BitmapFileMaterial(getFileName()); } private function getFileName():String{ return "http://ben.rb.chang.googlepages.com/photos"+(Math.floor(Math.random()*photoCount)+1)+".JPG"; }}}
測試畫面如下:
同樣的機制,我把先前教過的範例再加上這個週期換圖的效果,感覺又更絢麗了!程式碼如下,每個 Cube 都有自己的 Timer 控制,換圖時間不一定,以亂數決定的!
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.Event;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.* import flash.utils.Timer;import flash.events.TimerEvent;[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class Step8 extends Sprite{ private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var AMOUNT:int = 50; private var rotationSettingArray:Array = new Array(); private var timerArray:Array = new Array(); private var photoCount:int = 9; public function Step8() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.z = -3000; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); for(var i:int=0; i<AMOUNT; i++){ var myCube:DisplayObject3D = rootNode.addChild(new Cube(new BitmapFileMaterial(getFileName()), 100, 100, 100, 1, 1, 1), "myCube" + i); myCube.moveBackward(Math.random() * (3000-100/2+1)); if(Math.random()*2>1) myCube.moveLeft(Math.random()*500); else myCube.moveRight(Math.random()*500); if(Math.random()*2>1) myCube.moveUp(Math.random()*500); else myCube.moveDown(Math.random()*500); rotationSettingArray.push({rX:(Math.random()-Math.random())*2 , rY:(Math.random()-Math.random())*2 , rZ:(Math.random()-Math.random())*2}); var timer:Timer = new Timer((Math.round(Math.random()*5)+5)*1000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); timerArray.push(timer); } } private function loop3D(event:Event):void{ for(var i:int=0; i<AMOUNT; i++){ var myCube:DisplayObject3D = rootNode.getChildByName("myCube" + i); if(myCube!=null){ myCube.rotationX+=rotationSettingArray[i].rX; myCube.rotationY+=rotationSettingArray[i].rY; myCube.rotationZ+=rotationSettingArray[i].rZ; } } scene.renderCamera(camera); } private function onTimer(event:TimerEvent):void{ for(var i:int=0; i<timerArray.length; i++){ if(event.target==timerArray[i]){ var myCube:DisplayObject3D = rootNode.getChildByName("myCube"+i); var fileName:String = getFileName(); trace(fileName); myCube.material = new BitmapFileMaterial(fileName); } } } private function getFileName():String{ return "http://ben.rb.chang.googlepages.com/photos"+(Math.floor(Math.random()*photoCount)+1)+".JPG"; }}}
看效果!
於 6/13/2007 12:47:00 下午 0 意見
標籤: AS3, Flash, Papervision3D
Papervision3D 教學 part 2.2 -- 空照 與滑鼠互動
繼續上一篇的 Camera 操控,這次加上滑鼠,左右移動可以控制 camera 繞著圓心做旋轉,然後滾輪的部份,我會用來同時改變 carema 的高度以及繞圓心旋轉的半徑,程式碼如下:
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.*;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T2step3 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; [Embed(source="../assets/IMG_1054.JPG")] private var CubeTexture:Class; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; private var movingRadius:int = 2000; private var movingHeight:int = 2000; public function T2step3() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = movingHeight; camera.z = -movingRadius; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 10, 10), "ground"); ground.rotationX = -90; var cubeTexture:Bitmap = new CubeTexture() as Bitmap; var myCube1:DisplayObject3D = rootNode.addChild(new Cube(new BitmapMaterial(cubeTexture.bitmapData), 100, 100, 100, 1, 1, 1), "myCube1"); myCube1.y = 50; } private function loop3D(event:Event):void{ /* du++; if(du==360)du=0; */ du = 360 * (this.mouseX / stage.stageWidth); var newX:Number = movingRadius * formatNum(Math.cos(du*TH), 3); var newY:Number = movingHeight; var newZ:Number = movingRadius * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.y = newY; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); } private function onMouseWheel(event:MouseEvent):void{ //event.delta = 3 | -3 movingRadius -= event.delta*10; if(movingRadius<=0)movingRadius=1; movingHeight -= event.delta*10; if(movingHeight<=200)movingHeight=200; }}}
看效果!
於 6/13/2007 10:43:00 上午 6 意見
標籤: AS3, Flash, Papervision3D
Papervision3D 教學 part 2 -- 空照
我第二篇 PaperVision3D 的教學,是針對 Camera 的基本操控,這個範例我將 Camera 移到空中 高度 2000 的位置(y=2000),在 onEnterFrame() 時,會設定 carema 的座標,繞著中心點作旋轉,有點像是衛星移動的感覺。不過若是只對著一個 myCube1 做拍照的話,可能這樣的範例會看不出到底是 myCube1 在自己旋轉,還是 camera 在繞著他旋轉,所以我另外製作了一 Plane 物件名叫 ground 作為地板,預設這個地板是 X-Y 面向的單面,我需要將他順著 X 軸做翻轉,變成 X-Z 面向。
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.Event;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T2step1 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; [Embed(source="../assets/IMG_1054.JPG")] private var CubeTexture:Class; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; public function T2step1() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = 2000; camera.z = -2000; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 1, 1), "ground"); ground.rotationX = -90; var cubeTexture:Bitmap = new CubeTexture() as Bitmap; var myCube1:DisplayObject3D = rootNode.addChild(new Cube(new BitmapMaterial(cubeTexture.bitmapData), 100, 100, 100, 1, 1, 1), "myCube1"); myCube1.y = 50; } private function loop3D(event:Event):void{ du++; if(du==360)du=0; var newX:Number = 2000 * formatNum(Math.cos(du*TH), 3); var newZ:Number = 2000 * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); }}}
測試畫面如下:
你可能會發現,在 camera 繞著中心旋轉拍攝時,地面 ground 與 myCube1 某些部份會有些重疊衝突的問題,你需要時時想像,其實我們看到的 " 一個面 ",並不是真的由一個面構成,而是由 PV3D engine 將這個面拆成多個三角形拼貼而成的。對於這個問題,我試圖將 myCube1 的高度拉更高一點,從 myCube1.y = 51 一直拉到 100 以上,這個問題會得到改善,但還是會出現重疊三角形。另一種做法也可以改善這個問題,就是將地面的 segments 增加,由原本的 1 改成 10 以上,這樣一來,地面就是由更多的小三角碎片所組成的,而重疊時會造成的破碎感覺會小一點點,不過想必這樣的運算會比較多,所以,就別介意這種視覺問題囉!以下是改過的程式碼:
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.Event;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T2step2 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; [Embed(source="../assets/IMG_1054.JPG")] private var CubeTexture:Class; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; public function T2step2() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = 2000; camera.z = -2000; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 10, 10), "ground"); ground.rotationX = -90; var cubeTexture:Bitmap = new CubeTexture() as Bitmap; var myCube1:DisplayObject3D = rootNode.addChild(new Cube(new BitmapMaterial(cubeTexture.bitmapData), 100, 100, 100, 1, 1, 1), "myCube1"); myCube1.y = 50; } private function loop3D(event:Event):void{ du++; if(du==360)du=0; var newX:Number = 2000 * formatNum(Math.cos(du*TH), 3); var newZ:Number = 2000 * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); }}}
想嚐試製作子母視窗的感覺,建立了兩個 Camera3D,但是並無法透過 camera2 看到 scene,然後輸出在另外一個 MC 上,或許有方法可以做到,我還需要找找看。而以下我的作法是,用 camera2 先將 scene 輸出一次,並且立即讀取其 BiemapData 將之繪製到另外一個 MC 子視窗中,然後立刻改以 camera 將 scene 重新輸出一次。程式碼如下:
package {import flash.display.*;import flash.events.*;import flash.utils.*;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*;import org.papervision3d.materials.*;import flash.geom.Rectangle;import flash.geom.Matrix;[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T3step2 extends Sprite{private static var PI:Number = Math.PI;private static var TH:Number = PI / 180;private var container:Sprite;private var scene:Scene3D;private var camera:Camera3D;private var camera2:Camera3D;private var rootNode:DisplayObject3D;private var du:Number = 0;private var photoCount:int = 9;private var movingRadius:int = 1000;private var movingHeight:int = 500;private var timer:Timer;private var childWindowScreen:Sprite;private var bd:BitmapData;private var matrix:Matrix;private var bmp:Bitmap;public function T3step2(){ // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D);}private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = movingHeight; camera.z = -movingRadius; camera.zoom = 10; camera.focus = 100; camera2 = new Camera3D(); camera2.y = movingHeight; camera2.z = -movingRadius; camera2.zoom = 10; camera2.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 3, 3), "ground"); ground.rotationX = -90; var item:DisplayObject3D = new DisplayObject3D(); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:0, z:-50}), "p1"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:90, x:-50}), "p2"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:-90, x:50}), "p3"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:180, z:50}), "p4"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationX:90, y:-50}), "p5"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationX:-90, y:50}), "p6"); item.y = 150; rootNode.addChild(item, "item"); /* timer = new Timer(1000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); */ //子母視窗 var childWindow:Sprite = new Sprite(); addChild(childWindow); var childWindowBorder:Sprite = new Sprite(); childWindow.addChild(childWindowBorder); childWindowBorder.graphics.lineStyle(2, 0xffffff); childWindowBorder.graphics.drawRect(0, 0, 100, 100); childWindowScreen = new Sprite(); childWindow.addChild(childWindowScreen); childWindow.x = 300; childWindow.y = 300;}private function loop3D(event:Event):void{ //物體本身旋轉 var item:DisplayObject3D = rootNode.getChildByName("item"); if(item!=null){ item.rotationX++; item.rotationY++; item.rotationZ++; } //carema2先將畫面記錄下來 scene.renderCamera(camera2); bd = new BitmapData(400, 400, false, 0x0000ff); matrix = new Matrix(); matrix.translate(200, 200); matrix.scale(0.25, 0.25); bd.draw(scene.container, matrix); if(bmp!=null){ childWindowScreen.removeChild(bmp); } bmp = new Bitmap(bd); childWindowScreen.addChild(bmp); bd = null; //改用carema旋轉輸出 du++; if(du==360)du=0; var newX:Number = movingRadius * formatNum(Math.cos(du*TH), 3); var newZ:Number = movingRadius * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.z = newZ; scene.renderCamera(camera);}private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt);}private function onTimer(event:TimerEvent):void{ var item:DisplayObject3D = rootNode.getChildByName("item"); if(item!=null){ var pName:String = "p" + (Math.floor(Math.random()*6)+1); var p:DisplayObject3D = item.getChildByName(pName); if(p!=null){ p.material = new BitmapFileMaterial(getFileName()); } }}private function getFileName():String{ return "http://ben.rb.chang.googlepages.com/photos"+(Math.floor(Math.random()*photoCount)+1)+".JPG";}}}
測試時,不斷搞到瀏覽器當掉,後來我將 onTimer() 時的切換各面向的貼圖部分拿掉,改善了一點點!此外,若是觀察記憶體消耗的話,會發現他很快就衝到頂點,然後只好等 Gabarge Collection(GC) 自己找時間釋放掉,才會稍微順暢幾秒鐘......$%&@#
等到整個瀏覽器關閉後,就恢復正常了!
看效果!
於 6/13/2007 06:35:00 下午 0 意見
標籤: AS3, Flash, Papervision3D
Papervision3D 教學 part 3 -- 建模
先前的練習,我們都是直接以 PaperVision3D 所提供的基本模型 Cube 來建模,然後你會發現我們貼圖時,會將這個 Cube 的六個面都貼成同樣的材質,但是通常我們的模型上每個面有不同的貼圖,所以以下我做的範例,是先建立一個叫做 item 的 DisplayObject3D,然後在這個 DisplayObject3D 中加入六個 Plane 物件,並為這六個 Plane 進行貼圖,然後將這六個 Plane 組合成 Cube 的六個面向。範例中的其他部分之前提過,包含 camera 照圓心座標旋轉,以及透過 Timer 每隔一秒亂數決定這個我們自製 Cube 中其中一面向換貼圖。程式碼如下:
package {import flash.display.*;import flash.events.*;import flash.utils.*;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T3step1 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; private var photoCount:int = 9; private var movingRadius:int = 1000; private var movingHeight:int = 500; private var timer:Timer; public function T3step1() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = movingHeight; camera.z = -movingRadius; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 10, 10), "ground"); ground.rotationX = -90; var item:DisplayObject3D = new DisplayObject3D(); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:0, z:-50}), "p1"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:90, x:-50}), "p2"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:-90, x:50}), "p3"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationY:180, z:50}), "p4"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationX:90, y:-50}), "p5"); item.addChild(new Plane(new BitmapFileMaterial(getFileName()), 100, 100, 1, 1, {rotationX:-90, y:50}), "p6"); item.y = 150; rootNode.addChild(item, "item"); timer = new Timer(1000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); } private function loop3D(event:Event):void{ var item:DisplayObject3D = rootNode.getChildByName("item"); if(item!=null){ item.rotationX++; item.rotationY++; item.rotationZ++; } du++; if(du==360)du=0; var newX:Number = movingRadius * formatNum(Math.cos(du*TH), 3); var newZ:Number = movingRadius * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); } private function onTimer(event:TimerEvent):void{ var item:DisplayObject3D = rootNode.getChildByName("item"); if(item!=null){ var pName:String = "p" + (Math.floor(Math.random()*6)+1); var p:DisplayObject3D = item.getChildByName(pName); if(p!=null){ p.material = new BitmapFileMaterial(getFileName()); } } } private function getFileName():String{ return "http://ben.rb.chang.googlepages.com/photos"+(Math.floor(Math.random()*photoCount)+1)+".JPG"; }}}
看效果!
於 6/13/2007 04:22:00 下午 1 意見
標籤: AS3, Flash, Papervision3D
Papervision3D 教學 part 2.3 -- 用外部圖檔做貼圖材質
貼圖材質,除了可以貼純色 (ColorMaterial) 與 BitmapData (BitmapMaterial) 之外,還可以直接拿外部圖檔 (BitmapFileMaterial) 進行貼圖,以下這個範例我就是採用 BitmapFileMaterial 貼圖,並且每隔 3000 微秒就將圖片重新載入貼過!程式碼如下:
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.*;import flash.utils.*;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T2step4 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; private var movingRadius:int = 2000; private var movingHeight:int = 2000; private var photoIdx:int = 1; private var photoCount:int = 9; private var timer:Timer; public function T2step4() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = movingHeight; camera.z = -movingRadius; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 10, 10), "ground"); ground.rotationX = -90; var myCube1:DisplayObject3D = rootNode.addChild(new Cube(new BitmapFileMaterial(getFileName()), 100, 100, 100, 1, 1, 1), "myCube1"); myCube1.y = 50; timer = new Timer(3000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); } private function loop3D(event:Event):void{ /* du++; if(du==360)du=0; */ du = 360 * (this.mouseX / stage.stageWidth); var newX:Number = movingRadius * formatNum(Math.cos(du*TH), 3); var newY:Number = movingHeight; var newZ:Number = movingRadius * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.y = newY; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); } private function onMouseWheel(event:MouseEvent):void{ //event.delta = 3 | -3 movingRadius -= event.delta*10; if(movingRadius<=0)movingRadius=1; movingHeight -= event.delta*10; if(movingHeight<=200)movingHeight=200; } private function onTimer(event:TimerEvent):void{ var myCube1:DisplayObject3D = rootNode.getChildByName("myCube1"); myCube1.material = new BitmapFileMaterial(getFileName()); } private function getFileName():String{ return "http://ben.rb.chang.googlepages.com/photos"+(Math.floor(Math.random()*photoCount)+1)+".JPG"; }}}
測試畫面如下:
同樣的機制,我把先前教過的範例再加上這個週期換圖的效果,感覺又更絢麗了!程式碼如下,每個 Cube 都有自己的 Timer 控制,換圖時間不一定,以亂數決定的!
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.Event;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.* import flash.utils.Timer;import flash.events.TimerEvent;[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class Step8 extends Sprite{ private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var AMOUNT:int = 50; private var rotationSettingArray:Array = new Array(); private var timerArray:Array = new Array(); private var photoCount:int = 9; public function Step8() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.z = -3000; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); for(var i:int=0; i<AMOUNT; i++){ var myCube:DisplayObject3D = rootNode.addChild(new Cube(new BitmapFileMaterial(getFileName()), 100, 100, 100, 1, 1, 1), "myCube" + i); myCube.moveBackward(Math.random() * (3000-100/2+1)); if(Math.random()*2>1) myCube.moveLeft(Math.random()*500); else myCube.moveRight(Math.random()*500); if(Math.random()*2>1) myCube.moveUp(Math.random()*500); else myCube.moveDown(Math.random()*500); rotationSettingArray.push({rX:(Math.random()-Math.random())*2 , rY:(Math.random()-Math.random())*2 , rZ:(Math.random()-Math.random())*2}); var timer:Timer = new Timer((Math.round(Math.random()*5)+5)*1000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); timerArray.push(timer); } } private function loop3D(event:Event):void{ for(var i:int=0; i<AMOUNT; i++){ var myCube:DisplayObject3D = rootNode.getChildByName("myCube" + i); if(myCube!=null){ myCube.rotationX+=rotationSettingArray[i].rX; myCube.rotationY+=rotationSettingArray[i].rY; myCube.rotationZ+=rotationSettingArray[i].rZ; } } scene.renderCamera(camera); } private function onTimer(event:TimerEvent):void{ for(var i:int=0; i<timerArray.length; i++){ if(event.target==timerArray[i]){ var myCube:DisplayObject3D = rootNode.getChildByName("myCube"+i); var fileName:String = getFileName(); trace(fileName); myCube.material = new BitmapFileMaterial(fileName); } } } private function getFileName():String{ return "http://ben.rb.chang.googlepages.com/photos"+(Math.floor(Math.random()*photoCount)+1)+".JPG"; }}}
看效果!
於 6/13/2007 12:47:00 下午 0 意見
標籤: AS3, Flash, Papervision3D
Papervision3D 教學 part 2.2 -- 空照 與滑鼠互動
繼續上一篇的 Camera 操控,這次加上滑鼠,左右移動可以控制 camera 繞著圓心做旋轉,然後滾輪的部份,我會用來同時改變 carema 的高度以及繞圓心旋轉的半徑,程式碼如下:
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.*;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T2step3 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; [Embed(source="../assets/IMG_1054.JPG")] private var CubeTexture:Class; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; private var movingRadius:int = 2000; private var movingHeight:int = 2000; public function T2step3() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = movingHeight; camera.z = -movingRadius; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 10, 10), "ground"); ground.rotationX = -90; var cubeTexture:Bitmap = new CubeTexture() as Bitmap; var myCube1:DisplayObject3D = rootNode.addChild(new Cube(new BitmapMaterial(cubeTexture.bitmapData), 100, 100, 100, 1, 1, 1), "myCube1"); myCube1.y = 50; } private function loop3D(event:Event):void{ /* du++; if(du==360)du=0; */ du = 360 * (this.mouseX / stage.stageWidth); var newX:Number = movingRadius * formatNum(Math.cos(du*TH), 3); var newY:Number = movingHeight; var newZ:Number = movingRadius * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.y = newY; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); } private function onMouseWheel(event:MouseEvent):void{ //event.delta = 3 | -3 movingRadius -= event.delta*10; if(movingRadius<=0)movingRadius=1; movingHeight -= event.delta*10; if(movingHeight<=200)movingHeight=200; }}}
看效果!
於 6/13/2007 10:43:00 上午 6 意見
標籤: AS3, Flash, Papervision3D
Papervision3D 教學 part 2 -- 空照
我第二篇 PaperVision3D 的教學,是針對 Camera 的基本操控,這個範例我將 Camera 移到空中 高度 2000 的位置(y=2000),在 onEnterFrame() 時,會設定 carema 的座標,繞著中心點作旋轉,有點像是衛星移動的感覺。不過若是只對著一個 myCube1 做拍照的話,可能這樣的範例會看不出到底是 myCube1 在自己旋轉,還是 camera 在繞著他旋轉,所以我另外製作了一 Plane 物件名叫 ground 作為地板,預設這個地板是 X-Y 面向的單面,我需要將他順著 X 軸做翻轉,變成 X-Z 面向。
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.Event;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T2step1 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; [Embed(source="../assets/IMG_1054.JPG")] private var CubeTexture:Class; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; public function T2step1() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = 2000; camera.z = -2000; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 1, 1), "ground"); ground.rotationX = -90; var cubeTexture:Bitmap = new CubeTexture() as Bitmap; var myCube1:DisplayObject3D = rootNode.addChild(new Cube(new BitmapMaterial(cubeTexture.bitmapData), 100, 100, 100, 1, 1, 1), "myCube1"); myCube1.y = 50; } private function loop3D(event:Event):void{ du++; if(du==360)du=0; var newX:Number = 2000 * formatNum(Math.cos(du*TH), 3); var newZ:Number = 2000 * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); }}}
測試畫面如下:
你可能會發現,在 camera 繞著中心旋轉拍攝時,地面 ground 與 myCube1 某些部份會有些重疊衝突的問題,你需要時時想像,其實我們看到的 " 一個面 ",並不是真的由一個面構成,而是由 PV3D engine 將這個面拆成多個三角形拼貼而成的。對於這個問題,我試圖將 myCube1 的高度拉更高一點,從 myCube1.y = 51 一直拉到 100 以上,這個問題會得到改善,但還是會出現重疊三角形。另一種做法也可以改善這個問題,就是將地面的 segments 增加,由原本的 1 改成 10 以上,這樣一來,地面就是由更多的小三角碎片所組成的,而重疊時會造成的破碎感覺會小一點點,不過想必這樣的運算會比較多,所以,就別介意這種視覺問題囉!以下是改過的程式碼:
package {import flash.display.Sprite;import flash.display.Bitmap;import flash.events.Event;import org.papervision3d.cameras.Camera3D;import org.papervision3d.scenes.Scene3D;import org.papervision3d.objects.*import org.papervision3d.materials.*[SWF(backgroundColor="#000000", frameRate="60", width="400", height="400")]public class T2step2 extends Sprite{ private static var PI:Number = Math.PI; private static var TH:Number = PI / 180; [Embed(source="../assets/IMG_1054.JPG")] private var CubeTexture:Class; private var container:Sprite; private var scene:Scene3D; private var camera:Camera3D; private var rootNode:DisplayObject3D; private var du:Number = 0; public function T2step2() { // initialize the objects init3D(); // add a listener for the 3D loop addEventListener(Event.ENTER_FRAME, loop3D); } private function init3D():void{ container = new Sprite(); addChild(container); container.x = 200; container.y = 200; scene = new Scene3D(container); camera = new Camera3D(); camera.y = 2000; camera.z = -2000; camera.zoom = 10; camera.focus = 100; rootNode = scene.addChild(new DisplayObject3D("rootNode")); var ground:DisplayObject3D = rootNode.addChild(new Plane(new ColorMaterial(0xffcc00), 500, 500, 10, 10), "ground"); ground.rotationX = -90; var cubeTexture:Bitmap = new CubeTexture() as Bitmap; var myCube1:DisplayObject3D = rootNode.addChild(new Cube(new BitmapMaterial(cubeTexture.bitmapData), 100, 100, 100, 1, 1, 1), "myCube1"); myCube1.y = 50; } private function loop3D(event:Event):void{ du++; if(du==360)du=0; var newX:Number = 2000 * formatNum(Math.cos(du*TH), 3); var newZ:Number = 2000 * formatNum(Math.sin(du*TH), 3); camera.x = newX; camera.z = newZ; scene.renderCamera(camera); } private function formatNum(num:Number, cnt:Number):Number{ return Math.round(num * Math.pow(10, cnt)) / Math.pow(10, cnt); }}}
发表评论
-
骨骼蒙皮动画(Skinned Mesh)的原理解析
2015-12-05 19:11 969一)3D模型动画基本原理和分类 3D模型动画的基本原 ... -
Visual C++游戏编程基础(肖永亮)2_1
2009-04-03 19:42 2118// yxbcjc2_1.cpp : 定义应用程序的入口点。 ... -
Papervision Perspective Line material
2008-05-04 10:16 1701// Perspective Line material fo ... -
PV3D学习(1)--插入图片
2008-05-04 09:58 2106只需要将上一例中以下 ... -
详解DX9下3D游戏编程1
2008-04-19 21:28 3172Introduction to 3D Game Program ... -
Direct3D入门之框架的搭建
2008-04-18 09:33 2734学习一样东西,最好能够从最基础做起。学习D3D,笔者并不赞同直 ... -
Papervision3D の BitmapMaterial と MovieMaterial の使用
2008-04-03 16:01 2252package { import flash.disp ... -
BitmapFileMaterial的用法
2008-04-01 12:19 2974package com.hclown.earth3d.map ... -
魔術方塊
2008-03-28 09:47 1279看到以前已經有人在沒有 Flash 3D engine 的幫助 ... -
賽車程式
2008-03-28 09:46 1178package { import flash.display. ... -
PV3D2 .0 的经典 包含各种渲染和触发
2008-03-17 14:52 2414最近发现的宝贝,分享下!!值得收藏!! /* ... -
PV3D第一个测试文件
2008-03-15 11:34 2550第一个PV3D的测试文件: 这个实例是根据一个网站视频教程里 ...
相关推荐
标题中的“pv.rar_matlab pv_pv_pv array matlab_pv-simulink”暗示了这是一个与光伏(PV)系统相关的MATLAB和Simulink项目。...同时,它还可以作为教学资源,帮助理解光伏系统的工作原理和关键组件。
总的来说,这个压缩包提供的模型可以作为研究和教学的重要工具,帮助用户深入理解光伏并网系统的工作机制,以及MPPT在实际应用中的重要性。通过对比和分析不同模型,可以加深对光伏系统设计和优化的理解,为实际工程...
此外,该模型还可用于教学,帮助学生理解光伏原理,以及如何利用MATLAB进行工程问题的求解。 总之,"PV_model_PV曲线_光伏发电模型_MATLAB光伏"项目提供了一个实用的工具,它结合了理论与实践,有助于研究人员和...
总结来说,"pv_characteristic_Curve.mdl"是一个基于MATLAB Simulink的光伏电池I-V特性曲线模型,它通过仿真展示了光伏电池在不同环境条件下的电流-电压特性,是光伏系统设计、优化以及教学的重要工具。通过深入研究...
IEEE 9 节点系统是一种经典的电力系统模型,广泛应用于教学和研究中,特别是在电力系统分析与设计方面。该模型包括 9 个节点和多个发电机、负载、线路等元件,可以用来模拟实际电力系统的某些特征。通过这个模型,...
标题中的“pv.zip_matlab PV_pv_光伏电池”暗示了这是一个关于光伏电池的MATLAB仿真模型,其中包含的“pv.mdl”文件很可能是该模型的核心。这个模型是为研究、教学或工程应用设计的,允许用户模拟光伏电池的行为,...
流水灯是一种常见的电子实验和教学实例,通过控制LED灯的顺序点亮和熄灭,可以直观地展示微控制器的定时器和I/O端口操作。 在S5PV210流水灯工程中,首先需要了解的是微处理器的GPIO(General-Purpose Input/Output...
9. **教学材料或教程**:如果针对初学者,可能包含MPPT学习路径、教程或练习题,帮助快速掌握相关知识。 这个压缩包资源对于太阳能工程师、研究者或学生来说非常有价值,他们可以从中了解和实践MPPT技术,提升光伏...
综合以上信息,这个文件包很可能包含了一个用于研究或教学目的的Simulink模型,模型专注于分析和设计太阳能光伏系统与电网连接时的恒流源行为。在实际应用中,理解如何有效地控制光伏系统的电流输出,确保其与电网的...
通常,PV操作的实现会涉及到操作系统内核中的互斥锁和条件变量,但也可以在用户空间模拟,用于教学或简单项目。这两个源文件可能会定义一个结构体来表示信号量,并提供相应的P()和V()函数。 3. www.pudn.com.txt: ...
1. **教学与研究**:教育机构使用这种模型来教授太阳能技术原理,让学生理解光伏系统的运作机制。 2. **设计与规划**:工程师可以利用模型预测光伏系统的性能,为新的太阳能项目提供设计依据。 3. **性能评估**:...
标题中的"model_pv.rar_photovoltic_pv_pv model"提到了光伏(photovoltaic,简称PV)模型,这指的是利用太阳能转化为电能的...同时,这也为教学和研究提供了方便的工具,帮助深入理解光伏技术的基本原理和工程实现。
“pv__mppt”、“matlab_pv_solar”、“mppt_solar”和“pv_+_mppt”分别强调了光伏、MATLAB、太阳能和MPPT的关联,进一步表明了这个项目是关于使用MATLAB进行太阳能光伏系统最大功率点跟踪的研究或教学材料。...
3. **下载**: 在互联网上,可以找到各种光伏相关的软件、数据集和教学资源,用于绘制和分析PV图象。这些资源可能包括模拟工具、实验数据和教程,帮助学生和研究人员进行实际操作和学习。 4. **课件**: 教育机构通常...
总的来说,这个MATLAB Simulink光伏电池模型为理解和优化光伏系统的性能提供了一个实用的工具,同时也为教学和研究提供了便利。通过深入学习和调整此模型,用户可以更好地掌握光伏技术的核心概念,并可能应用于实际...
- **教育科研**: 作为教学实验平台或研究开发平台使用。 #### 六、注意事项 在使用SMDK S5PV210开发套件时,需要注意以下几点: - **安全规范**: 确保遵循所有安全操作指南,防止损坏设备或造成人身伤害。 - **...
它可以用来教学光伏电池的工作原理,进行新设计的仿真验证,或者对现有光伏系统进行性能优化。 总结来说,`pv_array.mdl`是一个使用Simulink构建的光伏电池板模型,通过它我们可以学习和研究光伏电池的电能转换过程...
通过对“PV-System1.psc”文件的分析,可以进行性能评估,优化设计,或进行教学演示,帮助理解和改进光伏系统的设计。同时,这个模型也可以作为研究不同气候条件、组件性能或控制系统策略的实验平台。
总的来说,这个MATLAB/Simulink光伏电池模型提供了一个强大的平台,用于教学、研究和工程设计,帮助人们理解和优化太阳能发电系统。通过深入研究和仿真,我们可以更好地理解光伏系统的行为,提高太阳能的利用效率,...
总的来说,本项目提供了使用Matlab/Simulink进行光伏电池建模和仿真的实例,这对于太阳能系统的设计、优化和教学具有很高的价值。通过深入研究和分析,我们可以获得关于光伏电池如何响应环境变化的深刻见解,并为...