-1
我一直在嘗試製作3D遊戲引擎。到目前爲止,除了旋轉邊界框之外,所有工作都可以使我嘗試過不同的方式來做到這一點,我發現在這裏。幾乎一切都是一樣的。 「製作旋轉矩陣並將其應用於最小和最大邊界框。」這就是我現在這樣做的方式,但有各種各樣的問題。我認爲這是圍繞世界零點旋轉。另外我有兩個對象顯示最小和最大點,旋轉後它不會在這兩件事之間發生碰撞。LWJGL - 旋轉後更新3D邊界框座標
我變換矩陣:
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale) {
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);
return matrix;
}
更新碰撞盒:
Matrix4f rotationMin = Maths.createTransformationMatrix(min, rotX, rotY, rotZ, scale);
Matrix4f rotationMax = Maths.createTransformationMatrix(max, rotX, rotY, rotZ, scale);
min = Maths.transform(min, rotationMin);
max = Maths.transform(max, rotationMax);
min.x += difX/2;
min.y += difY/2;
min.z += difZ/2;
max.x += difX/2;
max.y += difY/2;
max.z += difZ/2;
和應用矩陣MIN和MAX:
public static Vector3f transform(Vector3f vector, Matrix4f matrix) {
Vector4f vec = new Vector4f(vector.x, vector.y, vector.z, 1.0f);
Vector4f result = new Vector4f(
(vec.x * matrix.m00) + (vec.y * matrix.m01) + (vec.z * matrix.m02) + (vec.w * matrix.m03),
(vec.x * matrix.m10) + (vec.y * matrix.m11) + (vec.z * matrix.m12) + (vec.w * matrix.m13),
(vec.x * matrix.m20) + (vec.y * matrix.m21) + (vec.z * matrix.m22) + (vec.w * matrix.m23),
1
);
return new Vector3f(result.x/result.w, result.y/result.w, result.z/result.w);
}
所有這一切都與LWJGL和Java(做+着色器的GLSL)。
Collinsions在旋轉之前完美地工作。 http://imgur.com/a/39Sya
那麼沒有人得到答案? – Maineri