private bool IsGCPInCameraView(Camera camera, GroundControlPoint gcp) { // Here, we check if the gcp is actually in front of the camera Vector3 viewportPoint = camera.WorldToViewportPoint(gcp.position); return(0 <= viewportPoint.x && viewportPoint.x <= 1 && 0 <= viewportPoint.y && viewportPoint.y <= 1 && 0 <= viewportPoint.z); }
private bool HasNothingInFront(Texture2D screenShot, Camera camera, GroundControlPoint gcp) { // Here, we check if there is something between the camera and the gcp by comparing the color on the screenshow. // Another way could be to use Raycasting, but we would need to have good fitting colliders for trees in those cases, and it could be computationally expensive. Pixel pixel = WorldToPixel(camera, gcp.position); bool a = AreTheSameColor(gcp.color, screenShot.GetPixel(pixel.x, pixel.y)); return(a); }
private bool IsInSight(Texture2D screenShot, Camera camera, GroundControlPoint gcp) { return(IsGCPInCameraView(camera, gcp) && HasNothingInFront(screenShot, camera, gcp)); }