What is the best way to restrict zooming of perspective camera in LibGDX? I have a planet in space and I need to zoom in/out it. Zooming works great, but I have to limit it to prevent the planet to be so close to the user and far away from him. Now, I'm using standart CameraInputController
to zoom in/out and restrict it by using the following code:
protected boolean pinchZoom (float amount) {
if(rho>25.f && rho<60.f){
return zoom(pinchZoomFactor * amount);
}
camera.update();
rho = calculateRho();
if(rho<=25.0){
while(rho<=25.0){
zoom(-.1f);
camera.update();
rho = calculateRho();
}
}
if(rho>=60){
while(rho>=60.0){
zoom(.1f);
camera.update();
rho = calculateRho();
}
}
}
private float calculateRho(){
return (float) Math.sqrt(Math.pow(camera.position.x, 2)+
Math.pow(camera.position.y, 2)+Math.pow(camera.position.z, 2));
}
Using this code my camera shakes sometimes a little bit. So, I find another way.