Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Zoom to New Centre

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 18th Aug 2013 19:24
Hi guy, I'm trying to work out how you zoom to the mouse position rather than the centre of the screen which once zoomed becomes the new centre point for zooming.

This is a old video of what I've been working on for keyframe animation, way more advanced now but as you can see in the vid, it zooms to the centre which is why I have to keep panning to where I want it.



Here's a quick example I made of the core zooming element:


"Get in the Van!" - Van B
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Aug 2013 19:25
The video is private.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 18th Aug 2013 19:32
Vid Fixed

"Get in the Van!" - Van B
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 18th Aug 2013 23:18
There are two ways of doing this I can think of, and I'm not sure which one you're going for.

The easier one would be to recenter the mouse and the camera whenever the user attempts to scroll. Find the position of the mouse and the camera center in your "world" (as opposed to on the screen), and move the camera by the difference between those two to recenter it. Then move the mouse to the screen center with position mouse.

The way you usually see in things like this is to just have the camera sort of "focus" on the mouse point when you zoom. I guess this would be considered "better", though I sometimes get confused by programs that work like this because I don't expect the location of the mouse cursor to affect the behavior of zooming (Photoshop, for example, doesn't do this and works just like the video you provided).

Anyway, to do that I though the most straightforward way would be to move the camera around based on the distance from the mouse to the camera center, and the relative zoom being made. Here's some code that does that, it ended up being rather more complicated than I expected, but hopefully it's applicable.


Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 19th Aug 2013 00:17 Edited at: 19th Aug 2013 00:18
wow looks amazing what you've done here..

im sure that DreamEditor's creator would be very intrested on this one

nice job man.

try taking it to a next level..
with curving the edges and magnetizing to a rounded numbers..

Stream SnifferTools/Plugins/Models/Games and more!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th Aug 2013 01:00
BMacZero, cheers and I'll try it out. What I find difficult and can't get my head round is panning the camera and changing the centre point of where it zooms to. I just can't combine the to, but I'll have a try with some of the ideas you have presented.

Quote: "nice job man."


Cheers man! That version is the mini version that is a tiny on demand bit of code that can be inserted into any code. Was gonna release it but then thought I want my engine to stand out so I didn't

Quote: "try taking it to a next level..
with curving the edges and magnetizing to a rounded numbers.."


Got a vid come out soon for my editor for my engine Scope showcasing keyframing! It will blow you guys away (I hope)! That vid is nearly a year old and I've been working on it since

"Get in the Van!" - Van B
Le Verdier
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 19th Aug 2013 01:52 Edited at: 20th Aug 2013 02:42
I think it is just an offset to add, considering the graph is still handled at the center
Here are my thoughts: (bold variables are vectors)

DeltaMouse = MousePos - ScreenCenter

The graph coords are
GraphCoordUnderMouse = GraphCoordAtCenter + DeltaMouse / Scale#

while zooming, GraphCoordUnderMouse would be also equals to:
GraphCoordUnderMouse = NewGraphCoordAtCenter + DeltaMouse / NewScale#

The wanted result is NewGraphCoordAtCenter so:
NewGraphCoordAtCenter = GraphCoordUnderMouse - DeltaMouse / NewScale#

...
This curve editor looks really cool!

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th Aug 2013 21:25
This is far more difficult than I imagined. Why it's hard is because:

1. The graph values need to be flipped so everything is position UP+Right ways rather than Down+Right ways. This messes up the calc for zoom to a new centre.

2. The graph isn't the whole screen, it's with in a rect.

These are the main issues I just can't get round which the given examples cheers Le Verdier and BMacZero don't really address.

"Get in the Van!" - Van B
Le Verdier
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 19th Aug 2013 21:56
I'll try to post a little example tomorow, it's something I've already done in my trackeditor program.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th Aug 2013 22:51
Cheers Le Verdier, I seeing your work, it's really great stuff

I'll keep going at it, this thing won't beat me!

"Get in the Van!" - Van B
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Aug 2013 23:10 Edited at: 19th Aug 2013 23:11
Hi Sasuke,

Let's assume there are maximums to how far out or in you can zoom. We'll say the farthest out is 1 and closest in is 100. At 1, this represents the entire graph or maximum screen pixels for the graph. At 100, it's the maximum pixels/100 .

At any level, the mouse has a relative position to level 1. The capture will always be from the relative position to the center of the display screen.

For example, if the the display is a level 20 zoom, then the capture is the pixel map from level1/20 starting from the pixel position the mouse is at a level 1. If the mouse is at 10,10 and level 1 pixel map is 1000,1000, the capture area is 10-(500/20) 10+(500/20) , 10-(500/20) 10+(500/20)

Capture these pixels and put them on the display starting at 0,0. You can handle the negative values by making them all black pixels or an empty grid.

Enjoy your day.
Le Verdier
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 20th Aug 2013 02:30 Edited at: 20th Aug 2013 02:38
Here is my little example:



Requires Advanced2d and a mousewheel...
RMB: Scroll graph
Mouse wheel: Zoom In/Out at the mouse location

Notice the X and Y coords are inverted...
The rect area is easyly modifiable

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 20th Aug 2013 14:47 Edited at: 20th Aug 2013 14:49
Le Verdier, with that code I was able to fix the Zooming functionality, thank you so much Now I can continue and get this thing working in my editor



I made something pretty fancy quick to show it working around a bunch of moving objects.

Requires Advanced2d and a mousewheel...
LMB: Scroll graph
Mouse wheel: Zoom In/Out at the mouse location



"Get in the Van!" - Van B
Le Verdier
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 20th Aug 2013 21:51

Nicely done..
Glad to see the the problem fixed


Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 23rd Aug 2013 10:17
Quote: "I think it is just an offset to add, considering the graph is still handled at the center
Here are my thoughts: (bold variables are vectors)..."

Having just read this thread I immediately thought this was the best type of approach. You find out how much x and y is needed to recenter, and you apply a fraction of this each time you scroll so the screen gradually re-centers.

This is similar to code I made to make characters look at the player when close. Find the correct final rotation and merely move at a fraction of that amount each time. Same principle.

Login to post a reply

Server time is: 2026-07-07 09:27:11
Your offset time is: 2026-07-07 09:27:11