有必要确定模型的三角形(鹰)是否在矩形平面内。写了这个程序,但由于某种原因,它运行得很糟糕。是什么原因?
matrCoord
- 三角形的顶点projMatrCopy
- 投影矩阵 P * V * M 。我得到了模型三角形顶点的新坐标:
private Vector3f getVector(int pos) {
Matrix4f projMatrCopy = new Matrix4f().set(proj);
Matrix4f matrCoord = new Matrix4f(new Vector4f(positions[pos], positions[pos + 1], positions[pos + 2], 1.0f),
new Vector4f(0, 0, 0, 0),
new Vector4f(0, 0, 0, 0),
new Vector4f(0,0,0, 0));
Vector4f p1 = new Vector4f();
projMatrCopy.mul(matrCoord).getColumn(0, p1);
return new Vector3f(p1.x, p1.y, p1.z);
}
然后我检查这个顶点以查看它是否在矩形区域内。我是这样做的:
private boolean intersectsPlaneToPoint(Vector3f point, List<Vector4f> planes) {
Float d1 = Intersectionf.distancePointPlane(point.x, point.y, point.z,planes.get(0).x,planes.get(0).y,planes.get(0).z,planes.get(0).w);
Float d2 = Intersectionf.distancePointPlane(point.x, point.y, point.z, planes.get(1).x,planes.get(1).y,planes.get(1).z,planes.get(1).w);
Float d3 = Intersectionf.distancePointPlane(point.x, point.y, point.z, planes.get(2).x,planes.get(2).y,planes.get(2).z,planes.get(2).w);
Float d4 = Intersectionf.distancePointPlane(point.x, point.y, point.z, planes.get(3).x,planes.get(3).y,planes.get(3).z,planes.get(3).w);
Float d5 = Intersectionf.distancePointPlane(point.x, point.y, point.z, planes.get(4).x,planes.get(4).y,planes.get(4).z,planes.get(4).w);
Float d6 = Intersectionf.distancePointPlane(point.x, point.y, point.z,planes.get(5).x,planes.get(5).y,planes.get(5).z,planes.get(5).w);
return d1 < 0 && d2 < 0 && d3 < 0 && d4 >= 0 && d5 < 0 && d6 >= 0;
}
planes.get (0).x, planes.get (0).y, planes.get (0).z, planes.get (0).w
是飞机的 a b c d 组件
必须输出: