【发布时间】:2017-03-18 06:16:17
【问题描述】:
现在,我正在尝试使用分离轴定理在 Java 中实现动态 3-D OBB 碰撞测试。我试图找到每个分离轴的实体从 0 到 1 的交点时间,其中 0 是帧的开始,1 是帧的结束。
这是我的代码:
private float calculateITime(OBB obb,
Vector3f axis /*the separating axis we are testing*/,
Vector3f d /*Current OBB's origin minus other OBB's origin*/,
float ra /*the first obb's projection*/,
float rb /*the second obb's projection*/,
float r /*what I understand to be the total length of the combined projections*/) {
//Find the time, from 0 (the beginning of the frame) to 1 (the end of the frame), that the obb's first intersected.
float intersectionLength = r - Math.abs(ra) - Math.abs(rb); //The measure of how much the two projections overlap
Vector3f aVelocity = this.getCollisionPacket().getVelocity();
Vector3f bVelocity = obb.getCollisionPacket().getVelocity();
double aMagnitude = Mathematics.dotProduct(axis, Mathematics.crossProduct(aVelocity, d));
double bMagnitude = Mathematics.dotProduct(axis, Mathematics.crossProduct(bVelocity, d));
double totalDistanceCovered = 0;
if(aMagnitude <= 0 && bMagnitude <= 0) {
totalDistanceCovered = Math.abs(aMagnitude - bMagnitude);
} else if((aMagnitude >= 0 && bMagnitude <= 0) || (aMagnitude <= 0 && bMagnitude >= 0)) {
totalDistanceCovered = Math.abs(aMagnitude + bMagnitude);
} else if(aMagnitude >= 0 && bMagnitude >= 0) {
totalDistanceCovered = Math.abs(aMagnitude - bMagnitude);
}
System.out.println("PotentialITime: " + Math.abs(intersectionLength / totalDistanceCovered));
return (float) Math.abs(intersectionLength / totalDistanceCovered);
}
但是,我的值远高于 1。假设我什至正确理解如何正确实现分离轴定理,我哪里错了?
如果您认为您有答案,但如果我发布课程的其余部分会有所帮助(虽然它很长),请告诉我,我会为您解答。谢谢!
最后说明:
此函数在 OBB 类中。因此,“this”指的是 OBB,“obb”指的是另一个 OBB。
collisionPacket.getVelocity() 返回在没有碰撞的情况下将在单个帧中发生的总位移。
“数学”是我自己的静态类。假设它工作正常。直到我做出来之后,我才意识到 Vector3f 拥有所有这些有用的功能。
This 是我正在使用的 PDF。我在 2.3.1 的第 9 页卡住了。
【问题讨论】: