2015-01-01 05:03:28 +00:00
|
|
|
/*
|
|
|
|
** polygons.c - <+DESC+>
|
|
|
|
**
|
|
|
|
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "game.h"
|
|
|
|
#include "polygons.h"
|
|
|
|
#include "obs.h"
|
|
|
|
#include "SDL_prims.h"
|
|
|
|
#include "SDL/SDL.h"
|
|
|
|
|
|
|
|
SDL_Point
|
2015-01-01 06:40:25 +00:00
|
|
|
get_hexagon_vertice(int faceno, int dist) { //{{{
|
2015-01-01 05:03:28 +00:00
|
|
|
SDL_Point p1;
|
|
|
|
|
|
|
|
p1.x = dist * cos((M_PI/3)*faceno);
|
|
|
|
p1.y = dist * sin((M_PI/3)*faceno);
|
|
|
|
|
|
|
|
OFFSET_POINT(p1);
|
|
|
|
|
|
|
|
return p1;
|
|
|
|
} //}}}
|
|
|
|
void
|
|
|
|
draw_hexagon_side(struct s_game *g, int faceno, int dist, int thick, int col) { //{{{
|
|
|
|
SDL_Point p1, p2, p3, p4;
|
|
|
|
|
2015-01-01 06:40:25 +00:00
|
|
|
p1 = get_hexagon_vertice(faceno, dist);
|
|
|
|
p2 = get_hexagon_vertice(faceno+1, dist);
|
|
|
|
p3 = get_hexagon_vertice(faceno+1, dist+thick);
|
|
|
|
p4 = get_hexagon_vertice(faceno, dist+thick);
|
2015-01-01 05:03:28 +00:00
|
|
|
|
2015-01-01 06:01:41 +00:00
|
|
|
SDL_Point points[4] = {to_screen_coords(g, p1),
|
|
|
|
to_screen_coords(g, p2),
|
|
|
|
to_screen_coords(g, p3),
|
|
|
|
to_screen_coords(g, p4)} ;
|
2015-01-01 05:03:28 +00:00
|
|
|
SDL_FillPolygon(g->screen, points, 4, col);
|
|
|
|
}//}}}
|
2015-01-01 12:12:40 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
} //}}}
|
|
|
|
void
|
|
|
|
draw_square_side(struct s_game *g, int faceno, int dist, int thick, int col) { //{{{
|
|
|
|
SDL_Point p1, p2, p3, p4;
|
|
|
|
|
|
|
|
p1 = get_square_vertice(faceno, dist);
|
|
|
|
p2 = get_square_vertice(faceno+1, dist);
|
|
|
|
p3 = get_square_vertice(faceno+1, dist+thick);
|
|
|
|
p4 = get_square_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);
|
|
|
|
}//}}}
|
|
|
|
|
|
|
|
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_triangle_side(struct s_game *g, int faceno, int dist, int thick, int col) { //{{{
|
|
|
|
SDL_Point p1, p2, p3, p4;
|
|
|
|
|
|
|
|
p1 = get_triangle_vertice(faceno, dist);
|
|
|
|
p2 = get_triangle_vertice(faceno+1, dist);
|
|
|
|
p3 = get_triangle_vertice(faceno+1, dist+thick);
|
|
|
|
p4 = get_triangle_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);
|
|
|
|
}//}}}
|
|
|
|
|
2015-01-01 05:03:28 +00:00
|
|
|
void
|
2015-01-01 05:19:10 +00:00
|
|
|
draw_polygon(struct s_game *g) { //{{{
|
2015-01-01 05:03:28 +00:00
|
|
|
int faces;
|
|
|
|
|
2015-01-01 05:19:10 +00:00
|
|
|
void (*drawer)(struct s_game *, int faceno, int dist, int thick, int col);
|
|
|
|
drawer = get_polygon_drawer(g);
|
|
|
|
|
2015-01-01 06:37:18 +00:00
|
|
|
for(faces = 0; faces < SHAPE_HEXAGON; faces++) {
|
|
|
|
drawer(g, faces, 0, POLYGON_SIZE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-01 05:03:28 +00:00
|
|
|
for(faces = 0; faces < SHAPE_HEXAGON; faces++) {
|
2015-01-01 10:40:34 +00:00
|
|
|
drawer(g, faces, POLYGON_SIZE, POLYGON_THICK, g->color);
|
2015-01-01 05:03:28 +00:00
|
|
|
}
|
|
|
|
} //}}}
|
|
|
|
|