3d 放大时处理调整形状大小
在放大时,我无法重新调整球体的大小,使其随着长方体变小,碰撞边界也会随着长方体变小而调整大小。我做错了什么?这是我的代码:3d 放大时处理调整形状大小,3d,resize,processing,3d,Resize,Processing,在放大时,我无法重新调整球体的大小,使其随着长方体变小,碰撞边界也会随着长方体变小而调整大小。我做错了什么?这是我的代码: 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];
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-rotX,rotY;
浮动缩放=1;
浮动角度=0;
浮动边界=500;
整数金额=8000;
运动球;
整数[]x=新整数[金额];
整数[]y=新整数[金额];
int[]z=新的int[金额];
无效设置(){
尺寸(900900,P3D);
背景(0);
noFill();
中风(255);
冲程重量(1);
s=新的移动球体();
对于(int i=0;i界限/2.7 | |位置.y<-bounds/2.7){
速度y*=-1;
}
如果(位置z>bounds/2.7 | |位置z<-bounds/2.7){
速度z*=-1;
}
}
无效显示(){
//中风(255);
//填充(50、70、230);
球体(30);
}
}
您遇到了什么问题?这个代码是做什么的?你希望它做什么?代码的作用是使球体从长方体的边界反弹。可以放大、缩小或旋转长方体。但是,执行此操作时,旋转长方体或放大长方体时,长方体边界不会更改。我正在想办法解决这个问题。
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);
}
}