From 2a85123171d1ae42b79bfca6933d138ad7dc6322 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Thu, 15 Jan 2015 17:16:43 +0100 Subject: [PATCH] line duplication when zooming fixed --- main.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index fb3ecd8..6336a31 100755 --- a/main.c +++ b/main.c @@ -280,13 +280,25 @@ SDL_Surface* initSDL(int width, int height, int fullscreen) return screen; } +int screen_to_img(int pos_screen, int zoom ,int offset){ + return pos_screen/zoom + offset; +} + void render(SDL_Surface* screen, int x_offset, int y_offset, int zoom_level){ int i, j, x, y; + int pos_x,pos_y; + pos_x = x_offset - img->w/(2*zoom_level); + pos_y = y_offset - img->h/(2*zoom_level); SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); for(i=0; iw; i++){ for(j=0; jh; j++){ - x = (i - img->w/2)/zoom_level + x_offset; - y = (j - img->h/2)/zoom_level + y_offset; + //new version + x = screen_to_img(i,zoom_level,pos_x); + y = screen_to_img(j,zoom_level,pos_y); + + //old version + //x = (i - img->w/2 )/zoom_level + x_offset; + //y = (j - img->h/2 )/zoom_level + y_offset; if(x >= 0 && x < img->w && y >= 0 && y < img->h) putpixel(screen, i, j, getpixel(img, x, y)); } @@ -302,8 +314,6 @@ int MAIN int x_offset = 0; int y_offset = 0; int zoom_level = 1; - int seuil_x; // limit for x_offset - int seuil_y; // limit for y_offset int over = 0; int time = 0; int wait_time = 100; @@ -341,6 +351,7 @@ int MAIN x_offset = width/2; y_offset = height/2; + printf("Launching simulation...\n"); time = SDL_GetTicks(); @@ -398,19 +409,11 @@ int MAIN } } /* check x and y offset*/ - seuil_x = width/(2*zoom_level); - if (x_offset < seuil_x) x_offset=seuil_x; - - if (x_offset > width-seuil_x) x_offset=width-seuil_x; - - seuil_y = height/(2*zoom_level); - if (y_offset < seuil_y) y_offset=seuil_y; - - if(y_offset > height-seuil_y) y_offset=height-seuil_y; - - - /* */ + if (x_offset < 0) x_offset=0; + if (x_offset > width) x_offset=width; + if (y_offset < 0) y_offset=0; + if(y_offset > height) y_offset=height; new_time = SDL_GetTicks(); remaining_time -= new_time - time;