public void PositionTo(PositionedObject positionedObject, float yOffset) { int screenX = 0; int screenY = 0; MathFunctions.AbsoluteToWindow(positionedObject.X, positionedObject.Y, positionedObject.Z, ref screenX, ref screenY, Camera.Main); var zoom = Managers.Renderer.Camera.Zoom; X = screenX / zoom; Y = yOffset + screenY / zoom; }
public void SetFromWorldUnits(float left, float right, float top, float bottom) { int leftScreen = 0; int topScreen = 0; int bottomScreen = 0; int rightScreen = 0; MathFunctions.AbsoluteToWindow(left, top, 0, ref leftScreen, ref topScreen, Camera.Main); MathFunctions.AbsoluteToWindow(right, bottom, 0, ref rightScreen, ref bottomScreen, Camera.Main); // we're 2x zoomed: leftScreen /= 2; topScreen /= 2; bottomScreen /= 2; rightScreen /= 2; VisualRepresentation.X = leftScreen; VisualRepresentation.Y = topScreen; VisualRepresentation.Width = rightScreen - leftScreen; VisualRepresentation.Height = bottomScreen - topScreen; }
public void VerifyGumOnFrbAttachments() { int screenX = 0; int screenY = 0; MathFunctions.AbsoluteToWindow(X, Y, Z, ref screenX, ref screenY, FlatRedBall.Camera.Main); EntireButton.Parent.ShouldNotBe(null, "because this should be attached to a wraper GUE"); EntireButton.Parent.X.ShouldBe(screenX, "because the EntireButton is attached to this, and should move with this"); EntireButton.Parent.Y.ShouldBe(screenY, "because the EntireButton is attached to this, and should move with this"); GumButtonOnFrbSprite.GetAbsoluteWidth().ShouldBe(100, "because this Gum object gets its width from its parent FRB object"); var gumButtonAsRenderableIpso = (RenderingLibrary.Graphics.IRenderableIpso)GumButtonCenteredOnSprite; var spriteLeftAbsolute = SpriteWidth100.Left; MathFunctions.AbsoluteToWindow(spriteLeftAbsolute, Y, Z, ref screenX, ref screenY, FlatRedBall.Camera.Main); gumButtonAsRenderableIpso.GetAbsoluteLeft().ShouldBe(screenX, "because the Gum object has its values set to be perfectly centered and sized by the Sprite"); }
public void WorldToLayerCoordinates(float worldX, float worldY, float worldZ, out float xOnLayer, out float yOnLayer) { xOnLayer = 0; yOnLayer = 0; int screenX = 0; int screenY = 0; MathFunctions.AbsoluteToWindow(worldX, worldY, worldZ, ref screenX, ref screenY, SpriteManager.Camera); if (this.LayerCameraSettings == null) { MathFunctions.WindowToAbsolute(screenX, screenY, ref xOnLayer, ref yOnLayer, worldZ, SpriteManager.Camera, Camera.CoordinateRelativity.RelativeToWorld); } else { float xEdge = 0; float yEdge = 0; if (LayerCameraSettings.Orthogonal) { xEdge = LayerCameraSettings.OrthogonalWidth / 2.0f; yEdge = LayerCameraSettings.OrthogonalHeight / 2.0f; } else { xEdge = (float)(100 * System.Math.Tan(LayerCameraSettings.FieldOfView / 2.0)); // Right now we just assume the same aspect ratio, but we may want the LayerCamerasettings // to have its own AspectRatio - if so, this needs to be modified yEdge = (float)(xEdge * SpriteManager.Camera.AspectRatio); } Rectangle destinationRectangle; if (LayerCameraSettings.LeftDestination > 0 && LayerCameraSettings.TopDestination > 0) { destinationRectangle = new Rectangle( MathFunctions.RoundToInt(LayerCameraSettings.LeftDestination), MathFunctions.RoundToInt(LayerCameraSettings.RightDestination), MathFunctions.RoundToInt(LayerCameraSettings.RightDestination - LayerCameraSettings.LeftDestination), MathFunctions.RoundToInt(LayerCameraSettings.BottomDestination - LayerCameraSettings.TopDestination)); } else { destinationRectangle = SpriteManager.Camera.DestinationRectangle; } if (LayerCameraSettings.Orthogonal) { Camera camera = SpriteManager.Camera; float top = camera.Y + LayerCameraSettings.OrthogonalHeight / 2.0f; float left = camera.X - LayerCameraSettings.OrthogonalWidth / 2.0f; float distanceFromLeft = LayerCameraSettings.OrthogonalWidth * screenX / (float)camera.DestinationRectangle.Width; float distanceFromTop = -LayerCameraSettings.OrthogonalHeight * screenY / (float)camera.DestinationRectangle.Height; xOnLayer = left + distanceFromLeft; yOnLayer = top + distanceFromTop; } else { MathFunctions.WindowToAbsolute(screenX, screenY, ref xOnLayer, ref yOnLayer, worldZ, SpriteManager.Camera.Position, xEdge, yEdge, destinationRectangle, Camera.CoordinateRelativity.RelativeToWorld); } } }