t_color compute_light(t_scene *scene, t_ray *ray) { t_list *current; t_ray lray; t_color color[3]; t_phpa ph; current = scene->lights; ph.normal = get_normal(*ray); set_ambiant_light(&ph, scene, ray, color); while (current) { lray.pos = ((t_light *)current->content)->pos; lray.dir = norm_vect(mtx_add(mtx_sub(mtx_mult(ray->dir, ray->t), lray.pos), ray->pos)); lray.invdir = get_inv_vect(&lray.dir); if (find_closest(scene, &lray) && ray->closest == lray.closest && near_enough(ray, &lray)) { set_params(&ph, &lray, ray); ph.camera = scene->camera; ph.light = (t_light *)current->content; phong(&ph); } current = current->next; } set_color_max(&ph); return (*color); }
t_obj *plane_data(t_obj *lst, char **tab, char *buf) { if (tab[0] == NULL || tab[1] == NULL || tab[2] == NULL || tab[3] == NULL || tab[4] == NULL || tab[5] == NULL || tab[6] == NULL || tab[7] == NULL || tab[8] == NULL) file_error("Parser error in scene file near : ", buf); lst->pos = new_vect(ft_atof(tab[0]), ft_atof(tab[1]), ft_atof(tab[2])); lst->nor = new_vect(ft_atof(tab[3]), ft_atof(tab[4]), ft_atof(tab[5])); norm_vect(lst->nor); lst->r = ft_atoi(tab[6]); lst->g = ft_atoi(tab[7]); lst->b = ft_atoi(tab[8]); return (lst); }
/* Gourandovo mapovani barev na objekt */ void group_gourand_maping(K_EDITOR * p_cnf, byte cop) { GLMATRIX *p_kw; int mod = p_cnf->mod; int os = p_cnf->bar.oboustrany_stinovac; int k, o, v, gr; float tx, ty, tz; float px, py, pz; float v1, v2, v3; float uhel; float r, g, b, a; float rr, rg, rb, ra; v1 = p_cnf->p_camera->_13; v2 = p_cnf->p_camera->_23; v3 = p_cnf->p_camera->_33; norm_vect(&v1, &v2, &v3); rr = p_cnf->bar.gr; rg = p_cnf->bar.gg; rb = p_cnf->bar.gb; ra = p_cnf->bar.ga; for (gr = 0; gr < p_cnf->groupnum; gr++) { k = p_cnf->p_group[gr].k; o = p_cnf->p_group[gr].o; v = p_cnf->p_group[gr].v; if (p_cnf->p_kont[k]->kflag & KONT_KEYFRAME) p_kw = &p_cnf->p_kont[k]->p_obj[o]->m; else p_kw = kont_world_matrix(p_cnf->p_kont[k]); px = p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].nx; py = p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].ny; pz = p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].nz; tx = p_kw->_11 * px + p_kw->_21 * py + p_kw->_31 * pz; ty = p_kw->_12 * px + p_kw->_22 * py + p_kw->_32 * pz; tz = p_kw->_13 * px + p_kw->_23 * py + p_kw->_33 * pz; norm_vect(&tx, &ty, &tz); uhel = (tx * v1 + ty * v2 + tz * v3); uhel = (p_cnf->bar.gourand_scale * (p_cnf->bar.gourand_pridat1 + uhel)) + p_cnf->bar.gourand_pridat2; // uhel je od 0 - 1 // //uhel += (rand()%1000)*0.0001f; if (os) { uhel = fabsf(uhel); r = (rr * uhel > 1.0f) ? 1.0f : rr * uhel; g = (rg * uhel > 1.0f) ? 1.0f : rg * uhel; b = (rb * uhel > 1.0f) ? 1.0f : rb * uhel; a = (ra * uhel > 1.0f) ? 1.0f : ra * uhel; } else { if (uhel > 0) { r = (rr * uhel > 1.0f) ? 1.0f : rr * uhel; g = (rg * uhel > 1.0f) ? 1.0f : rg * uhel; b = (rb * uhel > 1.0f) ? 1.0f : rb * uhel; a = (ra * uhel > 1.0f) ? 1.0f : ra * uhel; } else { r = g = b = a = 0; } } if (!p_cnf->bar.mod) { nastav_barvu_rgba(&p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].dr, r, g, b, a, cop); nastav_barvu_rgba(&p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].mdr, r, g, b, a, cop); } else { nastav_barvu_rgb(&p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].sr, r, g, b, cop); nastav_barvu_rgb(&p_cnf->p_kont[k]->p_obj[o]->p_vertex[v].msr, r, g, b, cop); } } }
/* Gourandovo mapovani barev na objekt */ void obj_gourand_maping(K_EDITOR * p_cnf, EDIT_KONTEJNER * p_kont, EDIT_OBJEKT * p_obj, byte cop) { GLMATRIX *p_kw; MUJ_BOD *p_bod; int mod = p_cnf->mod; int v; int os = p_cnf->bar.oboustrany_stinovac; float tx, ty, tz; float px, py, pz; float v1, v2, v3; float uhel; float r, g, b, a; float rr, rg, rb, ra; if (p_kont->kflag & KONT_KEYFRAME) p_kw = &p_obj->m; else p_kw = kont_world_matrix(p_kont); rr = p_cnf->bar.gr; rg = p_cnf->bar.gg; rb = p_cnf->bar.gb; ra = p_cnf->bar.ga; // z vektor pohledu v1 = p_cnf->p_camera->_13; v2 = p_cnf->p_camera->_23; v3 = p_cnf->p_camera->_33; norm_vect(&v1, &v2, &v3); p_bod = p_obj->p_vertex; for (v = 0; v < p_obj->vertexnum; v++) { px = p_bod[v].nx; py = p_bod[v].ny; pz = p_bod[v].nz; tx = p_kw->_11 * px + p_kw->_21 * py + p_kw->_31 * pz; ty = p_kw->_12 * px + p_kw->_22 * py + p_kw->_32 * pz; tz = p_kw->_13 * px + p_kw->_23 * py + p_kw->_33 * pz; norm_vect(&tx, &ty, &tz); uhel = tx * v1 + ty * v2 + tz * v3; uhel = (p_cnf->bar.gourand_scale * (p_cnf->bar.gourand_pridat1 + uhel)) + p_cnf->bar.gourand_pridat2; // uhel je od 0 - 1 // //uhel += (rand()%1000)*0.0001f; if (os) { uhel = fabsf(uhel); r = (rr * uhel > 1.0f) ? 1.0f : rr * uhel; g = (rg * uhel > 1.0f) ? 1.0f : rg * uhel; b = (rb * uhel > 1.0f) ? 1.0f : rb * uhel; a = (ra * uhel > 1.0f) ? 1.0f : ra * uhel; } else { if (uhel > 0) { r = (rr * uhel > 1.0f) ? 1.0f : rr * uhel; g = (rg * uhel > 1.0f) ? 1.0f : rg * uhel; b = (rb * uhel > 1.0f) ? 1.0f : rb * uhel; a = (ra * uhel > 1.0f) ? 1.0f : ra * uhel; } else { r = g = b = a = 0; } } if (!p_cnf->bar.mod) { nastav_barvu_rgba(&p_bod[v].dr, r, g, b, a, cop); nastav_barvu_rgba(&p_bod[v].mdr, r, g, b, a, cop); } else { nastav_barvu_rgb(&p_bod[v].sr, r, g, b, cop); nastav_barvu_rgb(&p_bod[v].msr, r, g, b, cop); } } }