Skip to content

Commit

Permalink
Add a switch that controls the movement in the demo
Browse files Browse the repository at this point in the history
See #9
  • Loading branch information
leonmavr committed Sep 22, 2023
1 parent 95bf2f5 commit 90db299
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
9 changes: 8 additions & 1 deletion include/arg_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ extern unsigned g_max_iterations;
extern char g_mesh_file[256];
// defines the max and min values of random rotation bias
extern float rand_min;
// random rotation biases - the higher, the faster the rotation around x, y,
// random rotation biases - the higher, the faster the rotation around x, y,
extern float random_bias_x;
extern float random_bias_y;
extern float random_bias_z;
extern bool render_from_file;
// controls whether the cube bounces around the screen
// 0 = keep the cube centered, N (!= 0) = change direction every N frames
extern unsigned g_bounce_every;
// how many pixels to move per frame along x, y, z axes
extern int g_move_x;
extern int g_move_y;
extern int g_move_z;

void arg_parse(int argc, char** argv);
14 changes: 8 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ int main(int argc, char** argv) {
for (size_t t = 0; t < g_max_iterations; ++t) {
if (g_use_random_rotation)
obj_mesh_rotate_to(shape, amplitude_x*sin(random_rot_speed_x*sin(random_rot_speed_x*t) + 2*random_bias_x),
amplitude_y*sin(random_rot_speed_y*random_bias_y*t + 2*random_bias_y),
amplitude_z*sin(random_rot_speed_z*random_bias_z*t + 2*random_bias_z));
amplitude_y*sin(random_rot_speed_y*random_bias_y*t + 2*random_bias_y),
amplitude_z*sin(random_rot_speed_z*random_bias_z*t + 2*random_bias_z));
else
obj_mesh_rotate_to(shape, g_rot_speed_x/20*t, g_rot_speed_y/20*t, g_rot_speed_z/20*t);
if ((t % 100) >= 50)
obj_mesh_translate_by(shape, 1, 1, 1);
else
obj_mesh_translate_by(shape, -1, -1, -1);
if (g_bounce_every != 0) {
if ((t % (2*g_bounce_every)) >= g_bounce_every)
obj_mesh_translate_by(shape, g_move_x, g_move_y, g_move_z);
else
obj_mesh_translate_by(shape, -g_move_x, -g_move_y, -g_move_z);
}
render_write_shape(shape);
render_flush();
#ifndef _WIN32
Expand Down
16 changes: 15 additions & 1 deletion src/arg_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ unsigned g_max_iterations = UINT_MAX;
char g_mesh_file[256] = {'\0'};
// defines the max and min values of random rotation bias
float rand_min = 0.75, rand_max = 2.25;
// random rotation biases - the higher, the faster the rotation around x, y,
// random rotation biases - the higher, the faster the rotation around x, y,
float random_bias_x = 0;
float random_bias_y = 0;
float random_bias_z = 0;
bool render_from_file = false;

unsigned g_bounce_every = 0;
// how many pixels to move per frame along x, y, z axes
int g_move_x = 2;
int g_move_y = 1;
int g_move_z = 1;


void arg_parse(int argc, char** argv) {
// initialise pseudo randomness generator for random rotations
Expand Down Expand Up @@ -84,6 +90,14 @@ void arg_parse(int argc, char** argv) {
i++;
strcpy(g_mesh_file, argv[i]);
render_from_file = true;
} else if ((strcmp(argv[i], "--bounce") == 0) || (strcmp(argv[i], "-b") == 0)) {
g_bounce_every = atoi(argv[++i]);
} else if ((strcmp(argv[i], "--movex") == 0) || (strcmp(argv[i], "-mx") == 0)) {
g_move_x = atoi(argv[++i]);
} else if ((strcmp(argv[i], "--movey") == 0) || (strcmp(argv[i], "-my") == 0)) {
g_move_y = atoi(argv[++i]);
} else if ((strcmp(argv[i], "--movez") == 0) || (strcmp(argv[i], "-mz") == 0)) {
g_move_z = atoi(argv[++i]);
} else {
printf("Uknown option: %s\n", argv[i++]);
}
Expand Down

0 comments on commit 90db299

Please sign in to comment.