void *parse_light(const parsing_sect_t *section, t_scene *scene) { t_light *light; t_vec3 position; t_vec3 color; float intensity; vec3_set(&position, 0.f, 0.f, 0.f); if (section->option_count > 0) parse_vec3(section->options[0] + 1, &position); vec3_set(&color, 1.f, 1.f, 1.f); if (section->option_count > 1) parse_vec3(section->options[1] + 1, &color); intensity = 0.f; if (section->option_count > 2) intensity = atof(section->options[2][1]); light = create_light(&position, intensity, &color); lst_push_back(scene->lights, light); return (light); }
void *parse_sphere(const parsing_sect_t *section, t_scene *scene) { t_sphere *sphere; t_object *object; t_vec3 position; t_material *material; float radius; vec3_set(&position, 0, 0, 0); if (section->option_count > 0) parse_vec3(section->options[0] + 1, &position); radius = 0.f; if (section->option_count > 1) radius = atof(section->options[1][1]); material = NULL; if (section->option_count > 2) material = get_material(scene, section->options[2][1]); if (material == NULL) die("Unknown material."); sphere = create_sphere(&position, radius, material); object = create_object(section->name, SPHERE, sphere); lst_push_back(scene->objects, object); return (sphere); }
// the main function takes a single argument from the command line: the CSV file name int main(int argc, char **argv) { char line[MAX_LINE_SIZE]; struct vec3 data[MAX_VECTORS]; double vert[MAX_VECTORS]; double filtered[MAX_VECTORS]; int data_len = 0; if(argc < 2) { puts("No file provided."); return -1; } int fd = open(argv[1], O_RDONLY); // throw away the header line _getline(fd, line, sizeof(line)); // parse and load the vector data struct vec3 *ptr = data; while(_getline(fd, line, sizeof(line)) && data_len < MAX_VECTORS) { struct vec3 v = parse_vec3(line); //printf("x = %f, y = %f, z = %f\n", v.x, v.y, v.z); *ptr++ = v; data_len++; } printf("vectors read: %d\n", data_len); // calculate the gravity vector struct vec3 s = sum(data, data_len); double m = mag(s); //printf("mag = %f\n", m); struct vec3 g = scale(s, 1/m); printf("normalized gravity vector: %f %f %f\n", g.x, g.y, g.z); // reduce 3D data to 1D vertical acceleration for(int i = 0; i < data_len; i++) { vert[i] = dot(data[i], g); //printf("v = %f\n", vert[i]); } // bandpass filter 1-3 Hz filter(vert, data_len, filtered); //for(int i = 0; i < data_len; i++) printf("%f\n", filtered[i]); // calculate the thresholds double rms_val = rms(filtered, data_len); printf("rms: %f\n", rms_val); double threshold = rms_val * 0.5; // count the steps in the cleaned up signal int cnt = count_steps(filtered, data_len, threshold, -threshold); printf("cnt: %d\n", cnt); return 0; }
int parse_normal(const char **tokens) { t_vec3 *new_normal; if (!(new_normal = malloc(sizeof(t_vec3)))) return (0); else if (!parse_vec3(tokens, new_normal)) { free(new_normal); parser_die("A normal needs three arguments."); } lst_push_back(g_current_data->normals, new_normal); return (1); }