我有一個圓形物體,我想沿着它自己的軸旋轉一個扇形物體。圍繞軸旋轉物體
我可以改變任何方向的旋轉,即dx, dy, dz
使用我的變換矩陣。
下它的代碼:
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
Matrix4f.translate(translation, matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);
我的頂點代碼:
vec4 worldPosition = transformationMatrix * vec4(position,1.0);
vec4 positionRelativeToCam = viewMatrix*worldPosition;
gl_Position = projectionMatrix *positionRelativeToCam;
Main Game Loop:
Object.increaseRotation(dxf,dyf,dzf);
但是,它不是沿着它自己的軸旋轉。我在這裏錯過了什麼? 我想要這樣的東西。請幫助
見[4×4認識同質變換矩陣(http://stackoverflow.com/a/28084380/2521214)子彈**#5 **,並尋找本地之間差並在那裏進行全球輪換。 – Spektre
@Spektre會在回答中解釋需要做些什麼改變我也面臨類似問題 –
問題中的代碼太少,而不是問題的出現位置。數學的應用是正確的。所以我的猜測是,轉換矩陣無法正確加載到着色器的制服中。 – datenwolf