three.js从入门到精通系列教程006 - three.js创建旋转立方体BoxGeometry
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>three.js从入门到精通系列教程006 - three.js创建旋转立方体BoxGeometry</title>
<script src="js/three.js"></script>
<script src="js/jquery.js"></script>
</head>
<body>
<center id="myContainer"></center>
<script>
//创建渲染器
var myWidth = 480, myHeight = 320;
var myRenderer = new THREE.WebGLRenderer({ antialias: true });
//设置渲染尺寸大小
myRenderer.setSize(myWidth, myHeight);
myRenderer.setClearColor("white", 1);
$("#myContainer").append(myRenderer.domElement);
var myScene = new THREE.Scene();
var k = myWidth / myHeight, s = 120;
//创建透视相机OrthographicCamera
var myCamera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000);
myCamera.position.set(400, 300, 200);
//设置相机视角
myCamera.lookAt(myScene.position);
//创建立方体
var myGeometry = new THREE.BoxGeometry(100, 100, 100);
var myMaterial = new THREE.MeshNormalMaterial();
var myMesh = new THREE.Mesh(myGeometry, myMaterial);
//立方体放入场景
myScene.add(myMesh);
//使用定时器实现间隔渲染立方体,模拟旋转
setInterval(function () {
myMesh.rotateX(0.02); //按照指定的弧度围绕x轴旋转网格(立方体)
myRenderer.render(myScene, myCamera);
}, 50);
</script>
</body>
</html>
原文地址:https://blog.csdn.net/smartsmile2012/article/details/135710505
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!