int get_sphere(t_obj *obj, char *line) { char **tab; t_sphere *sphere; if ((tab = ft_strsplit(line, ' ')) == NULL) { ft_printf("%rAllocation Fail: "); return (-1); } if (get_size_tab(tab) != 21) { ft_printf("%rThis line has no 21 param: "); return (-1); } if (!test_tab(tab, 20)) return (-1); if ((sphere = (t_sphere *)malloc(sizeof(t_sphere))) == NULL) ft_printf("%rAllocation fail: "); set_sphere(sphere, tab); sphere->color = get_color(tab[20]); if (sphere->color == NULL) return (-1); calc_matrix((void *)sphere, SPHERE); ft_lstadd(&(obj->sphere), ft_lstnew(sphere, sizeof(t_sphere))); return (0); }
void sphere_initial_position(vector_field field, spheres *s){ int i, j, k; for(k = 0; k < field.n_z; k++) for(j = 0; j < field.n_y; j++) for(i = 0; i < field.n_x; i++) set_sphere(s,i,j,k,-field.n_x/2+i*field.d_x,-field.n_y/2+j*field.d_y,-field.n_z/2+k*field.d_z); }
void geometry_t::init(const parameter_reader_t* const reader) { const std::string geom_type = reader->get_attribute("type"); // PRX_DEBUG_COLOR("MAKING GEOMETRY " << geom_type.c_str(), PRX_TEXT_CYAN); if (geom_type == "box") { const vector_t dims = reader->get_attribute_as<vector_t>("dims"); if (dims.get_dim() != 3) PRX_FATAL_S("Box must have three-dimensional dims attribute.") set_box(dims[0], dims[1], dims[2]); } else if (geom_type == "sphere") set_sphere(reader->get_attribute_as<double>("radius")); else if (geom_type == "cone") set_cone(reader->get_attribute_as<double>("radius"), reader->get_attribute_as<double>("height")); else if (geom_type == "cylinder") set_cylinder(reader->get_attribute_as<double>("radius"), reader->get_attribute_as<double>("height")); else if (geom_type == "open_cylinder") set_open_cylinder(reader->get_attribute_as<double>("radius"), reader->get_attribute_as<double>("height")); else if (geom_type == "capsule") set_capsule(reader->get_attribute_as<double>("radius"), reader->get_attribute_as<double>("height")); else if (geom_type == "mesh") set_mesh(reader->get_attribute_as<std::string>("filename")); else if (geom_type == "point_cloud") set_point_cloud(); else if (geom_type == "heightmap") set_heightmap(reader->get_attribute_as<std::string>("filename")); else if (geom_type == "polygon") { const std::vector< double > triangles = reader->get_attribute_as< std::vector<double> >("triangles"); set_polygon( triangles ); } else { const std::string trace = reader->trace(); PRX_FATAL_S("Unrecognized geometry type (" << geom_type.c_str() << ") in " << trace.c_str()); } if ( reader->has_attribute("scale")) { scale = reader->get_attribute_as<vector_t>("scale"); if (scale.get_dim() != 3) PRX_FATAL_S("Scale must have 3 elements at " << reader->trace() ); } else set_scale(1.0,1.0,1.0); if( reader->has_attribute("material" ) ) { std::string color_string = reader->get_attribute("material"); if( color_string == "yellow" ) { color[0] = 1; color[1] = 1; color[2] = 0; color[3] = 1.0; } else if( color_string == "blue" ) { color[0] = 0; color[1] = 0; color[2] = 1; color[3] = 1.0; } else if( color_string == "dark_grey" ) { color[0] = 0.25; color[1] = 0.25; color[2] = 0.25; color[3] = 1.0; } else if( color_string == "black" ) { color[0] = 0; color[1] = 0; color[2] = 0; color[3] = 1.0; } else if( color_string == "green" ) { color[0] = 0; color[1] = 1; color[2] = 0; color[3] = 1.0; } else if( color_string == "red" ) { color[0] = 1; color[1] = 0; color[2] = 0; color[3] = 1.0; } else if( color_string == "silver" ) { color[0] = 0.75; color[1] = 0.75; color[2] = 0.75; color[3] = 1.0; } else if( color_string == "cyan" ) { color[0] = 0.7; color[1] = 1; color[2] = 1; color[3] = 1.0; } else if( color_string == "orange" ) { color[0] = 1; color[1] = 0.6; color[2] = 0.05; color[3] = 1.0; } else if( color_string == "brown" ) { color[0] = 0.4; color[1] = 0.25; color[2] = 0.0; color[3] = 1.0;} else if( color_string == "glass" ) { color[0] = 0.5; color[1] = 0.5; color[2] = 0.55; color[3] = 0.18;} else { color[0] = 1; color[1] = 1; color[2] = 1; color[3] = 1.0; } } else { color[0] = 1; color[1] = 1; color[2] = 1; color[3] = 1.0; } }
void geometry_t::set_params( const std::vector<double>* params ) { switch (type) { case PRX_SPHERE: PRX_ASSERT(params->size() == 1); set_sphere((*params)[0]); break; case PRX_BOX: PRX_ASSERT(params->size() == 3); set_box((*params)[0], (*params)[1], (*params)[2]); break; case PRX_CONE: PRX_ASSERT(params->size() == 2); set_cone((*params)[0], (*params)[1]); break; case PRX_CYLINDER: PRX_ASSERT(params->size() == 2); set_cylinder((*params)[0], (*params)[1]); break; case PRX_OPEN_CYLINDER: PRX_ASSERT(params->size() == 2); set_open_cylinder((*params)[0], (*params)[1]); break; case PRX_CAPSULE: PRX_ASSERT(params->size() == 2); set_capsule((*params)[0], (*params)[1]); break; case PRX_LINES: // Must have at least two points. PRX_ASSERT(params->size() >= 6); // Must have three params per point. PRX_ASSERT(params->size() % 3 == 0); // Must have two points per line. PRX_ASSERT(params->size() % 6 == 0); this->type = type; info = *params; // Copy the info directly break; case PRX_LINESTRIP: // Must have at least two points. PRX_ASSERT(params->size() >= 6); // Must have three params per point. PRX_ASSERT(params->size() % 3 == 0); this->type = type; info = *params; // Copy the info directly break; case PRX_CLOUD: // Must have three params per point. PRX_ASSERT(params->size() % 3 == 0); info = *params; // Copy the info directly break; default: PRX_FATAL_S("Invalid geometry type: " << type); break; } }