void inter_cyl(t_params *params, t_3d *vc, t_objs *cyl) { double a; double b; double c; double delta; translation_obj(cyl, cyl->trans[0], cyl->trans[1], cyl->trans[2]); vc = rotate_ray(vc, cyl); a = (pow(vc->x, 2.0) + pow(vc->y, 2.0)); b = 2.0 * (vc->x * (params->pos_eye[0] - cyl->pos[0]) + vc->y * (params->pos_eye[1] - cyl->pos[1])); c = (pow(params->pos_eye[0], 2.0) + pow(params->pos_eye[1], 2.0) + (pow(cyl->pos[0], 2.0) + pow(cyl->pos[1], 2.0) - 2.0 * (cyl->pos[0] * params->pos_eye[0] + cyl->pos[1] * params->pos_eye[1]) - pow(cyl->ray, 2.0))); delta = pow(b, 2.0) - (4.0 * a * c); vc = unrotate_ray(vc, cyl); translation_obj(cyl, -cyl->trans[0], -cyl->trans[1], -cyl->trans[2]); if (delta < 0.0) cyl->intersection.k = 0.0; else if (delta == 0.0) cyl->intersection.k = (-b) / (2.0 * a); else sub_int_k(&(cyl->intersection), b, delta, a); }
static void move_light(t_data *d, const t_bunny_position *mpos) { t_acc vec; t_light *light; t_pos *pos; vec.z = 0; if (!d->itfc.obj_click || !d->itfc.light_selected) return ; if (!d->itfc.move.needmoving) { d->itfc.move.first_pos = *mpos; d->itfc.move.needmoving = true; } else { light = d->itfc.light_selected->datas; pos = &light->pos; d->itfc.move.second_pos = *mpos; vec.x = -((d->itfc.move.second_pos.x - d->itfc.move.first_pos.x) * 35); vec.y = -((d->itfc.move.second_pos.y - d->itfc.move.first_pos.y) * 35); translation_obj(&d->rt.rotation, &vec, &d->rt.eye.rot, pos); d->itfc.move.first_pos = d->itfc.move.second_pos; } }
void inter_plan(t_params *params, t_3d *vc, t_objs *pl) { double test; translation_obj(pl, pl->trans[0], pl->trans[1], pl->trans[2]); vc = rotate_ray(vc, pl); if (vc->x == 0.0 && vc->y == 0.0 && vc->z == 0.0) pl->intersection.k = 0.0; test = -(params->pos_eye[0] * pl->pos[0] + params->pos_eye[1] * pl->pos[1] + params->pos_eye[2] * pl->pos[2] + pl->ray) / (pl->pos[0] * vc->x + pl->pos[1] * vc->y + pl->pos[2] * vc->z); vc = unrotate_ray(vc, pl); translation_obj(pl, -pl->trans[0], -pl->trans[1], -pl->trans[2]); if (test < 0.0) pl->intersection.k = 0.0; else pl->intersection.k = test; }
void inter_sph(t_params *params, t_3d *vc, t_objs *sph) { double a; double b; double c; double delta; translation_obj(sph, sph->trans[0], sph->trans[1], sph->trans[2]); vc = rotate_ray(vc, sph); a = (pow(vc->x, 2.0) + pow(vc->y, 2.0) + pow(vc->z, 2.0)); b = 2.0 * (vc->x * (params->pos_eye[0] - sph->pos[0]) + vc->y * (params->pos_eye[1] - sph->pos[1]) + vc->z * (params->pos_eye[2] - sph->pos[2])); c = SUPERCALC; delta = pow(b, 2.0) - (4.0 * a * c); vc = unrotate_ray(vc, sph); translation_obj(sph, -sph->trans[0], -sph->trans[1], -sph->trans[2]); if (delta < 0.0) sph->intersection.k = 0.0; else if (delta == 0.0) sph->intersection.k = (-b) / (2.0 * a); else sub_int_k(&(sph->intersection), b, delta, a); }
void inter_cone(t_params *params, t_3d *vc, t_objs *cone) { double q; double a; double b; double c; double delta; translation_obj(cone, cone->trans[0], cone->trans[1], cone->trans[2]); vc = rotate_ray(vc, cone); q = tan(cone->ray * (M_PI / 180.0)); a = pow(vc->x, 2.0) + pow(vc->y, 2.0) - (q * pow(vc->z, 2.0)); b = SC_B; c = SC_C; delta = pow(b, 2.0) - (4.0 * a * c); vc = unrotate_ray(vc, cone); translation_obj(cone, -cone->trans[0], -cone->trans[1], -cone->trans[2]); if (delta < 0.0) cone->intersection.k = 0.0; else if (delta == 0.0) cone->intersection.k = (-b) / (2.0 * a); else sub_int_k(&(cone->intersection), b, delta, a); }