2016-11-02 8 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で何か似たようなことをしています。そこに月が地球を回っていて、2人が太陽の周りを周回していました。パラメトリック方程式を使うのは簡単です。カメラが地球の周りを周回するか、太陽の周回軌道を周回するようにします。あなたのカメラは固定位置にあります。地球をはるかに超えている。

私はすでに優れた映像を持っていることが証明されている処理を学び始めています。 Parametricsを実行するMathプログラムを使用して、 ポイントまたは頂点の出力テーブルを生成し、beginShapeの後にテーブルをカットアンドペーストすることをお勧めします。私はあなたのコードをダウンロードし、それに取り組むでしょう。 私は実際に非常に似たようなものを構築しようとしています。私はいつかすぐに分かち合うことができます。 VIB [email protected]

関連する問題