/* ================ R_Alias_clip_z pfv0 is the unclipped vertex, pfv1 is the z-clipped vertex ================ */ void R_Alias_clip_z (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) { float scale; auxvert_t *pav0, *pav1, avout; pav0 = &av[pfv0 - &fv[0][0]]; pav1 = &av[pfv1 - &fv[0][0]]; if (pfv0->v[1] >= pfv1->v[1]) { scale = (ALIAS_Z_CLIP_PLANE - pav0->fv[2]) / (pav1->fv[2] - pav0->fv[2]); avout.fv[0] = pav0->fv[0] + (pav1->fv[0] - pav0->fv[0]) * scale; avout.fv[1] = pav0->fv[1] + (pav1->fv[1] - pav0->fv[1]) * scale; avout.fv[2] = ALIAS_Z_CLIP_PLANE; out->v[2] = pfv0->v[2] + (pfv1->v[2] - pfv0->v[2]) * scale; out->v[3] = pfv0->v[3] + (pfv1->v[3] - pfv0->v[3]) * scale; out->v[4] = pfv0->v[4] + (pfv1->v[4] - pfv0->v[4]) * scale; } else { scale = (ALIAS_Z_CLIP_PLANE - pav1->fv[2]) / (pav0->fv[2] - pav1->fv[2]); avout.fv[0] = pav1->fv[0] + (pav0->fv[0] - pav1->fv[0]) * scale; avout.fv[1] = pav1->fv[1] + (pav0->fv[1] - pav1->fv[1]) * scale; avout.fv[2] = ALIAS_Z_CLIP_PLANE; out->v[2] = pfv1->v[2] + (pfv0->v[2] - pfv1->v[2]) * scale; out->v[3] = pfv1->v[3] + (pfv0->v[3] - pfv1->v[3]) * scale; out->v[4] = pfv1->v[4] + (pfv0->v[4] - pfv1->v[4]) * scale; } R_AliasProjectFinalVert (out, &avout); if (out->v[0] < r_refdef.aliasvrect.x) out->flags |= ALIAS_LEFT_CLIP; if (out->v[1] < r_refdef.aliasvrect.y) out->flags |= ALIAS_TOP_CLIP; if (out->v[0] > r_refdef.aliasvrectright) out->flags |= ALIAS_RIGHT_CLIP; if (out->v[1] > r_refdef.aliasvrectbottom) out->flags |= ALIAS_BOTTOM_CLIP; }
void R_AliasClipAndProjectFinalVert (finalvert_t *fv, auxvert_t *av) { if (av->fv[2] < ALIAS_Z_CLIP_PLANE) { fv->flags |= ALIAS_Z_CLIP; return; } R_AliasProjectFinalVert (fv, av); if (fv->v[0] < r_refdef.aliasvrect.x) fv->flags |= ALIAS_LEFT_CLIP; if (fv->v[1] < r_refdef.aliasvrect.y) fv->flags |= ALIAS_TOP_CLIP; if (fv->v[0] > r_refdef.aliasvrectright) fv->flags |= ALIAS_RIGHT_CLIP; if (fv->v[1] > r_refdef.aliasvrectbottom) fv->flags |= ALIAS_BOTTOM_CLIP; }
/* ================ R_AliasPreparePoints General clipped case ================ */ void R_AliasPreparePoints(void) { int i; stvert_t *pstverts; finalvert_t *fv; auxvert_t *av; mtriangle_t *ptri; finalvert_t *pfv[3]; pstverts = (stvert_t *)((byte *)paliashdr + paliashdr->stverts); r_anumverts = pmdl->numverts; fv = pfinalverts; av = pauxverts; for (i=0 ; i<r_anumverts ; i++, fv++, av++, r_apverts++, pstverts++) { R_AliasTransformFinalVert(fv, av, r_apverts, pstverts); if (av->fv[2] < ALIAS_Z_CLIP_PLANE) { fv->flags |= ALIAS_Z_CLIP; } else { R_AliasProjectFinalVert(fv, av); if (fv->v[0] < r_refdef.aliasvrect.x) { fv->flags |= ALIAS_LEFT_CLIP; } if (fv->v[1] < r_refdef.aliasvrect.y) { fv->flags |= ALIAS_TOP_CLIP; } if (fv->v[0] > r_refdef.aliasvrectright) { fv->flags |= ALIAS_RIGHT_CLIP; } if (fv->v[1] > r_refdef.aliasvrectbottom) { fv->flags |= ALIAS_BOTTOM_CLIP; } } } // // clip and draw all triangles // r_affinetridesc.numtriangles = 1; ptri = (mtriangle_t *)((byte *)paliashdr + paliashdr->triangles); for (i=0 ; i<pmdl->numtris ; i++, ptri++) { pfv[0] = &pfinalverts[ptri->vertindex[0]]; pfv[1] = &pfinalverts[ptri->vertindex[1]]; pfv[2] = &pfinalverts[ptri->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 = ptri; D_PolysetDraw(); } else { // partially clipped R_AliasClipTriangle(ptri); } } }
/* ================ R_AliasPreparePoints General clipped case ================ */ static void R_AliasPreparePoints (void) { int i; stvert_t *pstverts; finalvert_t *fv; auxvert_t *av; mtriangle_t *ptri; finalvert_t *pfv[3]; pstverts = (stvert_t *)((byte *)paliashdr + paliashdr->stverts); r_anumverts = pmdl->numverts; fv = pfinalverts; av = pauxverts; for (i = 0 ; i < r_anumverts ; i++, fv++, av++, r_apverts++) { fv->flags = 0; R_AliasTransformFinalVert (fv, av, r_apverts); if (av->fv[2] < ALIAS_Z_CLIP_PLANE) fv->flags |= ALIAS_Z_CLIP; else { R_AliasProjectFinalVert (fv, av); if (fv->v[0] < r_refdef.aliasvrect.x) fv->flags |= ALIAS_LEFT_CLIP; if (fv->v[1] < r_refdef.aliasvrect.y) fv->flags |= ALIAS_TOP_CLIP; if (fv->v[0] > r_refdef.aliasvrectright) fv->flags |= ALIAS_RIGHT_CLIP; if (fv->v[1] > r_refdef.aliasvrectbottom) fv->flags |= ALIAS_BOTTOM_CLIP; } } // // clip and draw all triangles // r_affinetridesc.numtriangles = 1; ptri = (mtriangle_t *)((byte *)paliashdr + paliashdr->triangles); for (i = 0 ; i < pmdl->numtris ; i++, ptri++) { pfv[0] = &pfinalverts[ptri->vertindex[0]]; pfv[1] = &pfinalverts[ptri->vertindex[1]]; pfv[2] = &pfinalverts[ptri->vertindex[2]]; if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags & (ALIAS_XY_CLIP_MASK | ALIAS_Z_CLIP) ) continue; // completely clipped //jfm: fill in the triangles s and t into the finalvert pfv[0]->v[2] = pstverts[ptri->stindex[0]].s; pfv[0]->v[3] = pstverts[ptri->stindex[0]].t; pfv[0]->flags |= pstverts[ptri->stindex[0]].onseam; pfv[1]->v[2] = pstverts[ptri->stindex[1]].s; pfv[1]->v[3] = pstverts[ptri->stindex[1]].t; pfv[1]->flags |= pstverts[ptri->stindex[1]].onseam; pfv[2]->v[2] = pstverts[ptri->stindex[2]].s; pfv[2]->v[3] = pstverts[ptri->stindex[2]].t; pfv[2]->flags |= pstverts[ptri->stindex[2]].onseam; 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 = ptri; if ((currententity->model->flags & EF_SPECIAL_TRANS)) D_PolysetDrawT5 (); else if (currententity->drawflags & DRF_TRANSLUCENT) D_PolysetDrawT (); else if ((currententity->model->flags & EF_TRANSPARENT)) D_PolysetDrawT2 (); else if ((currententity->model->flags & EF_HOLEY)) D_PolysetDrawT3 (); else D_PolysetDraw (); } else { // partially clipped R_AliasClipTriangle (ptri); } } }