Since github is secure against code contributions I figured I would place this here. At least I can find it later.
These are new zoom functions for the MonoGame.Extended OrthographicCamera class
public void ZoomIn(float deltaZoom, Vector2 zoomCenter)
{
float pastZoom = Zoom;
ClampZoom(Zoom + deltaZoom);
Position += (zoomCenter - Origin - Position) * ((Zoom - pastZoom) / Zoom);
}
public void ZoomOut(float deltaZoom, Vector2 zoomCenter)
{
float pastZoom = Zoom;
ClampZoom(Zoom - deltaZoom);
Position += (zoomCenter - Origin - Position) * ((Zoom - pastZoom) / Zoom);
}
They can be called like this.
_worldPosition = _camera.ScreenToWorld(mouseState.Position.ToVector2());
// zoom targeting the mouse
int previousMouseWheelValue = currentMouseWheelValue;
currentMouseWheelValue = Mouse.GetState().ScrollWheelValue;
if (currentMouseWheelValue > previousMouseWheelValue)
{
_camera.ZoomIn(1 / 12f, _worldPosition);
}
if (currentMouseWheelValue < previousMouseWheelValue)
{
_camera.ZoomOut(1 / 12f, _worldPosition);
}