我正在尝试使用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); –