/* ** polygons.c - <+DESC+> ** ** 2014 - Frank Villaro-Dixon */ #include #include #include #include "game.h" #include "polygons.h" #include "obs.h" #include "SDL_prims.h" #include "SDL/SDL.h" SDL_Point get_hexagon_vertice(int faceno, int dist) { //{{{ SDL_Point p1; p1.x = dist * cos((M_PI/3)*faceno); p1.y = dist * sin((M_PI/3)*faceno); OFFSET_POINT(p1); return p1; } //}}} SDL_Point get_square_vertice(int faceno, int dist) { //{{{ SDL_Point p1; p1.x = dist * cos((M_PI/2)*faceno); p1.y = dist * sin((M_PI/2)*faceno); OFFSET_POINT(p1); return p1; } //}}} SDL_Point get_triangle_vertice(int faceno, int dist) { //{{{ SDL_Point p1; p1.x = dist * cos((2*M_PI/3)*faceno); p1.y = dist * sin((2*M_PI/3)*faceno); OFFSET_POINT(p1); return p1; } //}}} void draw_polygon_side(struct s_game *g, int faceno, int dist, int thick, int col) { //{{{ SDL_Point (*get_poly_vertice)(int faceno, int dist); SDL_Point p1, p2, p3, p4; /* Depending on the polygon */ switch(g->polygon_type) { case SHAPE_HEXAGON: get_poly_vertice = get_hexagon_vertice; break; case SHAPE_SQUARE: get_poly_vertice = get_square_vertice; break; case SHAPE_TRIANGLE: get_poly_vertice = get_triangle_vertice; break; default: fprintf(stderr, "Unknown SHAPE @ %s", __FILE__); exit(EXIT_FAILURE); } p1 = get_poly_vertice(faceno, dist); p2 = get_poly_vertice(faceno+1, dist); p3 = get_poly_vertice(faceno+1, dist+thick); p4 = get_poly_vertice(faceno, dist+thick); SDL_Point points[4] = {to_screen_coords(g, p1), to_screen_coords(g, p2), to_screen_coords(g, p3), to_screen_coords(g, p4)} ; SDL_FillPolygon(g->screen, points, 4, col); }//}}} void draw_polygon(struct s_game *g) { //{{{ int faces; for(faces = 0; faces < SHAPE_HEXAGON; faces++) { draw_polygon_side(g, faces, 0, POLYGON_SIZE, 0); } for(faces = 0; faces < SHAPE_HEXAGON; faces++) { draw_polygon_side(g, faces, POLYGON_SIZE, POLYGON_THICK, g->color); } } //}}}