【问题标题】:Get PeasyCam to follow a sphere shape as it orbits another sphere in Processing让 PeasyCam 在处理中围绕另一个球体运行时跟随球体形状
【发布时间】: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


【解决方案1】:

我在 MapleMath 中做过类似的事情,我让月球围绕地球旋转,而两者都在绕太阳运行。使用参数方程很容易。您希望相机绕地球运行或绕太阳运行。您的相机位于固定位置。远远超出地球。

我刚刚开始学习 Processing,它已经被证明具有出色的视觉效果。我可以建议您使用一个运行参数的数学程序来生成点的输出表 或顶点,然后在 beginShape 之后剪切和粘贴表格。我已经下载了您的代码,并将继续使用它。 我实际上是在尝试构建一些非常相似的东西。我很乐意很快分享。 振动 vburach@shaw.ca

【讨论】:

    猜你喜欢
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 2015-04-26
    相关资源
    最近更新 更多