我已经用jPCT创建了魔方,现在我需要旋转整个魔方。我试图通过旋转矩阵来实现这一点,我已经旋转了单个立方体元素,但这似乎不是一个好方法。
所以我想让相机绕着立方体旋转,而不是旋转立方体。这很简单,但问题是jPCT随意改变了我相机的方向,或者我做了另一个错误,我无法修复它。
SimpleVector cameraPos = new SimpleVector(-20, 0, 0);
SimpleVector cubeCenter = new SimpleVector(2, 2, 2);
while (!org.lwjgl.opengl.Display.isCloseRequested()) {
refreshScene();
// Camera position is repeatedly rotated
cameraPos.rotateAxis(new SimpleVector(0, 0, 1), (float) Math.toRadians(1));
// Here I set camera position
world.getCamera().setPosition(cameraPos);
// Camera looks at the center of cube, but unfortunately
// not with fixed orientation
world.getCamera().lookAt(cubeCenter);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
}上面的代码执行这种奇怪的立方体旋转:

这很酷,但我需要像这样旋转我的立方体:

我尝试过用setOrientation方法设置摄像头方向:
SimpleVector upVector = world.getCamera().getUpVector();
upVector.scalarMul(-1.0f);
world.getCamera().setOrientation(world.getCamera().getDirection(), upVector);这段代码中的最后一行应该将相机方向颠倒,但它什么也不做。我使用的是最新版本的jPCT。
怎样才能获得正确的摄像头方向?我们非常欢迎您的帮助!
发布于 2015-04-30 03:47:06
如果你想旋转立方体,这似乎是你真正想要做的,为什么不简单地将一个虚拟的Object3D放在它的中心,使该虚拟的立方体的所有元素成为该虚拟的子元素,并且只旋转该虚拟的呢?这实际上应该会给你想要的结果。关于你的方法:你可以确保旋转不是随机的。你在你的代码中得到了你想要的。如果不知道完整的场景设置,就很难说出为什么会导致您在这里实际看到的结果。无论如何,在空间中围绕某个固定点旋转相机的最简单方法是在初始设置中使其看起来是该点,然后执行以下操作:
cam.moveCamera(Camera.CAMERA_MOVEIN, distance);
cam.rotateAxis(<some axis>, <float>);
cam.moveCamera(Camera.CAMERA_MOVEOUT, distance);其中距离是从相机到旋转轴的初始距离。你可以使用find an example here。
https://stackoverflow.com/questions/29947901
复制相似问题