2016-11-02 28 views
1

對不起,所有的代碼,但基本上我試圖設置一個相機跟隨一個行星,因爲它圍繞它的太陽軌道。我如何讓相機跟隨地球?平局中的旋轉根本不會移動相機。得到PeasyCam跟隨一個球形,因爲它繞着另一個球體的軌道處理

import peasy.*; 
import peasy.org.apache.commons.math.*; 
import peasy.org.apache.commons.math.geometry.*; 
import peasy.test.*; 


float sunRadius, planetRadius; 
PImage mercury; 
PImage the_sun; 
PVector sunCenter; 
PVector spoke; 
Planet ourSun; 
Planet ourPlanet; 
float orbitSpeed = 0; 
PeasyCam camera; 



void setup() 
{ 
    size(1000,700, P3D); 

    sunRadius = 200; 
    planetRadius = 50; 

    mercury = loadImage("planet2.png"); 
    the_sun = loadImage("sun.jpg"); 

    sunCenter = new PVector(width/2, height/2, -500); 
    spoke = new PVector(1,0,1); 

    ourSun = new Planet(the_sun, sunRadius); 
    ourPlanet = new Planet(mercury, planetRadius); 
} 

void draw() 
{ 
    background(0); 
    ourSun.show(sunCenter); 
    ourPlanet.orbit(sunCenter, spoke, orbitSpeed, 1000); 

    pushMatrix(); 
     rotateY(orbitSpeed); 
     camera = new PeasyCam(this, sunCenter.x, sunCenter.y, sunCenter.z, 4000); 
     camera.setActive(false); 
    popMatrix(); 

    orbitSpeed += 0.01; 

} 




class Planet { 

    float sizeof; 
    PShape planet; 

    Planet(PImage img, float sizeof) 
    { 
     noStroke(); 
     noFill(); 
     this.sizeof = sizeof; 
     planet = createShape(SPHERE, sizeof); 
     planet.setTexture(img); 
    } 


    void show(PVector position) 
    { 
     pushMatrix(); 
     translate(position.x, position.y, position.z); 
     shape(planet); 
     popMatrix(); 
    } 

    void orbit(PVector parent, PVector spoke, float speed, float distance) 
    { 
     pushMatrix(); 
      translate(parent.x, parent.y, parent.z); 
      PVector traj = new PVector(parent.x-distance, 0, 0); 
      PVector axis = traj.cross(spoke); 
      rotate(speed, axis.x, axis.y, axis.z); 
      translate(traj.x, traj.y, traj.z); 
      shape(planet); 
     popMatrix(); 

    } 

} 

我有困難計算地球球體的中心點,因爲它旋轉,平移,也得到peasycam成功繞任何軸。

+0

紋理(planet2.png和sun.jpg)缺少 –

+0

@GeorgeProfenza appologies,我不知道如何在這裏上傳圖片。任何圖像文件都可以用來紋理球體,或者只是在他們的位置使用填充 –

回答

0

我在MapleMath中做過類似的事情,那裏有月球繞地球旋轉,兩個繞太陽旋轉。使用參數方程很容易。你想讓相機繞地球運行或繞太陽運行。您的相機位於固定位置。遠遠超出地球。

我剛剛開始學習處理,這已經證明具有卓越的視覺效果。我可以建議您使用一個運行參數的數學程序,它將生成點 或頂點的輸出表格,並在beginShape之後剪切並粘貼表格。我已經下載了你的代碼,並且會對它進行處理。 我實際上試圖構建一些非常相似的東西。我很樂意儘快分享。 vib [email protected]

相關問題