Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

processing - rotate/point with sub-pixel precision

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]);
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...