I am currently developing a simple 2D map with terrain and other stuff, but I have encountered a problem relative to the zoom. In fact I can zoom in without any problem, but when I try to zoom out the zoom doesn't simply work and stays still.
int cellScale = 4;
int mapWidth, mapHeight;
int gridWidth, gridHeight;
map theMap;
float zoom, cameraX, cameraY;
void setup(){
size(800,800,P3D);
mapWidth = 1*width;
mapHeight = 1*height;
gridWidth = mapWidth/cellScale;
gridHeight = mapHeight/cellScale;
theMap = new map();
cameraX = width/2.0;
cameraY = height/2.0;
zoom = (height/2.0) / tan(PI*30.0/180.0);
}
void draw(){
theMap.display();
keyInput();
}
void keyInput(){
if(keyPressed){
if(keyCode == LEFT){
cameraX-=5;
}
if(keyCode == RIGHT){
cameraX+=5;
}
if(keyCode == UP){
cameraY-=5;
}
if(keyCode == DOWN){
cameraY+=5;
}
camera(cameraX, cameraY, zoom,
cameraX, cameraY, 0,
0,1,0);
}
}
void mouseWheel(MouseEvent event){
float e = event.getCount();
zoom = max(1.0, zoom + 10*e);
camera(cameraX, cameraY, zoom,
cameraX, cameraY, 0,
0,1,0);
}
I have noticed that after I do the zoom out with the mouse wheel, with the screen staying the same, when I zoom in I have to "re beat" the zooming out. I mean if I zoom out let's say 50, with always the screen that doesn't change, when I want to zoom in of 20 I have to zoom in of 70 because I have before zoomed out without succes of 50.