view math?

Neptune

Member
If you have an angle, point_direction from the player (whose x, y is somewhere in the view) to the cursor (mouse_x, mouse_y) - perhaps 30 degrees.
Then zoom the view out, drawing more of the room - say +20% of the native view size.
What would be the math for the artificial mouse coordinates in the zoomed out state, that would maintain the original angle of 30 degrees on a point_direction check?

My brain is toast, so any help is really appreciated :)
 
In the begin step event of your control object:
GML:
global.imouse_x = mouse_x * viewZoomAmount

global.imouse_y = mouse_y * viewZoomAmount

Then just use global.imouse_x and global.imouse_y instead of mouse_x and mouse_y in all your code.
 

Neptune

Member
Is that really it? (1 + zoom) ...
I turned my brain into spaghetti over this.
I'll try that asap, thankyou!!
 
Well, I'm assuming you're setting your view's size with something like camera_set_view_size(mainCamera, defaultWidth * viewZoomAmount, defauleHeight * viewZoomAmount), in which case viewZoomAmount will be 0.9 to zoom in, or 1.2 to zoom out. You'd add 1 if you were instead doing defaultWidth * (defaultWidth * viewZoomAmount), where viewZoomAmount would be negative to zoom in.
 

Neptune

Member
Right, for me 0.9 would zoom in and 1.1 would zoom out.

When I zoom out, that angle from player to mouse shifts a bit, but I believe it's not a fixed amount.

Imagine the player is not in the middle of the screen before the zoom out - I think the shift amount depends on the starting position of the mouse, relative to the view horizontal and vertical center lines 🤔

If the player was indeed centered before the zoom out, I think there would be no angle change.
 
Last edited:

Neptune

Member

Ideally I would like to manually adjust the actual mouse coordinates during a zoom in/out, so that no angle shift happens.
I'm just finding it super confusing to think about for some reason...
 
Last edited:
RIght, what's happening is the view's position is changing, so while the mouse stays at the same screen coordinates its position relative to the scaled room changes. You'd still use global.imouse_x and global.imouse_y, but you wouldn't have their values be directly taken from mouse_x and mouse_y - you'd instead initialize them to mouse_x and mouse_y, then change them by however much mouse_x and mouse_y changed each step. Then when zooming, you'd keep track of the camera position as well, and additionally change them by how much the camera position changed each step. It'd look something like this:
GML:
//create event
prevMouseX = mouse_x
prevMouseY = mouse_y

prevCameraX = camera_get_view_x(mainCamera)
prevCameraY = camera_get_view_y(mainCamera)

//begin step

global.imouse_x += mouse_x - prevMouseX
global.imouse_y += mouse_y - prevMouseY

prevMouseX = mouse_x
prevMouseY = mouse_y

//end step

if zooming{
    global.imouse_x += camera_get_view_x(mainCamera) - prevCameraX
    global.imouse_y += camera_get_view_y(mainCamera) - prevCameraY
}

prevCameraX = camera_get_view_x(mainCamera)
prevCameraY = camera_get_view_y(mainCamera)
This would have the side effect of making it so the game cursor no longer follows the actual cursor, but it doesn't sound like that's a problem for you. Alternately you could just center zooms on the mouse position instead of the player object or camera center.
 

Neptune

Member
Thanks for the detailed reply.
I'm trying your approach, however I may just have to live with the bit of shift, opposed to changing other things.
Hmm having the game cursor not following the real cursor is not ideal either.

I would like to "set" the cursor position with window_mouse_set() to account for the shifts and maintain real mouse coordinates.
I think I would be setting the mouse to the artificial coordinates you created above, but the function is in respect to the display size and not mouse_x, mouse_y
o_O

[EDIT] Actually... Idk whats up, your way might work for me, but I'm not certain incrementing the view's x/y movement difference is the amount that is needed!
 
Last edited:
Top