• threejs学习笔记05---相机透视-正透视


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="js/Three.js"></script>
        <script src="js/Stats.js"></script>
        <script src="js/tween.min.js"></script>
    
        <style type="text/css">
            div#canvas-frame {
                border: none;
                cursor: pointer;
                 100%;
                height: 600px;
                background-color: #EEEEEE;
            }
    
        </style>
        <script>
            var renderer;
            function initThree(){
                width = document.getElementById('canvas-frame').clientWidth;
                height = document.getElementById('canvas-frame').clientHeight;
                renderer= new THREE.WebGLRenderer({
                    antialias:true
                });
                renderer.setSize(width,height);
                document.getElementById('canvas-frame').appendChild(renderer.domElement);
                renderer.setClearColor(0xFFFFFF,1.0);
            }
    
            var camera;
            function initCamera(){
                //透视投影相机THREE.PerspectiveCamera
                 camera = new THREE.PerspectiveCamera(45,width/height,1,10000);
                //正投影相机THREE.OrthographicCamera
                //camera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 10, 1000 );
                camera.position.x=0;
                camera.position.y = 0;
                camera.position.z = 600;
                camera.up.x = 0;
                camera.up.y = 1;
                camera.up.z = 0;
                camera.lookAt({
                    x : 0,
                    y : 0,
                    z : 0
                });
            }
    
            var scene;
            function initScene(){
                scene = new THREE.Scene();
            }
    
            var light;
            function initLight(){
                light=new THREE.AmbientLight(0xFF0000);
                light.position.set(100,100,200);
                scene.add(light);
    
                light=new THREE.PointLight(0xFF0000);
                light.position.set(100,100,200);
                scene.add(light);
            }
    
            var cube;
            function initObject(){
                var geometry=new THREE.CylinderGeometry(70,100,200);
                var material = new THREE.MeshLambertMaterial({color:0xFFFFFF});
                var mesh = new THREE.Mesh(geometry,material);
                mesh.position=new THREE.Vector3(0,0,0);
                scene.add(mesh);
            }
            function animation(){
                changeFov();
                renderer.render(scene, camera);
                requestAnimationFrame(animation);
            }
    
            function setCameraFov(fov){
                camera.fov = fov;
                //视角fov:这个最难理解,我的理解是,眼睛睁开的角度,即,视角的大小,如果设置为0,
                 //       相当你闭上眼睛了,所以什么也看不到,如果为180,那么可以认为你的视界很广阔,
                 //       但是在180度的时候,往往物体很小,因为他在你的整个可视区域中的比例变小了。
                camera.updateProjectionMatrix();
            }
    
            function changeFov(){
                var txtFov = document.getElementById("txtFov").value;
                var val = parseFloat(txtFov);
                setCameraFov(val);
            }
    
            function threeStart() {
                initThree();
                initCamera();
                initScene();
                initLight();
                initObject();
                animation();
    
            }
        </script>
    </head>
    <body onload="threeStart();">
    <div></div>
    <div id="canvas-frame"></div>
    <div>
        Fov:<input type="text" value="45" id="txtFov"/>(0到180的值)
        <p>
            视角fov:这个最难理解,我的理解是,眼睛睁开的角度,即,视角的大小,如果设置为0, <br>
                   相当你闭上眼睛了,所以什么也看不到,如果为180,那么可以认为你的视界很广阔,<br>
                   但是在180度的时候,往往物体很小,因为他在你的整个可视区域中的比例变小了。
        </p>
    </div>
    </body>
    </html>
    

      

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/Three.js"></script>
    <script src="js/Stats.js"></script>
    <script src="js/tween.min.js"></script>

    <style type="text/css">
    div#canvas-frame {
    border: none;
    cursor: pointer;
    width: 100%;
    height: 600px;
    background-color: #EEEEEE;
    }

    </style>
    <script>
    var renderer;
    function initThree(){
    width = document.getElementById('canvas-frame').clientWidth;
    height = document.getElementById('canvas-frame').clientHeight;
    renderer= new THREE.WebGLRenderer({
    antialias:true
    });
    renderer.setSize(width,height);
    document.getElementById('canvas-frame').appendChild(renderer.domElement);
    renderer.setClearColor(0xFFFFFF,1.0);
    }

    var camera;
    function initCamera(){
    //透视投影相机THREE.PerspectiveCamera
    camera = new THREE.PerspectiveCamera(45,width/height,1,10000);
    //正投影相机THREE.OrthographicCamera
    //camera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 10, 1000 );
    camera.position.x=0;
    camera.position.y = 0;
    camera.position.z = 600;
    camera.up.x = 0;
    camera.up.y = 1;
    camera.up.z = 0;
    camera.lookAt({
    x : 0,
    y : 0,
    z : 0
    });
    }

    var scene;
    function initScene(){
    scene = new THREE.Scene();
    }

    var light;
    function initLight(){
    light=new THREE.AmbientLight(0xFF0000);
    light.position.set(100,100,200);
    scene.add(light);

    light=new THREE.PointLight(0xFF0000);
    light.position.set(100,100,200);
    scene.add(light);
    }

    var cube;
    function initObject(){
    var geometry=new THREE.CylinderGeometry(70,100,200);
    var material = new THREE.MeshLambertMaterial({color:0xFFFFFF});
    var mesh = new THREE.Mesh(geometry,material);
    mesh.position=new THREE.Vector3(0,0,0);
    scene.add(mesh);
    }
    function animation(){
    changeFov();
    renderer.render(scene, camera);
    requestAnimationFrame(animation);
    }

    function setCameraFov(fov){
    camera.fov = fov;
    //视角fov:这个最难理解,我的理解是,眼睛睁开的角度,,视角的大小,如果设置为0,
    // 相当你闭上眼睛了,所以什么也看不到,如果为180,那么可以认为你的视界很广阔,
    // 但是在180度的时候,往往物体很小,因为他在你的整个可视区域中的比例变小了。
    camera.updateProjectionMatrix();
    }

    function changeFov(){
    var txtFov = document.getElementById("txtFov").value;
    var val = parseFloat(txtFov);
    setCameraFov(val);
    }

    function threeStart() {
    initThree();
    initCamera();
    initScene();
    initLight();
    initObject();
    animation();

    }
    </script>
    </head>
    <body onload="threeStart();">
    <div></div>
    <div id="canvas-frame"></div>
    <div>
    Fov:<input type="text" value="45" id="txtFov"/>(0180的值)
    <p>
    视角fov:这个最难理解,我的理解是,眼睛睁开的角度,,视角的大小,如果设置为0, <br>
    相当你闭上眼睛了,所以什么也看不到,如果为180,那么可以认为你的视界很广阔,<br>
    但是在180度的时候,往往物体很小,因为他在你的整个可视区域中的比例变小了。
    </p>
    </div>
    </body>
    </html>
    学习是对自己负责,自己是职业发展的负责人!
  • 相关阅读:
    C# List转换成DataTable
    表达式计算
    通过GitHub高级条件组合精确搜索开源项目学习
    今天开通博客啦 随便记录一下东西
    VSCode开发Vue-代码格式化最完美设置
    C# DataTable 行转列 列转行 同时转换
    [转载]DevExpress GridControl 使用方法技巧 总结 收录整理
    控件已成功添加到工具箱中,但未在活动设计器中启用
    js-beautify 不换行
    tomcat端口修改后在Eclipse中启动无效问题解决
  • 原文地址:https://www.cnblogs.com/Webyangbowen/p/8058890.html
Copyright © 2020-2023  润新知