【发布时间】:2016-11-02 23:15:03
【问题描述】:
抱歉所有代码,但基本上我正在尝试设置一个相机来跟随一颗行星,因为它围绕它的太阳运行。如何让相机跟随地球? draw 中的旋转根本不移动相机。
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,我不知道如何在这里上传图片。任何图像文件都可以对球体进行纹理处理,或者只是在它们的位置使用填充
标签: java 3d camera processing