void setup() {
size(640, 360, P3D);
frameRate(10);
}
void draw() {
cameraRotation();
background(0);
lights();
fill(120,10,120);
box(40,20,40);
}
void cameraRotation() {
for (int i=0; i<360; i+=1) {
camera(80*cos(i), -25, 80*sin(i),
0,0,0,
0,1,0);
}
}
我想让相机围绕中央盒子旋转。我的cameraRotation
方法应该将相机移动到物体上方的圆圈中,同时始终聚焦在物体上。
我得到了一个盒子的静止图像。我尝试将frameRate设置得更低。
答案 0 :(得分:0)
首先,Processing在其trig函数中使用弧度,因此你应该将0 - 360转换为0 - TWO_PI。
其次,你每帧都要更换相机360次。 cameraRotation函数不应包含for循环。您可以在绘制循环中递增变量:
int ang = 0;
void setup() {
...
}
void draw() {
cameraRotation(ang);
...
ang+=1;
if ( ang > 360 ) ang = 0;
}
void cameraRotation( int a ) {
camera(80*cos(a), -25, 80*sin(a),
0,0,0,
0,1,0);
}
该递增也可以包含在cameraRotation函数中。
或者您可以使用frameCount和模数来循环数字。
void cameraRotation() {
int a = frameCount % 360;
camera(80*cos(a), -25, 80*sin(a),
0,0,0,
0,1,0);
}
同样,您可能不希望使用整数0-360,因为它可以非常快速地旋转。您可能希望将这些数字转换为浮点数并进行一些除法以使它们更小以实现更平滑的旋转。