悟心

          成功不是將來才有的,而是從決定去做的那一刻起,持續(xù)累積而成。 上人生的旅途罷。前途很遠(yuǎn),也很暗。然而不要怕。不怕的人的面前才有路。

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            93 隨筆 :: 1 文章 :: 103 評論 :: 0 Trackbacks
            1 ------------ 變量申明 --------------------------
            2 property mySphere  --代理球
            3 property mySprite  --當(dāng)前精靈
            4 property pCam   --攝像機(jī)1
            5 property pCam2  --攝像機(jī)2
            6 property scene  --場景
            7 property pSphere --球體
            8 property ground  --地面
            9 
           10 property wall  --墻壁
           11 property wall01  --墻壁1
           12 property wall02  --墻壁2
           13 property wall03  --墻壁3
           14 property wall04  --墻壁4
           15 
           16 property stair  --樓梯
           17 
           18 -------------方法、事件----------------------
           19 on beginSprite me
           20   
           21   scene = member("3d")  --設(shè)置 場景=3d 成員 
           22   scene.resetWorld()   --重置
           23   mySprite = sprite(me.spriteNum)  --設(shè)置精靈
           24   put mySprite
           25   pSphere = scene.newModelResource( "pSphere",#sphere )  --創(chuàng)建 圓球
           26   pSphere.radius = 50  --設(shè)置 圓球 半徑
           27   
           28   mySphere = scene.newModel( "pSphere",pSphere )  --將 圓球 加到 3D場景 中
           29   mySphere.translate(0,-1500,50)  --設(shè)置 球 的位置
           30   --mySp.rotate(10,0,0)
           31   
           32   --創(chuàng)建 地面,并且設(shè)置 屬性
           33   ground = scene.newModelResource("ground",#plane)
           34   ground.length = 5000
           35   ground.width = 5000
           36   ground.widthVertices = 10
           37   ground.lengthVertices = 10
           38   
           39   scene.newModel("ground",ground)  --加到 3D場景中
           40   --設(shè)置 地面 的貼圖 的比例
           41   scene.shader("defaultShader").textureTransform.scale(0.1,0.1,1)
           42   
           43   --創(chuàng)建 四面墻體
           44   wall = scene.newModelResource( "wall",#plane,#front )
           45   wall.length = 200
           46   wall.width = 5000
           47   
           48   --添加到 3D場景 中
           49   wall01 = scene.newModel("wall01",wall)
           50   wall02 = scene.newModel("wall02",wall)
           51   wall03 = scene.newModel("wall03",wall)
           52   wall04 = scene.newModel("wall04",wall)
           53   
           54   --設(shè)置4面墻的位置
           55   wall01.translate(0,-2500,100,#world)
           56   wall01.rotate(90,0,0)
           57   
           58   wall02.translate(0,2500,100,#world)
           59   wall02.rotate(-90,0,0)
           60   
           61   wall03.translate(2500,0,100,#world)
           62   wall03.rotate(90,0,90)
           63   
           64   wall04.translate(-2500,0,100,#world)
           65   wall04.rotate(90,0,-90)
           66   
           67   --創(chuàng)建樓梯
           68   stair = scene.newModelResource("stair",#box)
           69   stair.height = 60
           70   stair.width = 300
           71   stair.length = 30
           72   
           73   scene.newModel("stair",stair)
           74   scene.model("stair").translate(0,0,0)
           75   
           76   --循環(huán),輸出每一節(jié)樓梯
           77   repeat with i=1 to 20
           78     stairI=scene.newModel( "b0"&string(i),stair )
           79     stairI.translate(0,60*i,30*i)
           80   end repeat
           81   
           82   --創(chuàng)建攝像機(jī)1
           83   pCam = scene.newCamera("cam01")
           84   pCam.transform.position = mySphere.transform.position
           85   pCam.rotate(90,0,0)
           86   pCam.translate(0,50,0)
           87   
           88   --攝像機(jī)2
           89   pCam2= scene.newCamera("cam02")
           90   pCam2.transform.position = mySphere.transform.position
           91   pCam2.translate(0,-2000,2000)
           92   pCam2.rotate(45,0,0)
           93   
           94   mySprite.camera=pCam  --設(shè)置當(dāng)前默認(rèn)相機(jī)
           95   --mySprite.camera=pCam2
           96   
           97   --將相機(jī)綁定到 球體 中
           98   mySphere.addChild(pCam)
           99   mySphere.addChild(pCam2)
          100   
          101   --創(chuàng)建燈光
          102   lightx = scene.newLight("lightx",#point)
          103   
          104   lightx.translate(2000,1500,1000)
          105   mySphere.translate(0,0,50)   --設(shè)置球的位置
          106   
          107 end beginSprite
          108 -------------------------------------------------------------------
          109 on exitFrame me
          110   --簡單重力
          111   mySphere.translate(0,0,-50)
          112   
          113   myKeyPressed  --調(diào)用鍵盤按下事件
          114   
          115   ---模擬碰撞測試程序------
          116   -- modelsUnderRay 函數(shù)將返回關(guān)于射線經(jīng)過模型的一些數(shù)據(jù)。
          117   --碰撞處理程序?qū)@些數(shù)據(jù)進(jìn)行分析。
          118   
          119   --以 負(fù)z 為中心軸
          120   tList = scene.modelsUnderRay( mySphere.worldPosition,-mySphere.transform.zAxis,#detailed )
          121   if tList.count then
          122     me.checkGroundCollsision(tList[1])  --檢查對 地面 碰撞
          123   end if
          124   
          125   --以 正z 為中心軸
          126   tList = scene.modelsUnderRay( mySphere.worldPosition,mySphere.transform.zAxis,#detailed )
          127   if (tList.countthen
          128     me.checkForCollision(tList[1])
          129   end if   
          130   
          131   --以 正y 為中心軸 
          132   tList = scene.modelsUnderRay( mySphere.worldPosition,mySphere.transform.yAxis,#detailed )
          133   if tList.count then
          134     me.checkForCollision(tList[1])
          135   end if
          136   
          137   --以 負(fù)y 為中心軸
          138   tList = scene.modelsUnderRay( mySphere.worldPosition,-mySphere.transform.yAxis,#detailed )
          139   if tList.count then
          140     me.checkForCollision(tList[1])
          141   end if
          142   
          143   --以 正x 為中心軸
          144   tList = scene.modelsUnderRay( mySphere.worldPosition,mySphere.transform.xAxis,#detailed )  
          145   if (tList.countthen
          146     me.checkForCollision(tList[1])
          147   end if  
          148   
          149   --以 負(fù)x為 中心軸
          150   tList = scene.modelsUnderRay( mySphere.worldPosition,-mySphere.transform.xAxis,#detailed )  
          151   if (tList.countthen
          152     me.checkForCollision(tList[1])
          153   end if 
          154   
          155   go the frame
          156 end exitFrame
          157 
          158 -- 發(fā)生 與 墻壁、樓梯 碰撞  處理方法 
          159 on checkForCollision (me,thisData)
          160   
          161   thisDistance = thisData.distance  --距離、間距
          162   
          163   mySphereRadius = mySphere.resource.radius+5  --圓球半徑+5
          164   
          165   --如果當(dāng)前 距離 小于 球體的半徑+25
          166   if thisDistance < mySphereRadius then
          167     
          168     tVector = thisData.isectNormal * (mySphereRadius-thisDistance)
          169     
          170     mySphere.translate(tVector,#world)  --移動(dòng) 圓球
          171   end if
          172 end checkForCllision
          173 
          174 --與 地面 碰撞處理,防止“下沉”
          175 on checkGroundCollsision(me,thisData)
          176   
          177   thisDistance = thisData.distance
          178   mySphereRadius = mySphere.resource.radius+70
          179   
          180   if thisDistance < mySphereRadius then
          181     tVector = thisData.isectNormal * ( mySphereRadius-thisDistance )
          182     mySphere.translate( tVector,#world )
          183   end if
          184   
          185 end checkGroundCollsision
          186 
          187 --------鍵盤按下事件--------------
          188 on myKeyPressed 
          189   if keyPressed(126or keyPressed("w") then  --top 前進(jìn)
          190     mySphere.translate(0,20,0)  --移動(dòng)
          191   end if
          192   
          193   if keyPressed(125or keyPressed("s") then  --botton 后退
          194     mySphere.translate(0,-20,0)  --移動(dòng)
          195   end if
          196   
          197   if keyPressed("a") then  --
          198     mySphere.translate(-10,0,0)  --移動(dòng)
          199   end if
          200   
          201   if keyPressed("d") then  --
          202     mySphere.translate(10,0,0)  --移動(dòng)
          203   end if
          204   
          205   if keyPressed(123then  --left
          206     mySphere.rotate(0,0,2)  --旋轉(zhuǎn)
          207   end if
          208   
          209   if keyPressed(124then
          210     mySphere.rotate(0,0,-2)  --旋轉(zhuǎn)
          211   end if
          212   
          213   if keyPressed("1") then
          214     mySprite.camera = pCam  --如果是按1,切換到1號視角
          215   end if
          216   
          217   if keyPressed("2") then
          218     mySprite.camera = pCam2  --切換2號視角
          219   end if
          220 end myKeyPressed
          221 
          posted on 2009-11-27 12:30 艾波 閱讀(359) 評論(0)  編輯  收藏 所屬分類: Other
          主站蜘蛛池模板: 尤溪县| 青田县| 江达县| 中宁县| 丰都县| 浠水县| 酒泉市| 河间市| 皋兰县| 乡宁县| 肇东市| 金寨县| 宁国市| 宿迁市| 通化市| 专栏| 三江| 海南省| 垦利县| 万全县| 玛曲县| 灵宝市| 阜宁县| 大兴区| 邻水| 大城县| 德庆县| 镇宁| 图们市| 柏乡县| 咸丰县| 固原市| 开化县| 清丰县| 什邡市| 新津县| 元谋县| 泽库县| 阿图什市| 洛宁县| 新野县|