Camera functions to convert between world and screen coordinates
This commit is contained in:
@@ -28,6 +28,16 @@ namespace DepthsBelow
|
||||
Speed = 300;
|
||||
}
|
||||
|
||||
public Vector2 ScreenToWorld(Vector2 screenPos)
|
||||
{
|
||||
return Vector2.Transform(screenPos, Matrix.Invert(Transform));
|
||||
}
|
||||
|
||||
public Vector2 WorldToScreen(Vector2 worldPos)
|
||||
{
|
||||
return Vector2.Transform(worldPos, Transform);
|
||||
}
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
||||
@@ -48,7 +58,6 @@ namespace DepthsBelow
|
||||
Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0))
|
||||
* Matrix.CreateRotationZ(Rotation)
|
||||
* Matrix.CreateScale(Zoom)
|
||||
//* Matrix.CreateTranslation(new Vector3(
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,9 +68,10 @@ namespace DepthsBelow
|
||||
}
|
||||
|
||||
// Grid highlighting
|
||||
Point currentGrid = Grid.ScreenToGrid(new Vector2(ms.X + core.camera.Position.X, ms.Y + core.camera.Position.Y));
|
||||
Vector2 currentScreen = Grid.GridToScreen(currentGrid);
|
||||
gridRectangle = new Rectangle((int)currentScreen.X, (int)currentScreen.Y, Grid.TileSize, Grid.TileSize);
|
||||
Vector2 clickWorldPos = core.camera.ScreenToWorld(new Vector2(ms.X, ms.Y));
|
||||
Point clickGridPos = Grid.WorldToGrid(clickWorldPos);
|
||||
Vector2 rectWorldPos = Grid.GridToWorld(clickGridPos);
|
||||
gridRectangle = new Rectangle((int)rectWorldPos.X, (int)rectWorldPos.Y, Grid.TileSize, Grid.TileSize);
|
||||
|
||||
lastMouseState = ms;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user