void calc_light(t_param *param, t_info *info, t_list *spot) { t_info *light; t_spot *o_spot; t_lum lum; int *s_color; if (info->distance < 0) return ; s_color = init_color(); while (spot) { o_spot = (t_spot *)spot->content; light = init_light(info, o_spot); calc_intersection(param, light); if (point_cmp(info->r_pos, light->r_pos) == 1) { lum.fading = ft_abs(calc_fading(light->r_line.vec, info->vec_n)); lum.shining = ft_abs(calc_shining(info->vec_n, light->r_line.vec)); info->light += o_spot->value * lum.fading; info->light += o_spot->value * lum.shining * lum.fading; calc_color(&s_color, o_spot->color, o_spot->value, lum.fading); } spot = spot->next; } info->color = retrieve_col(s_color, damer(param, info, info->s_pos), get_shine(info)); }
static int draw_background(struct objlist *obj, N_VALUE *inst, int GC, struct axis_pos *ax, struct axis_pos *ay) { int r, br, bg, bb, ba, pos[8]; _getobj(obj, "BR", inst, &br); _getobj(obj, "BG", inst, &bg); _getobj(obj, "BB", inst, &bb); _getobj(obj, "BA", inst, &ba); GRAcolor(GC, br, bg, bb, ba); r = calc_intersection(ax->x, ax->y, ay->dir, ay->x, ay->y, ax->dir, pos + 0, pos + 1); if (r) return 1; pos[2] = pos[0] + ax->len_x; pos[3] = pos[1] - ax->len_y; pos[4] = pos[2] + ay->len_x; pos[5] = pos[3] - ay->len_y; pos[6] = pos[0] + ay->len_x; pos[7] = pos[1] - ay->len_y; GRAdrawpoly(GC, 4, pos, GRA_FILL_MODE_EVEN_ODD); return 0; }
//------------------------------------------------------------------------ bool vcgen_contour::calc_miter(const vertex_dist& v0, const vertex_dist& v1, const vertex_dist& v2) { double dx1, dy1, dx2, dy2; dx1 = m_signed_width * (v1.y - v0.y) / v0.dist; dy1 = m_signed_width * (v1.x - v0.x) / v0.dist; dx2 = m_signed_width * (v2.y - v1.y) / v1.dist; dy2 = m_signed_width * (v2.x - v1.x) / v1.dist; double xi; double yi; if(!calc_intersection(v0.x + dx1, v0.y - dy1, v1.x + dx1, v1.y - dy1, v1.x + dx2, v1.y - dy2, v2.x + dx2, v2.y - dy2, &xi, &yi)) { m_x1 = v1.x + dx1; m_y1 = v1.y - dy1; return false; } else { double d1 = calc_distance(v1.x, v1.y, xi, yi); double lim = m_abs_width * m_miter_limit; if(d1 > lim) { d1 = lim / d1; m_x1 = v1.x + dx1; m_y1 = v1.y - dy1; m_x2 = v1.x + dx2; m_y2 = v1.y - dy2; m_x1 += (xi - m_x1) * d1; m_y1 += (yi - m_y1) * d1; m_x2 += (xi - m_x2) * d1; m_y2 += (yi - m_y2) * d1; return true; } else { m_x1 = xi; m_y1 = yi; } } return false; }
static int draw_grid_line(struct objlist *obj, int GC, struct axis_prm *a1_prm, struct axis_pos *a1_pos, struct axis_pos *a2_pos, struct grid_prm *gprm) { int r, rcode, snum, wid, *sdata; double po; int x0, y0, x, y; struct axislocal alocal; if (getaxispositionini(&alocal, a1_prm->type, a1_prm->amin, a1_prm->amax, a1_prm->inc, a1_prm->div, TRUE)) { error(obj, ERRMINMAX); return 1; } r = calc_intersection(a1_pos->x, a1_pos->y, a2_pos->dir, a2_pos->x, a2_pos->y, a1_pos->dir, &x, &y); if (r) { error(obj, ERRAXISDIR); return 1; } while ((rcode = getaxisposition(&alocal, &po)) != -2) { switch (rcode) { case 1: case 2: case 3: snum = gprm->snum[rcode - 1]; sdata = gprm->sdata[rcode - 1]; wid = gprm->wid[rcode - 1]; break; default: wid = 0; } if (wid == 0) continue; GRAlinestyle(GC, snum, sdata, wid, GRA_LINE_CAP_BUTT, GRA_LINE_JOIN_MITER, 1000); x0 = x + (po - a1_prm->min) * a1_pos->len_x / (a1_prm->max - a1_prm->min); y0 = y - (po - a1_prm->min) * a1_pos->len_y / (a1_prm->max - a1_prm->min); GRAline(GC, x0, y0, x0 + a2_pos->len_x, y0 - a2_pos->len_y); } return 0; }
//------------------------------------------------------------------------ void gen_stroke::calc_miter(const vertex_dist& v0, const vertex_dist& v1, const vertex_dist& v2, double dx1, double dy1, double dx2, double dy2) { double xi = v1.x; double yi = v1.y; if(!calc_intersection(v0.x + dx1, v0.y - dy1, v1.x + dx1, v1.y - dy1, v1.x + dx2, v1.y - dy2, v2.x + dx2, v2.y - dy2, &xi, &yi)) { m_out_vertices.add(coord_type(v1.x + dx1, v1.y - dy1)); } else { double d1 = calc_distance(v1.x, v1.y, xi, yi); double lim = m_width * m_miter_limit; if(d1 > lim) { d1 = lim / d1; double x1 = v1.x + dx1; double y1 = v1.y - dy1; double x2 = v1.x + dx2; double y2 = v1.y - dy2; x1 += (xi - x1) * d1; y1 += (yi - y1) * d1; x2 += (xi - x2) * d1; y2 += (yi - y2) * d1; m_out_vertices.add(coord_type(x1, y1)); m_out_vertices.add(coord_type(x2, y2)); } else { m_out_vertices.add(coord_type(xi, yi)); } } }