欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

three.js實現3D視野縮放效果

 更新時間:2017年11月16日 10:25:51   作者:妙趣又橫生  
這篇文章主要為大家詳細介紹了three.js實現3D視野縮放效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

首先,不再廢話了,什么是three.js,是干什么的,知道的就是知道,不知道的就百度吧。

小編為大家推薦一篇:Three.js快速入門教程

昨兒發(fā)現three.js中的3D視野的縮小和放大效果可以用照相機的遠近焦來實現。


縮小后:

這里采用的是透視照相機:

//照相機配置
  var fov = 40;//拍攝距離
  var near = 1;//最小范圍
  var far = 1000;//最大范圍
  var camera = new THREE.PerspectiveCamera(fov, window.innerWidth / window.innerHeight, near, far);


在這里可以改變fov的值,并更新這個照相機就可以了。

camera.fov = fov;//fov是變量哦 
camera.updateProjectionMatrix();
renderer.render(scene, camera);


另外:咱們都是習慣用鼠標上下滑輪實現放大縮小效果,so看代碼

canvas.addEventListener('mousewheel', mousewheel, false);
    //鼠標滑輪
    function mousewheel(e) {
      e.preventDefault();
      //e.stopPropagation();
      if (e.wheelDelta) { //判斷瀏覽器IE,谷歌滑輪事件
        if (e.wheelDelta > 0) { //當滑輪向上滾動時
          fov -= (near < fov ? 1 : 0);
        }
        if (e.wheelDelta < 0) { //當滑輪向下滾動時
          fov += (fov < far ? 1 : 0);
        }
      } else if (e.detail) { //Firefox滑輪事件
        if (e.detail > 0) { //當滑輪向上滾動時
          fov -= 1;
        }
        if (e.detail < 0) { //當滑輪向下滾動時
          fov += 1;
        }
      }
      camera.fov = fov;
      camera.updateProjectionMatrix();
      renderer.render(scene, camera);
      //updateinfo();
    }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論