public float WorldYAt(float screenY, float zPosition, Layer layer) { if (layer == null || layer.LayerCameraSettings == null) { return(WorldYAt(screenY, zPosition, this.Orthogonal, this.OrthogonalHeight)); } else { LayerCameraSettings lcs = layer.LayerCameraSettings; Camera cameraToUse = layer.CameraBelongingTo; if (cameraToUse == null) { cameraToUse = this; } // If the orthogonal resolution per destination width/height // of the layer matches the Camera's orthogonal per destination, then // we can just use the camera. This is the most common case so we'll just // use that. //return WorldYAt(zPosition, cameraToUse, lcs.Orthogonal, lcs.OrthogonalHeight); // If we have a 2D layer ona 3D camera, then we shouldn't use the Camera's orthogonal values float orthogonalHeightToUse = cameraToUse.OrthogonalHeight; if (lcs.Orthogonal && !cameraToUse.Orthogonal) { orthogonalHeightToUse = lcs.OrthogonalHeight; } float layerMultiplier = 1; float bottomDestination = lcs.BottomDestination; float topDestination = lcs.TopDestination; if (bottomDestination == -1 || topDestination == -1) { bottomDestination = cameraToUse.BottomDestination; topDestination = cameraToUse.TopDestination; } if (lcs.Orthogonal && bottomDestination != topDestination) { layerMultiplier = lcs.OrthogonalHeight / (float)(bottomDestination - topDestination); } float cameraMultiplier = 1; if (cameraToUse.Orthogonal && cameraToUse.BottomDestination != cameraToUse.TopDestination) { cameraMultiplier = cameraToUse.OrthogonalHeight / (float)(cameraToUse.BottomDestination - cameraToUse.TopDestination); } layerMultiplier /= cameraMultiplier; orthogonalHeightToUse *= layerMultiplier; return(WorldYAt(screenY, zPosition, lcs.Orthogonal, orthogonalHeightToUse)); } }
public float WorldXAt(float screenX, float zPosition, Layer layer) { if (layer == null || layer.LayerCameraSettings == null) { return(WorldXAt(screenX, zPosition, this.Orthogonal, this.OrthogonalWidth)); } else { LayerCameraSettings lcs = layer.LayerCameraSettings; Camera cameraToUse = layer.CameraBelongingTo; if (cameraToUse == null) { cameraToUse = this; } // If the orthogonal resolution per destination width/height // of the layer matches the Camera's orthogonal per destination, then // we can just use the camera. This is the most common case so we'll just // use that. float destinationLeft = cameraToUse.DestinationRectangle.Left; float destinationRight = cameraToUse.DestinationRectangle.Right; float destinationWidth = destinationRight - destinationLeft; float horizontalPercentage = (screenX - destinationLeft) / (float)destinationWidth; float orthogonalWidthToUse = cameraToUse.OrthogonalWidth; if (lcs.Orthogonal && !cameraToUse.Orthogonal) { orthogonalWidthToUse = lcs.OrthogonalWidth; } // used for adjusting the ortho width/height if the Layer is zoomed float layerMultiplier = 1; float bottomDestination = lcs.BottomDestination; float topDestination = lcs.TopDestination; if (bottomDestination == -1 || topDestination == -1) { bottomDestination = cameraToUse.BottomDestination; topDestination = cameraToUse.TopDestination; } if (lcs.Orthogonal && bottomDestination != topDestination) { layerMultiplier = lcs.OrthogonalHeight / (float)(bottomDestination - topDestination); } float cameraMultiplier = 1; if (cameraToUse.Orthogonal && cameraToUse.BottomDestination != cameraToUse.TopDestination) { cameraMultiplier = cameraToUse.OrthogonalHeight / (float)(cameraToUse.BottomDestination - cameraToUse.TopDestination); } layerMultiplier /= cameraMultiplier; orthogonalWidthToUse *= layerMultiplier; // I think we want to use the Camera's orthogonalWidth if it's orthogonal //return GetWorldXGivenHorizontalPercentage(zPosition, cameraToUse, lcs.Orthogonal, lcs.OrthogonalWidth, horizontalPercentage); return(GetWorldXGivenHorizontalPercentage(zPosition, lcs.Orthogonal, orthogonalWidthToUse, horizontalPercentage)); } }