所以我的边界框有一个非常奇怪的行为。每次我平移任何值为负的对象时,边界框都会被拉伸到 0 点。
这是正面翻译的样子:
一切安好。但现在我用负 Z 坐标翻译它。
这是我创建边界框的代码:
private final void calcBoundingBox() {
if(this.mesh != null) {
float[] vertices = this.mesh.getVertexArray().getBuffer(0).getDataAsFloats();
float xn = Float.MAX_VALUE;
float yn = xn;
float zn = xn;
float xf = Float.MIN_VALUE;
float yf = xf;
float zf = xf;
for(int index = 0; index < vertices.length; index += 3) {
Vector3f vertex = MatrixUtil.multiply(this.transformation, vertices[index], vertices[index + 1], vertices[index + 2]);
float x = vertex.x;
float y = vertex.y;
float z = vertex.z;
if(x < xn) xn = x; else if(x > xf) xf = x;
if(y < yn) yn = y; else if(y > yf) yf = y;
if(z < zn) zn = z; else if(z > zf) zf = z;
}
float width = xf - xn;
float height = yf - yn;
float depth = zf - zn;
this.boundingBox.setBounds(xn, yn, zn, width, height, depth);
}
}
public static final Vector3f multiply(Matrix4f matrix, float x, float y, float z) {
Vector3f result = new Vector3f();
result.x = (x * matrix.m00) + (y * matrix.m10) + (z * matrix.m20) + matrix.m30;
result.y = (x * matrix.m01) + (y * matrix.m11) + (z * matrix.m21) + matrix.m31;
result.z = (x * matrix.m02) + (y * matrix.m12) + (z * matrix.m22) + matrix.m32;
return result;
}
我现在的问题是:我做错了什么?
ABOUTYOU
哈士奇WWW
相关分类