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成功繞任何軸。
紋理(planet2.png和sun.jpg)缺少 –
@GeorgeProfenza appologies,我不知道如何在這裏上傳圖片。任何圖像文件都可以用來紋理球體,或者只是在他們的位置使用填充 –