kn0*_*ulo 2 javascript vector three.js
我必须用three.js 创建一个小型太阳系(1 个恒星、2 个行星、1 个卫星绕行星运行) 这是我第一次用three.js(以及一般的JavaScript)编程,所以我是一个完全的新手。
我设法创建了我的静态系统,这样我就有了太阳、火星、火卫一、地球和月球。
现在我不知道如何让行星绕太阳运行,卫星绕行星运行。
这是我到目前为止所做的
//global variables declaration
function init(){
/*starting code: cameras, declaring variables and so on*/
function celestialBodiesSetup(){
var geometry,material,image;
var celestialBodies=[sun,mars,phobos,earth,moon];
//sun, mars etc are declared as global variables before the init function
for(var i=0;i<celestialBodies.length;i++){
switch (celestialBodies[i]){
case sun:
material=new THREE.MeshPhongMaterial();
geometry =new THREE.SphereGeometry(35,32,32);
image="mysun.png";
sun=createSphere(geometry,material,image);
sun.position.set(0,0,20);
var pointLight = new THREE.PointLight( 0xFDFDFD, 2, 1800,70 );
sun.add(pointLight);
break;
case mars:
material=new THREE.MeshPhongMaterial();
geometry =new THREE.SphereGeometry(17,32,32);
image="mars.jpg";
mars=createSphere(geometry,material,image,sun);
mars.position.set(150,-15,0);
break;
/*repeat process for the remaining celestial bodies*/
function createSphere(geometry,material,image,celBody){
var sphere = new THREE.Mesh(geometry, material);
material.map= THREE.ImageUtils.loadTexture(image);
if(celBody) celBody.add(sphere); /*I set that all the planets are added to the sun, and all
the moons are added to their planet. Only the sun is added to the scene itself*/
else scene.add(sphere);
return sphere;
}
celestialBodiesSetup();
}
Run Code Online (Sandbox Code Playgroud)
在这一点上,我必须处理 animate() 函数,但我对向量、旋转等一无所知。
我唯一能做的就是设置类似 earth.rotation.y+=0.1 的东西,以便行星开始绕其轴旋转,但仅此而已。
你为什么不试试
http://www.html5rocks.com/en/tutorials/casestudies/100000stars/
案例研究,这很好,另外还有很多例子
https://www.chromeexperiments.com/?q=solar%20
为了更好地参考threejs库启动器,请继续示例可视化
http://stemkoski.github.io/Three.js/
http://mrdoob.github.io/three.js/examples/canvas_geometry_earth.html
http://oos.moxiecode.com/blog/index.php/experiments/javascript-webgl/
在库接口的抽象级别,这些教程可以帮助您制作项目。您需要花时间在旋转向量、四元数和着色器上才能深入。
您还可以查看 Unity 3d 引擎,为您的东西构建一个快速的隔夜原型,以获取用于演示的东西。
| 归档时间: |
|
| 查看次数: |
8385 次 |
| 最近记录: |