简体   繁体   English

jPCT:奇怪的摄像机旋转

[英]jPCT: Strange camera rotation

I have created Rubik's cube by jPCT and now I need to rotate this whole cube. 我已经通过jPCT创建了Rubik's cube,现在我需要旋转整个立方体。 I have tried to achieve this by rotation matrixes and I have rotated single cube elements but this does not seem to be good way.. 我尝试通过旋转矩阵来实现此目的,并且旋转了单个多维数据集元素,但这似乎不是一个好方法。

So I want to rotate my camera around the cube instead of rotating the cube. 所以我想绕立方体旋转摄像机,而不是旋转立方体。 It is pretty easy but problem is that jPCT changes the orientation of my camera randomly or I have done some another mistake and I am unable to fix it. 这很容易,但是问题是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) {

    }
}

Above code performs this strange rotation of cube: 上面的代码执行多维数据集的这种奇怪的旋转:

当前相机旋转

That is cool but I need rotate my cube like this: 太酷了,但是我需要像这样旋转我的立方体: 所需的相机旋转

I have tried to set camera orientation by setOrientation method: 我试图通过setOrientation方法设置相机方向:

SimpleVector upVector = world.getCamera().getUpVector();
upVector.scalarMul(-1.0f);
world.getCamera().setOrientation(world.getCamera().getDirection(), upVector);

The last line in this code should IMHO turn camera orientation upside down, but it just does nothing. 这段代码的最后一行应该恕我直言,将照相机方向颠倒过来,但是它什么也没做。 I use last version of jPCT. 我使用的是jPCT的最新版本。

How can I achieve right camera orientation? 如何实现正确的相机方向? Any help is very welcome! 任何帮助都非常欢迎!

If you want to rotate the cube, which seems to be what you actually want to do, why not simply put a dummy Object3D in its center, make all elements of the cube children of that dummy and only rotate the dummy? 如果要旋转多维数据集(这似乎是您实际要执行的操作),为什么不简单地在其中心放置一个虚拟Object3D,使该虚拟对象的多维数据集子代的所有元素仅旋转该虚拟对象呢? That should actually give you the desired results. 那实际上应该给您期望的结果。 About your approach: You can be sure that the rotations aren't random. 关于您的方法:您可以确定旋转不是随机的。 You get what you ask for in your code. 您可以在代码中得到想要的东西。 Why this results in what you are actually seeing here, is hard to tell without knowing your complete scene setup. 为什么这会导致您在这里实际看到的内容,而又不知道完整的场景设置就很难说出来。 Anyway, the easiest way to rotate the camera around some fixed point in space, is to make it look at that point in the initial setup, then do something like this: 无论如何,最简单的方法是围绕空间中的某个固定点旋转相机,就是让它在初始设置中看着该点,然后执行以下操作:

cam.moveCamera(Camera.CAMERA_MOVEIN, distance);
cam.rotateAxis(<some axis>, <float>);
cam.moveCamera(Camera.CAMERA_MOVEOUT, distance);

Where distance is the initial distance from the camera to the rotation pivot. 其中,距离是从摄像机到旋转枢轴的初始距离。 You can find an example here . 您可以在此处找到示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM