Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...