【发布时间】:2015-04-08 07:26:30
【问题描述】:
对于我的 OpenGL 场景中的每个对象,我想添加一个 BoundingBox,以便我可以将它们用于简单的碰撞检测。为此,我创建了一个简单的 BoundingBox 类,如下所示:
public class BoundingBox
{
private float[] mathVector;
public float[] minVector;
public float[] maxVector;
public BoundingBox(float minX, float maxX, float minY, float maxY,float minZ, float maxZ)
{
mathVector = new float[] {0, 0, 0, 0};
minVector = new float[] {minX, minY, minZ, 1};
maxVector = new float[] {maxX, maxY, maxZ, 1};
}
public void recalculate(float[] modelMatrix)
{
Matrix.multiplyMV(mathVector, 0, modelMatrix, 0, minVector, 0);
System.arraycopy(mathVector, 0, minVector, 0, minVector.length);
Matrix.multiplyMV(mathVector, 0, modelMatrix, 0, maxVector, 0);
System.arraycopy(mathVector, 0, maxVector, 0, maxVector.length);
}
public boolean overlap(BoundingBox bb)
{
return (maxVector[0] >= bb.minVector[0] && bb.maxVector[0] >= minVector[0]) &&
(maxVector[1] >= bb.minVector[1] && bb.maxVector[1] >= minVector[1]) &&
(maxVector[2] >= bb.minVector[2] && bb.maxVector[2] >= minVector[2]);
}
}
我现在的问题是重新计算功能实际上不起作用。我认为将矩阵(因为存储了旋转、位置和 sclae)与向量相乘就足够了,它看起来还不够。我还需要做什么才能进行重新计算工作?
【问题讨论】:
标签: opengl collision-detection bounding-box