Processing 三球速度差

Processing 三球速度差,processing,Processing,我是一个新的编码处理,这就是为什么请温柔。我为你做了一个简单的代码。通常我的代码更长更复杂。但是,我为您编写了一个简单的代码 //main class ArrayList<Clouds> clouds = new ArrayList(); void setup() { size(1200, 800, P3D); for (int i = 0; i < 3; i++) { Clouds C = new Clouds(); clouds.add(C)

我是一个新的编码处理,这就是为什么请温柔。我为你做了一个简单的代码。通常我的代码更长更复杂。但是,我为您编写了一个简单的代码

//main class
ArrayList<Clouds> clouds = new ArrayList();

void setup() {
  size(1200, 800, P3D);

  for (int i = 0; i < 3; i++)
  {
    Clouds C = new Clouds();
    clouds.add(C);
  }
}

void draw() {
  background(0); 
  for (int i = 0; i < clouds.size(); i++)
  {
    clouds.get(i).drawClouds();
  }
}

//Clouds class

class Clouds
{
  float xC, yC, zC, speedC;
  public Clouds()
  {
    xC = 20;
    yC = 40;
    zC = 0;
    noStroke();
    speedC = 1;
  }
  public void drawClouds()
  {
    translate(xC,yC);
    pushMatrix();
    makingClouds(100, 100, 100);
    popMatrix();
    if (xC > width - 780) {
      xC = -660; 
    }
    xC += speedC; 
  }
  public void makingClouds(float xF, float yF, float zF ) {
    translate(xF, yF, zF);
    pushMatrix();
    lights();
    scale(1, 1, 1);
    sphere(20);
    popMatrix();
  }
}
//主类
ArrayList clouds=新的ArrayList();
无效设置(){
尺寸(1200、800、P3D);
对于(int i=0;i<3;i++)
{
云C=新云();
添加(C);
}
}
作废提款(){
背景(0);
对于(int i=0;i宽度-780){
xC=-660;
}
xC+=speedC;
}
公共虚空生成云(浮动xF、浮动yF、浮动zF){
翻译(xF、yF、zF);
pushMatrix();
灯光();
量表(1,1,1);
球体(20);
popMatrix();
}
}
我希望,我在这里写两堂课没有做错,但我已经写了整整两天了,让我感到恶心。所以我的问题是:就像你们看到的,有三个球体,它们的速度相同,但当我运行程序时,它们以不同的速度结束。他们怎么有相同的速度?如果你帮助我,你将是我的英雄!谢谢。

不要只设置翻译,它定义了翻译矩阵,并将新的翻译矩阵乘以当前矩阵

必须在不同位置构建云:

void setup(){
// [...]
对于(int i=0;i<3;i++){
云C=新云(20,i*40);
添加(C);
}
} 
类云{
浮点数xC、yC、zC、speedC;
公共云(浮动x、浮动y){
xC=x;
yC=y;
zC=0;
// [...]
}
要在/块中移动
translate

类云{
// [...]
公共云(){
pushMatrix();
翻译(xC,yC);
// [...]
popMatrix();
// [...]
}
公共虚空生成云(浮动xF、浮动yF、浮动zF){
pushMatrix();
翻译(xF、yF、zF);
// [...]
popMatrix();
}
示例代码:

//主类
ArrayList clouds=新的ArrayList();
无效设置(){
尺寸(1200、800、P3D);
对于(int i=0;i<3;i++){
云C=新云(20,i*40);
添加(C);
}
}
作废提款(){
背景(0);
对于(int i=0;i宽度-780){
xC=-660;
}
xC+=speedC;
}
公共虚空生成云(浮动xF、浮动yF、浮动zF){
pushMatrix();
翻译(xF、yF、zF);
灯光();
量表(1,1,1);
球体(20);
popMatrix();
}
}

这是因为你要翻译几次(它在一个循环中)。球体在循环中的次数越多,对它应用的
translate
就越多,这就是为什么你要创建更多的“云”它们看起来会越来越快。@Iaancelot非常感谢你,你也是一个英雄。我对翻译函数的理解是错误的。Awe非常感谢@rabbi76你是一个英雄!我完全理解你对翻译函数和变量的看法。