美文网首页
js也能写3D游戏?

js也能写3D游戏?

作者: Peppa_6dad | 来源:发表于2019-06-01 14:18 被阅读0次

看完这本书《3D Game Programing for Kids》之后,发现3D游戏的学习,也可以使用javascript来写的。

先要上这个网站https://threejs.org,然后下载它的three.js源码放到一个目录,比如js。

然后放入这段代码:

<!DOCTYPE html>

<html>

<head>

<meta charset=utf-8>

<title>My first three.js app</title>

<style>

body { margin: 0; }

canvas { width: 100%; height: 100% }

</style>

</head>

<body>

<script src="js/three.js"></script>

<script>

var scene = new THREE.Scene();

var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );

var renderer = new THREE.WebGLRenderer();

renderer.setSize( window.innerWidth, window.innerHeight );

document.body.appendChild( renderer.domElement );

var geometry = new THREE.BoxGeometry( 1, 1, 1 );

var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );

var cube = new THREE.Mesh( geometry, material );

scene.add( cube );

camera.position.z = 5;

var animate = function () {

requestAnimationFrame( animate );

cube.rotation.x += 0.1;

cube.rotation.y += 0.1;

renderer.render(scene, camera);

};

animate();

</script>

</body>

</html>

保存之后,再使用CHROME浏览器打开,就可以看到下面的画面:

Python游戏开发入门

http://edu.csdn.net/course/detail/5690

你也能动手修改C编译器

http://edu.csdn.net/course/detail/5582

纸牌游戏开发

http://edu.csdn.net/course/detail/5538 

五子棋游戏开发

http://edu.csdn.net/course/detail/5487

RPG游戏从入门到精通

http://edu.csdn.net/course/detail/5246

WiX安装工具的使用

http://edu.csdn.net/course/detail/5207

俄罗斯方块游戏开发

http://edu.csdn.net/course/detail/5110

boost库入门基础

http://edu.csdn.net/course/detail/5029

Arduino入门基础

http://edu.csdn.net/course/detail/4931

Unity5.x游戏基础入门

http://edu.csdn.net/course/detail/4810

TensorFlow API攻略

http://edu.csdn.net/course/detail/4495

TensorFlow入门基本教程

http://edu.csdn.net/course/detail/4369

C++标准模板库从入门到精通 

http://edu.csdn.net/course/detail/3324

跟老菜鸟学C++

http://edu.csdn.net/course/detail/2901

跟老菜鸟学python

http://edu.csdn.net/course/detail/2592

在VC2015里学会使用tinyxml库

http://edu.csdn.net/course/detail/2590

在Windows下SVN的版本管理与实战 

http://edu.csdn.net/course/detail/2579

Visual Studio 2015开发C++程序的基本使用 

http://edu.csdn.net/course/detail/2570

在VC2015里使用protobuf协议

http://edu.csdn.net/course/detail/2582

在VC2015里学会使用MySQL数据库

http://edu.csdn.net/course/detail/2672

对web开发技术感兴趣的同学,欢迎私信小编加群,不管你是小白还是大牛我都欢迎,还有大牛整理的一套高效率学习路线和教程与您免费分享,同时每天更新视频资料。

最后,祝大家早日学有所成,拿到满意offer,快速升职加薪,走上人生巅峰

相关文章

网友评论

      本文标题:js也能写3D游戏?

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