我要創建一個小型太陽能系統簡單太陽能系統(1星,2個行星,月亮1每星球orbitating)與three.js所 這是我第一次編程一些與three.js所(和JavaScript一般)所以我是一個完整的新手。與three.js所
我設法創建我的靜態系統,讓我有太陽,火星,火衛一,地球和月亮。
現在我不知道如何使行星是圍繞太陽運行的軌道,而月亮在他們的行星軌道。
這是我到目前爲止
//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();
}
做在這一點上我對動畫()函數的工作,但我不知道向量,旋轉等線索。
只有我能做的事情就是設置類似earth.rotation.y + = 0.1,使這個星球上開始它的軸旋轉,但僅此而已。
這是你應該做你自己的任務? – WestLangley
請使用空格和新行。爲了你和我們的緣故。 –
這是我正在做的一項練習,因爲我的教授總是提出關於矢量的問題,我認爲這會幫助我,而不是它讓我瘋狂@WestLangley – kn0bbulo