【发布时间】:2011-06-16 00:59:35
【问题描述】:
给定视锥体(由 x、y、z 相机位置、旋转 [0-360)和俯仰 [0-180)以及视角(例如 45)定义)什么是(最好是最快的)用于确定一个框(由两个相对的角点定义)是否部分或全部在该截锥内的 Java 代码?
更准确地说,我该如何完成以下内容?
static boolean isBoxInFrustum(float cx, float cy, float cz, // Vector camera,
float rotation, float pitch, float angle,
float p1x, float p1y, float p1z, // Vector point1,
float p2x, float p2y, float p2z) { // Vector point2
//...
}
C++ 实现可以在http://www.lighthouse3d.com/tutorials/view-frustum-culling/找到
编辑:这是 2d 版本,它只有 4 行,在我看来很容易理解 - 如何修改为 3d 检查?
static boolean isPointInFrustum(
Vector cam, float rot, float pitch, float ang, Vector point) {
Vector diff = cam.minus(point);
float deg = Maths.arctan(diff.y, diff.x) + rot + 360;
deg %= 360;
return (deg > 180-ang && deg < 180+ang);
}
【问题讨论】: