我在放大时无法重新调整球体的大小,以便随着盒子一起变小,并且随着盒子变小,碰撞边界也会调整大小。我究竟做错了什么?这是我的代码:
float rotX, rotY;
float zoom = 1;
float angle = 0;
float bounds = 500;
int amount = 8000;
MovingSphere s;
int[] x = new int[amount];
int[] y = new int[amount];
int[] z = new int[amount];
void setup() {
size(900, 900, P3D);
background(0);
noFill();
stroke(255);
strokeWeight(1);
s = new MovingSphere();
for(int i = 0; i<amount; i++) {
x[i] = int(random(-250, 250));
y[i] = int(random(-250, 250));
z[i] = int(random(-250, 250));
}
}
void draw() {
background(0);
translate(width/2, height/2);
lights();
pushMatrix();
//translations();
//scale (zoom);
//rotate (angle);
s.collisions();
s.location();
s.display();
popMatrix();
translations();
scale (zoom);
rotate (angle);
//s.collisions();
//s.location();
//s.display();
box(bounds);
for(int i = 0; i<amount; i++) {
point(x[i], y[i], z[i]);
}
}
void mouseDragged(){
float x1 = mouseX-pmouseX;
float y1 = mouseY-pmouseY;
rotX += -y1 * 0.01;
rotY += x1 * 0.01;
}
void translations() {
rotateX(rotX);
rotateY(rotY);
}
void mouseWheel(MouseEvent event){
float e = event.getCount();
zoom += e *.01;
println(e);
}
第二档:
float xpos = 200;
float ypos = 50;
float gravity = 0.98;
float bounce = -1;
class MovingSphere {
PVector position;
PVector velocity;
MovingSphere(){
position = new PVector(0, 0, 0);
velocity = new PVector(2.5, 5, 7.5);
//vy = new PVector(0, 0, 0);
}
void location() {
position.add(velocity);
translate(position.x, position.y, position.z);
}
void collisions(){
if (position.x > bounds/2.7 || position.x < -bounds/2.7) {
velocity.x*=-1;
}
if (position.y > bounds/2.7 || position.y < -bounds/2.7) {
velocity.y*=-1;
}
if (position.z > bounds/2.7 || position.z < -bounds/2.7) {
velocity.z*=-1;
}
}
void display() {
//stroke(255);
//fill(50, 70, 230);
sphere(30);
}
}