Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Zoom around a Point  (Read 2481 times)
0 Members and 1 Guest are viewing this topic.
Offline Z-Knight

Junior Member





« Posted 2008-06-02 20:09:45 »

Hi, I'm trying to zoom an image around the current Mouse point (sort of like google craps...err, maps).  So when you have the mouse in the bottom right corner and zoom in (mouse wheel scroll up) it zooms around that point, but then you can move the mouse to the top left corner and continue to zoom in and it will zoom around the new point in the top left corner.  I have this working (in the attached code ... I guess you have to be logged in to see the code and image) but the problem I have is with zooming back out.  Unlike Google maps I don't want to zoom out past the boundary of the map - I want the map to remain in the view.  Right now, if you zoom in the bottom right corner and then move the mouse to the top left corner and start to zoom back out, eventually you will see the corner of the map but in reality I don't want to be able to zoom out past the map extents (...the code eventually snaps back but that's not a solution I want).

sorry for the poor code, but I tried a bunch of things like retrieving the rectangle that represents the current zoomed in portion of the map and using that to determine when to force the zoom to scale of 1.0, etc, etc....there must be a more elegant way to do this.  I don't want to use scroll bars and I don't want to zoom out and see the map edges.
Offline Z-Knight

Junior Member





« Reply #1 - Posted 2008-06-03 22:37:44 »

btw, I just found another example of what I'm trying to do...unfortunately this code doesn't limit the zoom out to remain within the bounds of the display/canvas but it does the same zoom in and out that I have (ie around a point).

It is a very cool example and completely functional:   http://today.java.net/pub/a/today/2007/03/27/navigable-image-panel.html
Offline Z-Knight

Junior Member





« Reply #2 - Posted 2008-06-09 16:57:04 »

so, no one zooms in on their scenes? 
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Z-Knight

Junior Member





« Reply #3 - Posted 2008-06-16 20:17:50 »

wow...this message board is quite, is there any better java2d boards where I can go ask questions?  I mean more active boards?
Offline Wildern

Junior Member





« Reply #4 - Posted 2008-06-18 17:35:34 »

This is the output from your program when the lower right corner of the map is visible with a white border.

 Screen 2D Point: 163 90
    Screen width: 824 height: 506
    Scale Factor: 0.9
    Scaled Point: 146.70000000000002 height: 81.0
    Scaled width: 741.6 height: 455.40000000000003
at: 2.6861527427269354 2.6861527427269354
CLICK> X: 163.0   Y: 90.0
1: 567 317 308 189
    clickX/getWidth()*rec.width   = 60.92718446601942
    clickY/getHeight()*rec.height = 33.616600790513836

You output the dimensions of your rec, with the width being 308, and the height being 189.
Both of those are less than your screen width and screen height.
I *think* that you need to detect the case where your rec.width is less than screen width and then move your map by the difference to force it to an edge, same would apply for rec.height being less than screen height.
You definitely want to move, and not force the scale to change as this condition could happen at a high zoom.
Offline Z-Knight

Junior Member





« Reply #5 - Posted 2008-06-19 20:38:27 »

Thanks for the response, Wildern.  I believe you are right that I need to detect when my width is less and I initially tried doing that and sort of do now and I then snap the map to the bounds of the screen/panel but I'm doing this poorly.  I've completely confused myself on this zooming and I'm having a hard time even explaining my problems so I'm glad you were able to see my problem and could contribute.  I need to review the link I provided in a previous post and I need to map this out on paper once again and then I can find a solution and post here or provide a better explanation for all of you to shoot holes through.

Initially I thought about doing a google maps kind of zoom, but they don't try to force the map within the panel bounds because as you zoom out you eventually zoom outside of the map and they also keep wrapping the image along the X axis which I don't want to do.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (70 views)
2013-05-17 21:29:12

alaslipknot (80 views)
2013-05-16 21:24:48

gouessej (111 views)
2013-05-16 00:53:38

gouessej (106 views)
2013-05-16 00:17:58

theagentd (117 views)
2013-05-15 15:01:13

theagentd (106 views)
2013-05-15 15:00:54

StreetDoggy (150 views)
2013-05-14 15:56:26

kutucuk (174 views)
2013-05-12 17:10:36

kutucuk (171 views)
2013-05-12 15:36:09

UnluckyDevil (180 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.114 seconds with 20 queries.