rotate/point with sub-pixel precision

荒凉一梦 提交于 2019-12-25 06:49:58

问题


How may I get sub-pixel precision in position of the points plotted below? Only integer precision is used -- causing the observed wobble of the moving points.

int amount = 300;
float[] x = new float[amount];
float[] y = new float[amount];
float[] z = new float[amount];

void setup() {
  size(500, 400, P3D);
  stroke(255);
  strokeWeight(1);
  for(int i = 0; i<amount; i++) {
    x[i] = float(random(-150, 150));
    y[i] = float(random(-150, 150));
    z[i] = float(random(-150, 150));
  }
}
void draw() {
  background(0);

  translate(width/2, height/2);

  rotateX(-0.1);
  rotateY((frameCount/1000)*1);

  for(int i = 0; i<amount; i++) {
    point(x[i], y[i]/22, z[i]);
  }
}

回答1:


This is the same problem as your other question. You're using integer division, which truncates the decimal part.

This line:

rotateY((frameCount/1000)*1);

Needs to be this:

rotateY((frameCount/1000.0)*1);

For future reference, problems like these are easily spotted through some debugging. You need to go through your program and test every assumption you're making. In other words, print everything out. For example:

println(frameCount/1000);

That line would have shown you your entire problem.



来源:https://stackoverflow.com/questions/36213167/rotate-point-with-sub-pixel-precision

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!