zoukankan      html  css  js  c++  java
  • three.js之创建一条直线

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset=utf-8>
        <title>My first three.js app</title>
        <style>
            body {
                margin: 0;
            }
    
            canvas {
                 100%;
                height: 100%
            }
        </style>
    </head>
    <body>
    
    <script src="../static/three.js-master/build/three.js"></script>
    <script>
    
    
    var renderer = new THREE.WebGLRenderer();  // 渲染器
    renderer.setSize( window.innerWidth, window.innerHeight );  // 设置渲染器的宽度和高度
    document.body.appendChild( renderer.domElement );
    
    var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 500 );  // 透视摄像机
    camera.position.set( 0, 0, 100 );  // 设置坐标
    camera.lookAt( 0, 0, 0 );
    
    var scene = new THREE.Scene();  // 场景
    // 上面是摄像机 下面是材料
    //create a blue LineBasicMaterial
    var material = new THREE.LineBasicMaterial( { color: 0x0000ff } );  // 定义线条的材料,接收字典类型的参数
    
    var geometry = new THREE.Geometry();  // 声明一个几何体geometry
    geometry.vertices.push(new THREE.Vector3( -10, 0, 0) );
    geometry.vertices.push(new THREE.Vector3( 0, 10, 0) );
    
    
    var line = new THREE.Line( geometry, material );  // 根据材料创建线条
    
    scene.add( line );  // 将线条添加到场景内
    renderer.render( scene, camera );  // 渲染器将场景和摄像机及线条渲染出来
    
    </script>
    </body>
    </html>

    附带three.js代码,点击下载

  • 相关阅读:
    cocos2d-x学习记录5——CCTransition场景过渡
    cocos2d-x学习记录4——图形绘制
    cocos2d-x学习记录3——CCTouch触摸响应
    cocos2d-x学习记录2——CCAction动作
    cocos2d-x学习记录1——图片显示
    cocos2d-x环境搭建
    自定义CCNode
    cocos2d-x调度器原理
    cocos2d-x动作原理
    cocos2d-x触摸分发器原理
  • 原文地址:https://www.cnblogs.com/aaronthon/p/10978507.html
Copyright © 2011-2022 走看看