すべてのコードは申し訳ありませんが、基本的に太陽を周回するようにカメラを設置しようとしています。カメラを地球に追いつけるにはどうすればいいですか?ドローイング時の回転は、カメラをまったく動かさない。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が欠落している、私はここに画像をアップロードする方法がわかりません。どんな画像ファイルでも球体をテクスチャ化するか、あるいはその場で塗りつぶしを使うだけです –