我正在嘗試使用Jonathan Feinberg的Peasycam庫進行處理以圍繞物體的Z軸旋轉相機。 documentation指定旋轉是圍繞主體,而不是對象。這似乎難以實現。 peasycam旋轉圍繞主體(即相機)而非物體,儘管在控制意義上peasycam的重點是面向對象的。並且設置camera()
似乎也有問題,因爲我無法讓peasycam記住分配的相機的位置。 Peasycam的y軸映射到數據空間的z軸也有差異。使用Peasycam旋轉相機周圍的物體軸
我做了一個基本的模型來幫助解釋這個交互。感謝一些新鮮的眼睛可以幫助解決這個問題。 Peasycam可能會將need installing添加到應用程序的庫文件夾中。總體目標是爲了動畫目的能夠在Z軸上旋轉3D數據圖。提前致謝。
import peasy.*;
PVector camPos;
PVector[] points = new PVector[50];
float angleXY, d;
PeasyCam cam;
void setup() {
size(300,300,P3D);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(50);
cam.setMaximumDistance(150);
for(int i=0; i<50; i++) points[i] = new PVector(random(-15,15),random(-15,15),random(-15,15));
}
void draw() {
background(250);
noFill();
box(30);
// axes for frame of reference
stroke(255,0,0); // red = Z
line(0,0,-100,0,0,100);
stroke(0,255,0); // green = Y
line(0,-100,0,0,100,0);
stroke(0,0,255); // blue = X
line(-100,0,0,100,0,0);
// points on axes to denote positive orientation
strokeWeight(3);
for(PVector p:points) point(p.x, p.y, p.z);
strokeWeight(5);
point(40,0,0);
point(0,40,0);
point(0,0,40);
strokeWeight(1);
stroke(0);
camPos = new PVector(cam.getPosition()[0], cam.getPosition()[1], cam.getPosition()[2]);
angleXY = degrees(atan2(camPos.z, camPos.x)); // camera XY angle from origin
d = sqrt(pow(camPos.z, 2) + pow(camPos.x, 2)); // camera-object XY distance (compare to cam.getDistance())
// ZX campera slots map to XY data plane:
println("campos: " + camPos + " " + ", ang: " + angleXY + ", dist:" + d);
}
void keyPressed(){
if(key=='r') setup(); // restart
if(key==' ') camera(camPos.x, camPos.y, camPos.z, 0, 0, 0, 0, 0, 1); // stabilise image on Z axis
if(key=='d') {
angleXY += radians(1);
camera(sin(angleXY)*d, camPos.y, cos(angleXY)*d, 0, 0, 0, 0, 1, 0);
}
// peasycam's rotations work around the subject:
if(key=='p') cam.rotateY(radians(2));
}
peasycam的事情是,它總是有「旋轉[圍繞軸通過查看點]」。爲了解決這個問題,你必須補償圍繞另外兩個軸的旋轉並將其發送到peasycam。你需要的是「桌面」旋轉。如果我可以提供一個簡單的方法來實現您的整體目標,請從草圖中刪除peasycam並添加:攝像頭(70 * sin(frameCount * .02),70 * cos(frameCount * .02), 70,0,0 ,0,0,0,-1); –