static void calculate_reflected(t_ray *a, t_ray *b) { t_vector n; t_point intersection; intersection.x = a->origin.x + a->direction.x * a->inter_t; intersection.y = a->origin.y + a->direction.y * a->inter_t; intersection.z = a->origin.z + a->direction.z * a->inter_t; if (a->closest->type == OBJ_SPHERE) { n.x = intersection.x - a->closest->origin.x; n.y = intersection.y - a->closest->origin.y; n.z = intersection.z - a->closest->origin.z; } else if (a->closest->type == OBJ_CYLINDER) get_cylinder_normal(&n, a->closest, &intersection); else if (a->closest->type == OBJ_CONE) get_cone_normal(&n, a->closest, &intersection); else n = a->closest->normal; b->origin = intersection; vect_scale(&a->direction, -1); b->direction.x = 2 * (vect_dot(&n, &a->direction)) * n.x - a->direction.x; b->direction.y = 2 * (vect_dot(&n, &a->direction)) * n.y - a->direction.y; b->direction.z = 2 * (vect_dot(&n, &a->direction)) * n.z - a->direction.z; normalize_vector(&b->direction); }
void set_val_cone(t_env *env, double t, t_ray *ray) { OBJ.new_start = vector_add(ray->start, vector_scale(t, ray->dir)); OBJ.normal = get_cone_normal(CONES[OBJ.cur_cone], OBJ.new_start); OBJ.cur_mat = env->obj.mats[CONES[OBJ.cur_cone].shape.material]; env->spec_coef = OBJ.cur_mat.specular; }
int get_normal(t_vec3 *normal, t_scene *obj, t_coord *point) { t_cone *circle; t_cone *plane; t_cone *cone; t_cylinder *cylinder; if (obj->type == CONE) { cone = obj->object; get_cone_normal(normal, cone, point); } else if (obj->type == CYLINDER) { cylinder = obj->object; get_cylinder_normal(normal, cylinder, point); } else if (obj->type == PLANE) { plane = obj->object; normal->x = plane->n.x; normal->y = plane->n.y; normal->z = plane->n.z; normalize(normal); } else if (obj->type == CIRCLE) { circle = obj->object; normal->x = point->x - circle->center.x; normal->y = point->y - circle->center.y; normal->z = point->z - circle->center.z; normalize(normal); } else return (1); return (0); }