struct mesh * make_cylinder(int density, float radius, float height) { struct mesh *mesh; struct vertex *vtx; struct polygon *poly; int i, j; float a, da; mesh = mesh_make(); mesh->nvtx = 2*density; mesh->npoly = density; vtx = mesh->vtx = malloc(mesh->nvtx * sizeof *mesh->vtx); poly = mesh->poly = malloc(mesh->npoly * sizeof *mesh->poly); da = 2.*M_PI/density; for (a = 0., i = 0; i < density; i++, a += da) { init_coord(&vtx[i], radius, a, 0.f); init_coord(&vtx[i + density], radius, a, height); } for (i = 0; i < density; i++) { j = (i + 1)%density; init_quad(poly++, i, j, j + density, i + density); } return mesh; }
int intersect_shadow(float t, t_scene *scene, t_ray *ray) { t_vec3 intersect_pt; t_ray shadow; float t_tmp; intersect_pt.x = ray->o.x + t * ray->d.x; intersect_pt.y = ray->o.y + t * ray->d.y; intersect_pt.z = ray->o.z + t * ray->d.z; init_coord(&shadow.o, 0, 0, -30); init_vec3(&(shadow.d), shadow.o.x - intersect_pt.x, shadow.o.y - intersect_pt.y, shadow.o.z - intersect_pt.z); t_tmp = -1; while (scene != NULL) { if (scene->type == CIRCLE) t_tmp = intersect_circle(&shadow, scene->object); else if (scene->type == PLANE) t_tmp = intersect_plane(&shadow, scene->object); else if (scene->type == CYLINDER) t_tmp = intersect_cylinder(&shadow, scene->object); if (t_tmp > 0) { return (1); } scene = scene->next; } return (0); }
void init_scene(t_scene **scene) { t_coord coord; t_vec3 v; init_coord(&coord, 0, 0, -50); init_vec3(&v, 0, 0, 1); //init_plane(scene, coord, v, 0x0000FF); init_coord(&coord, 0, -3, 0); init_vec3(&v, 0, 1, 0); init_plane(scene, coord, v, 0x00FF66); init_coord(&coord, -5, 4, -21); init_circle(scene, coord, 0xFFFFFF, 4); init_coord(&coord, 0, 4, -21); init_circle(scene, coord, 0xFF0000, 2); init_coord(&coord, 5, 2, -25); init_vec3(&v, 0, 0, 1); init_cylinder(scene, coord, v, 2, 0x0000FF); init_coord(&coord, -10, -2, -25); init_vec3(&v, 0, 0, 1); init_cone(scene, coord, v, 0x00FFFF); }
void stock_coord(char *file_name, t_co *c) { int fd; char *line; int v; v = 0; line = NULL; init_coord(file_name, c); fd = open(file_name, O_RDONLY); c->coord->vert = (t_point **)malloc(sizeof(t_point *) * c->coord->to_pts); get_points(c, &fd, line, &v); close(fd); }
void init_light(t_light **light, t_vec3 center, float intensity) { t_light *new_light; new_light = (t_light *)malloc(sizeof(t_light)); if (new_light == NULL) { ft_putendl_fd("Fatal error : Failed malloc in init_light", 2); exit(-1); } init_coord(&(new_light->center), center.x, center.y, center.z); // init_vec3(&(new_light->direction), 0, 0, 1); // normalize(&(new_light->direction)); new_light->intensity = intensity; new_light->next = *light; *light = new_light; }
void init_circle(t_scene **scene, t_vec3 center, unsigned int color, float radius) { t_circle *circle; t_scene *new_obj; circle = (t_circle *)malloc(sizeof(t_circle)); new_obj = (t_scene *)malloc(sizeof(t_scene)); if (circle == NULL || new_obj == NULL) { ft_putendl_fd("Fatal error : Failed malloc in init_circle", 2); exit(-1); } init_coord(&circle->center, center.x, center.y, center.z); circle->r = radius; new_obj->type = CIRCLE; new_obj->object = circle; new_obj->color = color; new_obj->next = *scene; *scene = new_obj; }
void init_coord(Arbre A, double total, int rayon){ if(A == NULL) return; if(A -> pere == NULL){ A -> coord.x = TAILLE_FEN / 2; A -> coord.y = TAILLE_FEN / 2; total = 2 * M_PI; } POINT nv_origine; double phi; for(i = 0; i < nbEnf ; i++){ phi = i * total / A -> nbEnfants; // changement de repère nv_origine.x = cos(phi) * x - sin(phi) * y; nv_origine.y = sin(phi) * x + cos(phi) * y; A -> fils[i] -> coord = conversion(nv_origine, rayon, -(total/nbEnfants)/2); init_coord(A -> fils[i], phi, rayon); } }