LWJGL camera zooming?

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”?

Simple linear interpolation should do the trick:


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; //speed
camera.setZoom(camera.getZoom() + t * (targetZoom - camera.getZoom()));

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?

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

Aha, yeah, I figured something like that would be needed. Thanks for the help, though! It really did help a lot.