📄 hw_main.c
字号:
tr_y = *cz - gr_viewy;// *cy = *cy; // rotation around vertical y axis *cz = (tr_x * gr_viewcos) + (tr_y * gr_viewsin ); *cx = (tr_x * gr_viewsin) - (tr_y * gr_viewcos ); //look up/down ----TOTAL SUCKS!!!--- do the 2 in one!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! tr_y = *cy; tr_x = *cz; *cy = (tr_x * gr_viewludcos) + (tr_y * gr_viewludsin ); *cz = (tr_x * gr_viewludsin) - (tr_y * gr_viewludcos ); //scale y before frustum so that frustum can be scaled to screen height *cy *= ORIGINAL_ASPECT;#endif}static int HWR_TranstableToAlpha(int transtablenum, FSurfaceInfo *pSurf){ switch(transtablenum) { case tr_transmed : pSurf->FlatColor.s.alpha = 0x80;return PF_Translucent; case tr_transmor : pSurf->FlatColor.s.alpha = 0x40;return PF_Translucent; case tr_transhi : pSurf->FlatColor.s.alpha = 0x30;return PF_Translucent; case tr_transfir : pSurf->FlatColor.s.alpha = 0x80;return PF_Additive; case tr_transfx1 : pSurf->FlatColor.s.alpha = 0xff;return PF_Translucent; } return PF_Translucent;}// v1,v2 : the start & end vertices along the original wall segment, that may have been// clipped so that only a visible portion of the wall seg is drawn.// floorheight, ceilingheight : depend on wall upper/lower/middle, comes from the sectors.// -----------------+// HWR_ProjectWall :// -----------------+/* wallVerts order is : 3--2 | /| |/ | 0--1*/void HWR_ProjectWall( wallVert3D * wallVerts, FSurfaceInfo * pSurf, int blendmode){ FOutVector trVerts[4]; int i; FOutVector *wv;#ifndef TANDL float tr_x,tr_y;#endif //Hurdler: added for correct dynamic ligting with mlook FVector wlVerts[4]; // shouldn't be necessary with new T&L code // transform wv = trVerts;#ifndef TANDL for (i=0; i<4; i++,wv++, wallVerts++) { // translation tr_x = wallVerts->x - gr_viewx; tr_y = wallVerts->z - gr_viewy; wv->y = wallVerts->y - gr_viewz; // rotation around vertical y axis wv->oow = (tr_x * gr_viewcos) + (tr_y * gr_viewsin ); wv->x = (tr_x * gr_viewsin) - (tr_y * gr_viewcos ); //Hurdler: added for correct dynamic ligting with mlook wlVerts[i].x = wv->x; wlVerts[i].y = wv->y; wlVerts[i].z = wv->oow; //look up/down ----TOTAL SUCKS!!!--- do the 2 in one!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! tr_y = wv->y; tr_x = wv->oow; wv->y = (tr_x * gr_viewludcos) + (tr_y * gr_viewludsin ); wv->oow = (tr_x * gr_viewludsin) - (tr_y * gr_viewludcos ); //scale y before frustum so that frustum can be scaled to screen height wv->y = wv->y * ORIGINAL_ASPECT; wv->sow = wallVerts->s; wv->tow = wallVerts->t; }#else // it sounds really stupid to do this conversion with the new T&L code // we should directly put the right information in the right structure // wallVerts3D seems ok, doesn't need FOutVector // also remove the light copy for (i=0; i<4; i++, wv++, wallVerts++) { wv->sow = wallVerts->s; wv->tow = wallVerts->t; wv->x = wallVerts->x; wv->y = wallVerts->y; wv->oow = wallVerts->z; wlVerts[i].x = wv->x; wlVerts[i].y = wv->y; wlVerts[i].z = wv->oow; }#endif HWD.pfnDrawPolygon( pSurf, trVerts, 4, blendmode|PF_Modulated|PF_Occlude|PF_Clip); if (gr_curline->linedef->splats && cv_splats.value) HWR_DrawSegsSplats( pSurf );#ifdef TANDL //Hurdler: do static lighting using gr_curline->lm#else HWR_WallLighting(trVerts, wlVerts);#endif}// ==========================================================================// BSP , CULL, ETC..// ==========================================================================// return the frac from the interception of the clipping line// (in fact a clipping plane that has a constant, so can clip with simple 2d)// with the wall segment//static float HWR_ClipViewSegment (int x, polyvertex_t* v1, polyvertex_t* v2){ float num; float den; float v1x; float v1y; float v1dx; float v1dy; float v2dx; float v2dy; angle_t clipangle=gr_xtoviewangle[x]; // a segment of a polygon v1x = v1->x; v1y = v1->y; v1dx = (v2->x - v1->x ); v1dy = (v2->y - v1->y ); // the clipping line clipangle = clipangle + dup_viewangle; //back to normal angle (non-relative) v2dx = (float)finecosine[clipangle>>ANGLETOFINESHIFT] * crapmul; v2dy = (float)finesine[clipangle>>ANGLETOFINESHIFT] * crapmul; den = v2dy*v1dx - v2dx*v1dy; if (den == 0) return -1; // parallel // calc the frac along the polygon segment, //num = (v2x - v1x)*v2dy + (v1y - v2y)*v2dx; //num = -v1x * v2dy + v1y * v2dx; num = (gr_viewx - v1x)*v2dy + (v1y - gr_viewy)*v2dx; return num / den;}//// HWR_StoreWallRange// A portion or all of a wall segment will be drawn, from startfrac to endfrac,// where 0 is the start of the segment, 1 the end of the segment// Anything between means the wall segment has been clipped with solidsegs,// reducing wall overdraw to a minimum//static void HWR_StoreWallRange (int startfrac, int endfrac){ wallVert3D wallVerts[4]; v2d_t vs, ve; // start, end vertices of 2d line (view from above) fixed_t worldtop; fixed_t worldbottom; fixed_t worldhigh=0; fixed_t worldlow=0; GlideTexture_t* grTex; float cliplow,cliphigh; int gr_midtexture; fixed_t h, l; // 3D sides and 2s middle textures FSurfaceInfo Surf; if (startfrac>endfrac) return; gr_sidedef = gr_curline->sidedef; gr_linedef = gr_curline->linedef; // mark the segment as visible for auto map gr_linedef->flags |= ML_MAPPED; worldtop = gr_frontsector->ceilingheight; worldbottom = gr_frontsector->floorheight; vs.x = ((polyvertex_t *)gr_curline->v1)->x; vs.y = ((polyvertex_t *)gr_curline->v1)->y; ve.x = ((polyvertex_t *)gr_curline->v2)->x; ve.y = ((polyvertex_t *)gr_curline->v2)->y; // // clip the wall segment to solidsegs ///* BP : removed since there is no more clipwalls ! // clip start of segment if (startfrac > 0){ if (startfrac>1) {#ifdef PARANOIA CONS_Printf ("startfrac %f\n", startfrac );#endif startfrac = 1; } vs.x = vs.x + (ve.x - vs.x) * startfrac; vs.y = vs.y + (ve.y - vs.y) * startfrac; } // clip end of segment if (endfrac < 1){ if (endfrac<0) {#ifdef PARANOIA CONS_Printf (" endfrac %f\n", endfrac );#endif endfrac=0; } ve.x = vs.x + (ve.x - vs.x) * endfrac; ve.y = vs.y + (ve.y - vs.y) * endfrac; }*/ // remember vertices ordering // 3--2 // | /| // |/ | // 0--1 // make a wall polygon (with 2 triangles), using the floor/ceiling heights, // and the 2d map coords of start/end vertices wallVerts[0].x = wallVerts[3].x = vs.x; wallVerts[0].z = wallVerts[3].z = vs.y; wallVerts[2].x = wallVerts[1].x = ve.x; wallVerts[2].z = wallVerts[1].z = ve.y; wallVerts[0].w = wallVerts[1].w = wallVerts[2].w = wallVerts[3].w = 1.0f; if (drawtextured) { // x offset the texture fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset; // clip texture s start/end coords with solidsegs if (startfrac > 0 && startfrac < 1) cliplow = texturehpeg + gr_curline->length * startfrac; else cliplow = texturehpeg; if (endfrac > 0 && endfrac < 1) cliphigh = texturehpeg + gr_curline->length * endfrac; else cliphigh = texturehpeg + gr_curline->length; } // use different light tables // for horizontal / vertical / diagonal // note: try to get the same visual feel as the original Surf.FlatColor.s.alpha = 0xff; if(fixedcolormap) // TODO: better handling of fixedcolormap Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0xff; else { FUINT lightnum; lightnum = LightLevelToLum(gr_frontsector->lightlevel); if (((polyvertex_t *)gr_curline->v1)->y == ((polyvertex_t *)gr_curline->v2)->y && lightnum >= (255/LIGHTLEVELS) ) lightnum -= (255/LIGHTLEVELS ); else if (((polyvertex_t *)gr_curline->v1)->x == ((polyvertex_t *)gr_curline->v2)->x && lightnum < 255 - (255/LIGHTLEVELS) ) lightnum += (255/LIGHTLEVELS ); // store Surface->FlatColor to modulate wall texture Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = lightnum; } if (gr_backsector) { // two sided line worldhigh = gr_backsector->ceilingheight; worldlow = gr_backsector->floorheight; // hack to allow height changes in outdoor areas if (gr_frontsector->ceilingpic == skyflatnum && gr_backsector->ceilingpic == skyflatnum) { worldtop = worldhigh; } // check TOP TEXTURE if (worldhigh < worldtop && texturetranslation[gr_sidedef->toptexture]) { if (drawtextured) { fixed_t texturevpegtop; //top grTex = HWR_GetTexture ( texturetranslation[gr_sidedef->toptexture] ); // PEGGING if (gr_linedef->flags & ML_DONTPEGTOP) texturevpegtop = 0; else texturevpegtop = worldhigh + textureheight[gr_sidedef->toptexture] - worldtop; texturevpegtop += gr_sidedef->rowoffset; wallVerts[3].t = wallVerts[2].t = texturevpegtop * grTex->scaleY; wallVerts[0].t = wallVerts[1].t = (texturevpegtop + worldtop - worldhigh) * grTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; } // set top/bottom coords wallVerts[2].y = wallVerts[3].y = (float)worldtop * crapmul; wallVerts[0].y = wallVerts[1].y = (float)worldhigh * crapmul; HWR_ProjectWall( wallVerts, &Surf, PF_Masked ); } // check BOTTOM TEXTURE if (worldlow > worldbottom && texturetranslation[gr_sidedef->bottomtexture]) //only if VISIBLE!!! { if (drawtextured) { fixed_t texturevpegbottom=0; //bottom grTex = HWR_GetTexture ( texturetranslation[gr_sidedef->bottomtexture] ); // PEGGING if (gr_linedef->flags & ML_DONTPEGBOTTOM ) texturevpegbottom = worldtop - worldlow; else texturevpegbottom = 0; texturevpegbottom += gr_sidedef->rowoffset; wallVerts[3].t = wallVerts[2].t = texturevpegbottom * grTex->scaleY; wallVerts[0].t = wallVerts[1].t = (texturevpegbottom + worldlow - worldbottom) * grTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; } // set top/bottom coords wallVerts[2].y = wallVerts[3].y = (float)worldlow * crapmul; wallVerts[0].y = wallVerts[1].y = (float)worldbottom * crapmul; HWR_ProjectWall( wallVerts, &Surf, PF_Masked ); } gr_midtexture = texturetranslation[gr_sidedef->midtexture]; if (gr_midtexture) { int blendmode; fixed_t opentop, openbottom, polytop, polybottom; // SoM: a little note: This code re-arranging will // fix the bug in Nimrod map02. opentop and openbottom // record the limits the texture can be displayed in. // polytop and polybottom, are the ideal (i.e. unclipped) // heights of the polygon, and h & l, are the final (clipped) // poly coords. opentop = worldtop < worldhigh ? worldtop : worldhigh; openbottom = worldbottom > worldlow ? worldbottom : worldlow; if (gr_linedef->flags & ML_DONTPEGBOTTOM) { polybottom = openbottom + gr_sidedef->rowoffset; polytop = polybottom + textureheight[gr_midtexture]; } else { polytop = opentop + gr_sidedef->rowoffset; polybottom = polytop - textureheight[gr_midtexture]; } if ( (gr_frontsector->ceilingheight == gr_backsector->ceilingheight) || (gr_linedef->flags & ML_DONTDRAW) ) h = polytop; else h = polytop < opentop ? polytop : opentop; if ( (gr_frontsector->floorheight == gr_backsector->floorheight)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -