我需要计算2d,x y width和height中的摄像机视图边界

在这个屏幕截图中,网格是每个1个单位,我需要计算3d视图的边界框,在上面的示例图像中,结果应该是:
float x = -3;
float y = 0;
float width = 14;
float height = 6;发布于 2019-09-21 01:59:56
假设你的相机总是向下看你的世界,所以地平线是不可见的,并且相机总是平行于地图的Y轴,所以水平线永远不会弯曲,我认为这是一个计算视野中最远的线的宽度的问题,因为在那里透视将水平地向你显示最多的瓦片。这将使您获得一个矩形区域的平铺贴图,该区域完全覆盖了圆锥体,尽管您将在近角绘制一些额外的平铺。
private final Ray tmpRay = new Ray();
private final Vector3 tmpVec = new Vector3();
private final Rectangle visibleTilesRegion = new Rectangle();
private void updateVisibleTilesRegion (){
// Define a ray that is a projection of the direction the camera is looking onto the
// tile plane (assuming it is a Z=0 plane).
tmpRay.origin.set(camera.position.x, camera.position.y, 0f);
tmpRay.direction.set(0f, 1f, 0f);
//Find top and bottom
Intersector.intersectRayPlane(tmpRay, camera.frustum.planes[4], tmpVec);
float yTop = tmpVec.y;
Intersector.intersectRayPlane(tmpRay, camera.frustum.planes[5], tmpVec);
float yBottom = tmpVec.y;
// Find left and right at the top of the screen by intersecting that line with the left
// and right planes
tmpRay.origin.set(camera.position.x, yTop, 0f);
tmpRay.direction.set(-1f, 0f, 0f);
Intersector.intersectRayPlane(tmpRay, camera.frustum.planes[2], tmpVec);
float xLeft = tmpVec.x;
tmpRay.direction.set(1f, 0f, 0f);
Intersector.intersectRayPlane(tmpRay, camera.frustum.planes[3], tmpVec);
float xRight = tmpVec.x;
visibleTilesRegion.set(xLeft, yBottom, xRight - xLeft, yTop - yBottom);
}https://stackoverflow.com/questions/58025552
复制相似问题