This commit is contained in:
anselme16 2015-01-15 17:43:04 +01:00
commit cb02ca1330

35
main.c
View File

@ -293,13 +293,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; i<screen->w; i++){
for(j=0; j<screen->h; 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));
}
@ -315,8 +327,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;
@ -354,6 +364,7 @@ int MAIN
x_offset = width/2;
y_offset = height/2;
printf("Launching simulation...\n");
time = SDL_GetTicks();
@ -411,19 +422,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;