问题
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