Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void zoom(float delta, float mouse_x, float mouse_y)
- {
- zoom += delta;
- view.w = window.w/zoom;
- view.h = window.h/zoom;
- // view.x = ???
- // view.y = ???
- }
- view.x = mouse_x - view.w/2;
- view.y = mouse_y - view.h/2;
- Vect2f mouse_true(mouse_position.x/zoom + view.x, mouse_position.y/zoom + view.y);
- Vect2f mouse_relative(window_size.x/mouse_pos.x, window_size.y/mouse_pos.y);
- view.x = mouse_true.x - view.w/mouse_relative.x;
- view.y = mouse_true.y - view.h/mouse_relative.y;
- var a = (mouse.x + camera.x) / zoom;
- // now increase the zoom e.g.: like that:
- zoom = zoom + 1;
- var newPosition = a * zoom - mouse.x;
- camera.setX(newPosition);
- screen.setWidth(originalWidth * zoom);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement