【发布时间】:2015-07-08 23:38:23
【问题描述】:
我已经通过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。
如何实现正确的相机方向?非常欢迎任何帮助!
【问题讨论】: