int search_coli(t_scene *scene, t_cam *cam, t_point *point) { int color; double k; t_object *tmp; t_object *tmp2; t_point *p; tmp2 = scene->obj; p = rotate(point, cam); k = search_k(scene, cam, p, &tmp); if (k <= 0.0) color = 0; else { if (tmp && search_attr(tmp->attr, COL_STR) != NULL) color = my_getnbr(search_attr(tmp->attr, COL_STR)); else color = COLOR; scene->obj = tmp2; color = calc_light(tmp, calc_vect(p), scene, k); } scene->obj = tmp2; return (color); }
static void R_IQMTransformAndProjectFinalVerts (iqm_t *iqm, swiqm_t *sw, iqmframe_t *frame) { finalvert_t *fv = pfinalverts; float zi; int i; for (i = 0; i < iqm->num_verts; i++, fv++) { byte *vert = iqm->vertices + i * iqm->stride; uint32_t bind = *(uint32_t *) (vert + sw->bindices->offset); vec_t *mat = (vec_t *) &frame[bind]; float *position = (float *) (vert + sw->position->offset); float *normal = (float *) (vert + sw->normal->offset); int32_t *texcoord = (int32_t *) (vert + sw->texcoord->offset); vec3_t tv, tn; Mat4MultVec (mat, position, tv); Mat4as3MultVec (mat, normal, tn); zi = 1.0 / (DotProduct (tv, aliastransform[2]) + aliastransform[2][3]); fv->v[5] = zi; fv->v[0] = (DotProduct (tv, aliastransform[0]) + aliastransform[0][3]) * zi + aliasxcenter; fv->v[1] = (DotProduct (tv, aliastransform[1]) + aliastransform[1][3]) * zi + aliasxcenter; fv->v[2] = texcoord[0]; fv->v[3] = texcoord[1]; fv->v[4] = calc_light (tn); } }
static void R_IQMPreparePoints (iqm_t *iqm, swiqm_t *sw, iqmframe_t *frame) { finalvert_t *fv = pfinalverts; auxvert_t *av = pauxverts; int i; uint32_t j; finalvert_t *pfv[3]; for (i = 0; i < iqm->num_verts; i++, fv++, av++) { byte *vert = iqm->vertices + i * iqm->stride; uint32_t bind = *(uint32_t *) (vert + sw->bindices->offset); vec_t *mat = (vec_t *) &frame[bind]; float *position = (float *) (vert + sw->position->offset); float *normal = (float *) (vert + sw->normal->offset); int32_t *texcoord = (int32_t *) (vert + sw->texcoord->offset); vec3_t tv, tn; Mat4MultVec (mat, position, tv); Mat4as3MultVec (mat, normal, tn); av->fv[0] = DotProduct (tv, aliastransform[0]) + aliastransform[0][3]; av->fv[1] = DotProduct (tv, aliastransform[1]) + aliastransform[1][3]; av->fv[2] = DotProduct (tv, aliastransform[2]) + aliastransform[2][3]; fv->v[2] = texcoord[0]; fv->v[3] = texcoord[1]; fv->flags = 0; fv->v[4] = calc_light (tn); R_AliasClipAndProjectFinalVert (fv, av); } for (i = 0; i < iqm->num_meshes; i++) { iqmmesh *mesh = &iqm->meshes[i]; mtriangle_t *mtri; iqm_setup_skin (sw, i); mtri = (mtriangle_t *) iqm->elements + mesh->first_triangle; r_affinetridesc.numtriangles = 1; for (j = 0; j < mesh->num_triangles; j++, mtri++) { pfv[0] = &pfinalverts[mtri->vertindex[0]]; pfv[1] = &pfinalverts[mtri->vertindex[1]]; pfv[2] = &pfinalverts[mtri->vertindex[2]]; if (pfv[0]->flags & pfv[1]->flags & pfv[2]->flags & (ALIAS_XY_CLIP_MASK | ALIAS_Z_CLIP)) continue; // completely clipped if (!((pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) & (ALIAS_XY_CLIP_MASK | ALIAS_Z_CLIP))) {// totally unclipped r_affinetridesc.pfinalverts = pfinalverts; r_affinetridesc.ptriangles = mtri; D_PolysetDraw (); } else { // partially clipped R_AliasClipTriangle (mtri); } } } }
// draw a circle on the specific y GLvoid DrawCurve(float y) { float direction0[4], direction1[4], direction2[4]; float ambient0[4], ambient1[4], ambient2[4]; float diffuse0[4], diffuse1[4], diffuse2[4]; float specular0[4], specular1[4], specular2[4]; glGetLightfv(GL_LIGHT0, GL_POSITION, direction0); glGetLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); glGetLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); glGetLightfv(GL_LIGHT0, GL_SPECULAR, specular0); glGetLightfv(GL_LIGHT1, GL_POSITION, direction1); glGetLightfv(GL_LIGHT1, GL_AMBIENT, ambient1); glGetLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1); glGetLightfv(GL_LIGHT1, GL_SPECULAR, specular1); glGetLightfv(GL_LIGHT2, GL_POSITION, direction2); glGetLightfv(GL_LIGHT2, GL_AMBIENT, ambient2); glGetLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse2); glGetLightfv(GL_LIGHT2, GL_SPECULAR, specular2); normalize_vector(direction0); normalize_vector(direction1); normalize_vector(direction2); //printf("diffuse0: %03f, %03f, %03f\n", diffuse0[0], diffuse0[1], diffuse0[2]); glBegin(GL_POLYGON); for (int i = 0; i < POINTNUM; i++) { float normal[] = {curve[i].x, CYLINDER_Y+y, curve[i].z-CYLINDER_Z}; float color0[3] = {0, 0, 0}, color1[3] = {0, 0, 0}, color2[3] = {0, 0, 0}; calc_light(curve[i], normal, direction0, ambient0, diffuse0, specular0, color0); calc_light(curve[i], normal, direction1, ambient1, diffuse1, specular1, color1); calc_light(curve[i], normal, direction2, ambient2, diffuse2, specular2, color2); float color[3] = {0, 0, 0}; vector_add_vector(color, color0, color); vector_add_vector(color, color1, color); vector_add_vector(color, color2, color); vector_multiply_num(color, 0.333f, color); glColor3fv(color); glVertex3f(curve[i].x, CYLINDER_Y+y, curve[i].z); } glEnd(); }