WEB开发网      濠电娀娼ч崐濠氬疾椤愶附鍋熸い鏍ㄧ〒闂勫嫰鏌﹀Ο渚Ц闁诲氦顕ч湁婵犲﹤楠告禍鍓х磼鏉堛劌绗氶柟宄版嚇閹晠宕归銈嗘濠电偞鍨堕幐鎾磻閹捐秮褰掓偐閻戞﹩妫勯梺鎼炲妼鐎涒晝绮嬪澶樻晝闁挎繂鏌婇敃鍌涚厵閻庢稒锚閻忥絾绻濇繝鍐ㄧ伌闁诡垰鍟村畷鐔碱敂閸♀晙绱樺┑鐐差嚟婵儳螞閸曨剚鍙忛柍鍝勬噹缁€澶嬬箾閹存繄锛嶆鐐灲閹綊宕惰濡插鏌涢妸銉ヮ劉缂佸倸绉归弫鎾绘晸閿燂拷 ---闂備焦瀵уú鈺呭箯閿燂拷
开发学院图形图像Flash Flash与3D编程探秘(五)- 摄像机旋转和移动 阅读

Flash与3D编程探秘(五)- 摄像机旋转和移动

 2008-11-12 11:51:23 来源:WEB开发网 闂備線娼уΛ鎾箯閿燂拷闂備礁鎲¢崹鐢垫崲閹扮増鍎嶆い鎺戝€甸崑鎾斥槈濞嗗秳娌紓鍌氱▌閹凤拷濠电姭鎷冮崨顓濈捕闂侀潧娲ゅú銊╁焵椤掍胶鈯曢柕鍥╁仧缁辩偤鏁撻敓锟�闂備線娼уΛ鎾箯閿燂拷  闂備胶枪缁绘鈻嶉弴銏犳瀬闁绘劕鐏氱€氼剟姊洪崹顕呭剰闁逞屽墮缁夊綊寮婚妸褉鍋撻棃娑欏暈闁伙綀浜埀顒傛暬閸嬪﹪宕伴弽褏鏆﹂柨鐕傛嫹
核心提示: //nowcreatelotsofballsaroundyourcamerafor(vari=0;i<MAX_OBJ;i++){varball=newSphere();ball.angle=Math.random()*(0-PI*2)+PI*2;//thisistherotatean

//nowcreatelotsofballsaroundyourcamera
for(vari=0;i<MAX_OBJ;i++)
{
  varball=newSphere();
  ball.angle=Math.random()*(0-PI*2)+PI*2;      //thisistherotateangleonthexzplane
  ball.dist_center=140+(MAX_OBJ-i)*DISTANCE;   //thedistancetoyourcamera
  ball.x_3d=Math.cos(ball.angle)*ball.dist_center;  //thenweusetrigtogetx
  ball.z_3d=Math.sin(ball.angle)*ball.dist_center;   //andz
  ball.y_3d=Math.random()*(-240-240)+240;     //nowputtheballatrandomy
  scene.addChild(ball);                      //addtheballtothecollection
}

4. 对于每一个物体,我们在摄像机转动角度时刷新它的大小和位置。于是我们下一步写一个函数来达到目的,首先我们要确定小P相对于我们的摄像机的旋转角度。然 后我们根据这个角度和他们之间的垂直距离,算出它到摄像机的x,z和y的距离。最后,还是运用我们之前学过的算法,缩放和移动物体。

//updateballsizeandposition
functionupdate(obj)
{
  //gettheanglerelativetoyourcamerapanningangle
  varangle=obj.angle-camera.panning;
  varx_pos=Math.cos(angle)*obj.dist_center-camera.x;    //usetrigcalculatethex
  varz_pos=Math.sin(angle)*obj.dist_center-camera.z;    //andz
  vary_pos=obj.y_3d-camera.y;            //calculatetherelativey
  
  if(z_pos>0)                         //iftheballisinfrontofthecamera
  {
    if(!obj.visible)                
      obj.visible=true;                  //maketheballvisibleanyway
      
    varscale=focal_length/(focal_length+z_pos);   //calthescaleoftheball
    obj.x=x_pos*scale;               //calcualtethexpositioninacameraview
    obj.y=y_pos*scale;               //andyposition
    obj.scaleX=obj.scaleY=scale;       //scaletheballtoaproperstate
  }
  else
  {
    obj.visible=false;
  }
}

上一页  1 2 3 4 5 6 7  下一页

Tags:Flash 编程 探秘

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接