added face rotation command-line switch.

This commit is contained in:
Antonio Carzaniga 2021-01-03 13:05:23 +01:00
parent 76bb057e6c
commit 6b59a065e4

14
balls.c
View File

@ -354,11 +354,12 @@ void draw_gravity_vector(cairo_t * cr) {
} }
const char * face_filename = 0; const char * face_filename = 0;
int face_rotation = 0;
static const double linear_rotation_unit = 2.0; static const double linear_rotation_unit = 2.0;
void init_ball_face(struct ball * b, cairo_surface_t * face) { void init_ball_face(struct ball * b, cairo_surface_t * face, int rotation) {
if (face) { if (face && rotation) {
b->rotation_steps = 2*M_PI * b->radius / linear_rotation_unit; b->rotation_steps = 2*M_PI * b->radius / linear_rotation_unit;
} else { } else {
b->rotation_steps = 1; b->rotation_steps = 1;
@ -402,7 +403,7 @@ void init_graphics() {
} }
} }
for(int i = 0; i < n_balls; ++i) for(int i = 0; i < n_balls; ++i)
init_ball_face(&(balls[i]), face_surface); init_ball_face(&(balls[i]), face_surface, face_rotation);
if (face_surface) if (face_surface)
cairo_surface_destroy (face_surface); cairo_surface_destroy (face_surface);
@ -510,7 +511,8 @@ void print_usage (const char * progname) {
"\tface=<filename>\n" "\tface=<filename>\n"
"\tclear=<clear-alpha>\n" "\tclear=<clear-alpha>\n"
"\tstats=<sample-count> :: rendering timing statitstics (0=disabled, default)\n" "\tstats=<sample-count> :: rendering timing statitstics (0=disabled, default)\n"
"\tcollisions=<C> :: n=no collisions, s=simple, i=index\n", "\tcollisions=<C> :: n=no collisions, s=simple, i=index\n"
"\t-r :: activate face rotation\n",
progname); progname);
} }
@ -586,6 +588,10 @@ int main (int argc, const char *argv[]) {
continue; continue;
} }
} }
if (strcmp(argv[i], "-r") == 0) {
face_rotation = 1;
continue;
}
print_usage(argv[0]); print_usage(argv[0]);
return 1; return 1;
} }