美文网首页
画一个坐标系

画一个坐标系

作者: waka | 来源:发表于2017-09-28 11:09 被阅读57次

参考文章: Threejs基础教程 第2章 还记得点、线、面吗(二)
THREE笛卡尔右手坐标系详解

学习 Three.js 的时候跟着老师做,但是发现视角有些难以理解,于是自己画了一个,个人认为比较容易理解

黄色为Y轴,紫色为X轴,红色为Z轴


github地址:https://github.com/BadWaka/BadWaka.github.io/blob/master/views/three/three-demo-2-2.html

代码如下:(依赖 three.js)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>2-2</title>
    <style>
        html, body, canvas {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
        }

        div#canvas-frame {
            border: none;
            cursor: pointer;
            width: 100%;
            height: 600px;
            background-color: #EEEEEE;
        }
    </style>
</head>
<body onload="threeStart()">
<div id="canvas-frame"></div>
<script src="../../library/three/three.js"></script>
<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() {
        camera = new THREE.PerspectiveCamera(45, width / height, 1, 10000);
        camera.position.x = 1000;
        camera.position.y = 1000;
        camera.position.z = 1000;
        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.DirectionalLight(0xFF0000, 1.0, 0);
        light.position.set(100, 100, 200);
        scene.add(light);
    }

    var cube;

    function initObject() {
        var geometry = new THREE.Geometry();
        geometry.vertices.push(new THREE.Vector3(-500, 0, 0));
        geometry.vertices.push(new THREE.Vector3(500, 0, 0));

        for (var i = 0; i <= 20; i++) {
            var line = new THREE.Line(geometry, new THREE.LineBasicMaterial({
                color: 0x000000,
                opacity: 0.2
            }));
            line.position.z = (i * 50) - 500;
            scene.add(line);

            var line = new THREE.Line(geometry, new THREE.LineBasicMaterial({
                color: 0x000000,
                opacity: 0.2
            }));
            line.position.x = (i * 50) - 500;
            line.rotation.y = 90 * Math.PI / 180;
            scene.add(line);
        }

        // Y坐标
        var lineY = new THREE.Line(geometry, new THREE.LineBasicMaterial({
            color: 0xFFD700,    // 黄色
            opacity: 0.2
        }));
        lineY.position.y = 500;
        lineY.rotation.z = 90 * Math.PI / 180;
        scene.add(lineY);

        // X坐标
        var lineX = new THREE.Line(geometry, new THREE.LineBasicMaterial({
            color: 0xFF00FF,    // 紫色
            opacity: 0.2
        }));
        lineX.position.x = 500;
        scene.add(lineX);

        // Z坐标
        var lineZ = new THREE.Line(geometry, new THREE.LineBasicMaterial({
            color: 0xEE3B3B,    // 红色
            opacity: 0.2
        }));
        lineZ.position.z = 500;
        lineZ.rotation.y = 90 * Math.PI / 180;
        scene.add(lineZ);

    }

    // 开始画3D
    function threeStart() {
        initThree();
        initCamera();
        initScene();
        initLight();
        initObject();
        renderer.clear();
        renderer.render(scene, camera);
    }

</script>
</body>
</html>

相关文章

  • 画一个坐标系

    参考文章: Threejs基础教程 第2章 还记得点、线、面吗(二)THREE笛卡尔右手坐标系详解 学习 Thre...

  • 手把手教你如何用UG编程软件快速建立莫比乌斯环模型

    1、新建文件。 2、调用矩形命令,在ZX平面随意画一个矩形。 3、调用几何约束命令,将矩形左边线中点对齐坐标系原点...

  • CoreGraphics绘制图表教程(二)

    本篇介绍如何使用CoreGraphics绘制一个折线图 有了上一篇绘制坐标系的基础,画一个折线图就变得非常简单了。...

  • Android自定义View(11)- 画一个FM调频收音机刻

    概述 这次我们来画一个调频收音机刻度表。这个控件看似并不复杂,但却涉及到蛮多的细节处理,需要对Android坐标系...

  • 3ds-max缩放操作

    先随便画一个长方体测试吧。 选择主工具栏中的“选择并均匀缩放”工具。 此时,在长方体上会出现一个xyz坐标系,根据...

  • 渲染管线中的顶点变换

    概述 在图形学渲染管线中,一个顶点坐标,大概要经历局部坐标系、世界坐标系、相机坐标系、裁剪坐标系,最后到窗口坐标系...

  • 灵魂

    分布在地球这个坐标系上的人 散散落落 匆匆忙忙 每个肉体承载着独特的灵魂 我总想为它做些什么 天亮之前为它画一个红...

  • LearnOpenGL 坐标系统(1)

    五个坐标系统 局部空间(物体空间) 世界空间 观察空间 裁剪空间 屏幕空间 五个坐标系统的概念 : 坐标系统[ht...

  • 单目相机标定___一、原理

    原理:成像模型的坐标系为:世界坐标系 --> 相机坐标系 --> 图像坐标系 --> 像素坐标系 先说从相机坐标系...

  • 多坐标系

    1.3D图形学中常用的坐标系: * 世界坐标系世界坐标系是一个特殊的坐标系,它建立了描述其他坐标系所需要的参考框架...

网友评论

      本文标题:画一个坐标系

      本文链接:https://www.haomeiwen.com/subject/uaemextx.html