Java-Gaming.org Hi !
 Featured games (88) games approved by the League of Dukes Games in Showcase (681) Games in Android Showcase (196) games submitted by our members Games in WIP (744) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 LWJGL camera zooming?  (Read 2151 times) 0 Members and 1 Guest are viewing this topic.
EliwoodL

Junior Devvie

Medals: 2
Exp: 5 years

 « Posted 2013-07-08 15:52:54 »

So I have a float value called zoom.  Zoom can be anywhere between 0.0125 and 1, with 1 being fully zoomed out, and 0.0125 being approximately 80 times zoomed in.

I'm attempting to change this value using the mouse scroll wheel, but I'm not sure how I would want to get a smooth zoom.  Would I repeatedly add (0.0125 * scroll wheel change) to the zoom value?

Or would I perhaps multiply zoom by something like 1.05?

Essentially, the question is, how would I go about creating a smooth zooming "range"?
PaidGEEK

Senior Devvie

Medals: 5
Projects: 3

 « Reply #1 - Posted 2013-07-08 16:07:59 »

Simple linear interpolation should do the trick:
 1  2  3  4  5  6  7 `int wheel = Mouse.getDWheel();if (wheel != 0) {   targetZoom += 0.05f * wheel;   targetZoom = clamp(targetZoom, 0.0125f, 1f); //clamp(x,min,max)}float t = 0.02f; //speedcamera.setZoom(camera.getZoom() + t * (targetZoom - camera.getZoom()));`

Improvisational programmer.
EliwoodL

Junior Devvie

Medals: 2
Exp: 5 years

 « Reply #2 - Posted 2013-07-08 16:25:04 »

Linear interpolation, huh?  I'll keep that in mind, thanks.

EDIT: nevermind, figured that one out.

However, my question now is:  Mouse.getDWheel() is returning an int of 120.  Is the 120 a universal value across all mouses, or do I need to create something to accomodate a change in that value?
PaidGEEK

Senior Devvie

Medals: 5
Projects: 3

 « Reply #3 - Posted 2013-07-08 16:39:16 »

Mouse.getDWheel() should return negative, 0 or positive number. So just change that to -1, 0 or 1 using IF's.

Improvisational programmer.
EliwoodL

Junior Devvie

Medals: 2
Exp: 5 years

 « Reply #4 - Posted 2013-07-08 18:13:01 »

Aha, yeah, I figured something like that would be needed.  Thanks for the help, though!  It really did help a lot.
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 CopyableCougar4 (25 views) 2016-06-25 16:56:52 Hydroque (59 views) 2016-06-22 02:17:53 SwampChicken (62 views) 2016-06-20 13:22:57 SwampChicken (62 views) 2016-06-20 13:22:49 SwampChicken (58 views) 2016-06-20 13:22:26 Hydroque (101 views) 2016-06-15 08:22:50 Hydroque (94 views) 2016-06-13 06:40:55 DarkCart (217 views) 2016-05-29 02:30:33 Hydroque (176 views) 2016-05-26 14:45:46 Mac70 (176 views) 2016-05-24 21:16:33
 Spasi 49x theagentd 44x NegativeZero 39x KaiHH 30x LiquidNitrogen 23x princec 23x kingroka123 15x ags1 15x CoDi^R 13x ra4king 12x Opiop 10x Hydroque 9x purenickery 9x Archive 8x czak 7x DarkCart 7x
 Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42FPS Camera Tutorialby Hydroque2016-05-22 05:40:58Website offering 3D Models specifically for games for freeby vusman2016-05-18 17:23:09Website offering 3D Models specifically for games for freeby vusman2016-05-09 08:50:56Website offering 3D Models specifically for games for freeby vusman2016-05-06 11:10:21Website offering 3D Models specifically for games for freeby vusman2016-04-29 12:56:17
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org