簡體   English   中英

jPCT:奇怪的攝像機旋轉

[英]jPCT: Strange camera rotation

我已經通過jPCT創建了Rubik's cube,現在我需要旋轉整個立方體。 我嘗試通過旋轉矩陣來實現此目的,並且旋轉了單個多維數據集元素,但這似乎不是一個好方法。

所以我想繞立方體旋轉攝像機,而不是旋轉立方體。 這很容易,但是問題是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的最新版本。

如何實現正確的相機方向? 任何幫助都非常歡迎!

如果要旋轉多維數據集(這似乎是您實際要執行的操作),為什么不簡單地在其中心放置一個虛擬Object3D,使該虛擬對象的多維數據集子代的所有元素僅旋轉該虛擬對象呢? 那實際上應該給您期望的結果。 關於您的方法:您可以確定旋轉不是隨機的。 您可以在代碼中得到想要的東西。 為什么這會導致您在這里實際看到的內容,而又不知道完整的場景設置就很難說出來。 無論如何,最簡單的方法是圍繞空間中的某個固定點旋轉相機,就是讓它在初始設置中看着該點,然后執行以下操作:

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

其中,距離是從攝像機到旋轉樞軸的初始距離。 您可以在此處找到示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM