private static Vector GetPositionOnScreen(ScreenView screen, MouseState state) { XnaV2 xnaPos = new XnaV2(state.X, state.Y); Vector pos = ScreenView.FromXnaCoords(xnaPos, screen.ViewportSize, Vector.Zero); return(pos.Transform(screen.GetScreenTransform())); }
/// <summary> /// Muuntaa annetun pisteen maailmankoordinaateista ruutukoordinaatteihin. /// </summary> public Vector WorldToScreen(Vector point) { Matrix4x4 transform = Matrix4x4.CreateTranslation(-new Vector(Position.X, Position.Y)) * Matrix4x4.CreateScale(new Vector(ZoomFactor, ZoomFactor)); return(point.Transform(transform)); }
private void SetPosition(Vector pos) { #if !WINRT && !WINDOWS_PHONE // Not supported on WinRT... only sets xna coords Vector screenpos = pos.Transform(screen.GetScreenInverse()); XnaV2 center = ScreenView.ToXnaCoords(screenpos, screen.ViewportSize, Vector.Zero); XnaMouse.SetPosition((int)center.X, (int)center.Y); #endif }
/// <summary> /// Muuntaa annetun pisteen maailmankoordinaateista ruutukoordinaatteihin /// ottaen huomioon oliokerroksen suhteellisen siirtymän. /// </summary> public Vector WorldToScreen(Vector point, Layer layer) { if (layer == null) { return(WorldToScreen(point)); } if (layer.IgnoresZoom) { return(point.Transform(Matrix4x4.CreateScale(new Vector(1, -1)) * Matrix4x4.CreateTranslation(new Vector(-Position.X * layer.RelativeTransition.X, Position.Y * layer.RelativeTransition.Y)) * Matrix4x4.CreateTranslation(new Vector(Game.Screen.Size.X / 2, Game.Screen.Size.Y / 2)))); } Matrix4x4 transform = Matrix4x4.CreateScale(new Vector(1, -1)) * Matrix4x4.CreateTranslation(new Vector(-Position.X * layer.RelativeTransition.X, Position.Y * layer.RelativeTransition.Y)) * Matrix4x4.CreateScale(new Vector(ZoomFactor, ZoomFactor)) * Matrix4x4.CreateTranslation(new Vector(Game.Screen.Size.X / 2, Game.Screen.Size.Y / 2)); return(point.Transform(transform)); }