java让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绕任何轴成功旋转
# 1 楼答案
我在MapleMath做过类似的事情,在那里我让月亮绕着地球转,两个绕着太阳转。使用参数方程很容易。您希望摄影机环绕地球或太阳运行。您的相机位于固定位置。远在地球之外
我刚刚开始学习处理,它已经被证明具有优越的视觉效果。我建议您使用一个运行参数的数学程序来生成点的输出表 或顶点,然后在beginShape之后剪切并粘贴表格。我已经下载了你的代码,并将处理它。 实际上,我正试图构建一些非常相似的东西。我很乐意在不久的将来与大家分享。 振动 vburach@shaw.ca