mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-31 13:40:45 +00:00
Merge branch 'sw-culling-inaccuracy' into 'next'
Use double precision in R_StoreWallRange sloped seg culling calculations (Fixes #434) Closes #434 See merge request STJr/SRB2!1424
This commit is contained in:
commit
d97de6d3bd
1 changed files with 27 additions and 20 deletions
47
src/r_segs.c
47
src/r_segs.c
|
@ -1649,23 +1649,26 @@ void R_StoreWallRange(INT32 start, INT32 stop)
|
||||||
// left
|
// left
|
||||||
temp = xtoviewangle[start]+viewangle;
|
temp = xtoviewangle[start]+viewangle;
|
||||||
|
|
||||||
|
#define FIXED_TO_DOUBLE(x) (((double)(x)) / ((double)FRACUNIT))
|
||||||
|
#define DOUBLE_TO_FIXED(x) (fixed_t)((x) * ((double)FRACUNIT))
|
||||||
|
|
||||||
{
|
{
|
||||||
// Both lines can be written in slope-intercept form, so figure out line intersection
|
// Both lines can be written in slope-intercept form, so figure out line intersection
|
||||||
float a1, b1, c1, a2, b2, c2, det; // 1 is the seg, 2 is the view angle vector...
|
double a1, b1, c1, a2, b2, c2, det; // 1 is the seg, 2 is the view angle vector...
|
||||||
///TODO: convert to FPU
|
///TODO: convert to fixed point
|
||||||
|
|
||||||
a1 = FIXED_TO_FLOAT(curline->v2->y-curline->v1->y);
|
a1 = FIXED_TO_DOUBLE(curline->v2->y-curline->v1->y);
|
||||||
b1 = FIXED_TO_FLOAT(curline->v1->x-curline->v2->x);
|
b1 = FIXED_TO_DOUBLE(curline->v1->x-curline->v2->x);
|
||||||
c1 = a1*FIXED_TO_FLOAT(curline->v1->x) + b1*FIXED_TO_FLOAT(curline->v1->y);
|
c1 = a1*FIXED_TO_DOUBLE(curline->v1->x) + b1*FIXED_TO_DOUBLE(curline->v1->y);
|
||||||
|
|
||||||
a2 = -FIXED_TO_FLOAT(FINESINE(temp>>ANGLETOFINESHIFT));
|
a2 = -FIXED_TO_DOUBLE(FINESINE(temp>>ANGLETOFINESHIFT));
|
||||||
b2 = FIXED_TO_FLOAT(FINECOSINE(temp>>ANGLETOFINESHIFT));
|
b2 = FIXED_TO_DOUBLE(FINECOSINE(temp>>ANGLETOFINESHIFT));
|
||||||
c2 = a2*FIXED_TO_FLOAT(viewx) + b2*FIXED_TO_FLOAT(viewy);
|
c2 = a2*FIXED_TO_DOUBLE(viewx) + b2*FIXED_TO_DOUBLE(viewy);
|
||||||
|
|
||||||
det = a1*b2 - a2*b1;
|
det = a1*b2 - a2*b1;
|
||||||
|
|
||||||
ds_p->leftpos.x = segleft.x = FLOAT_TO_FIXED((b2*c1 - b1*c2)/det);
|
ds_p->leftpos.x = segleft.x = DOUBLE_TO_FIXED((b2*c1 - b1*c2)/det);
|
||||||
ds_p->leftpos.y = segleft.y = FLOAT_TO_FIXED((a1*c2 - a2*c1)/det);
|
ds_p->leftpos.y = segleft.y = DOUBLE_TO_FIXED((a1*c2 - a2*c1)/det);
|
||||||
}
|
}
|
||||||
|
|
||||||
// right
|
// right
|
||||||
|
@ -1673,22 +1676,26 @@ void R_StoreWallRange(INT32 start, INT32 stop)
|
||||||
|
|
||||||
{
|
{
|
||||||
// Both lines can be written in slope-intercept form, so figure out line intersection
|
// Both lines can be written in slope-intercept form, so figure out line intersection
|
||||||
float a1, b1, c1, a2, b2, c2, det; // 1 is the seg, 2 is the view angle vector...
|
double a1, b1, c1, a2, b2, c2, det; // 1 is the seg, 2 is the view angle vector...
|
||||||
///TODO: convert to FPU
|
///TODO: convert to fixed point
|
||||||
|
|
||||||
a1 = FIXED_TO_FLOAT(curline->v2->y-curline->v1->y);
|
a1 = FIXED_TO_DOUBLE(curline->v2->y-curline->v1->y);
|
||||||
b1 = FIXED_TO_FLOAT(curline->v1->x-curline->v2->x);
|
b1 = FIXED_TO_DOUBLE(curline->v1->x-curline->v2->x);
|
||||||
c1 = a1*FIXED_TO_FLOAT(curline->v1->x) + b1*FIXED_TO_FLOAT(curline->v1->y);
|
c1 = a1*FIXED_TO_DOUBLE(curline->v1->x) + b1*FIXED_TO_DOUBLE(curline->v1->y);
|
||||||
|
|
||||||
a2 = -FIXED_TO_FLOAT(FINESINE(temp>>ANGLETOFINESHIFT));
|
a2 = -FIXED_TO_DOUBLE(FINESINE(temp>>ANGLETOFINESHIFT));
|
||||||
b2 = FIXED_TO_FLOAT(FINECOSINE(temp>>ANGLETOFINESHIFT));
|
b2 = FIXED_TO_DOUBLE(FINECOSINE(temp>>ANGLETOFINESHIFT));
|
||||||
c2 = a2*FIXED_TO_FLOAT(viewx) + b2*FIXED_TO_FLOAT(viewy);
|
c2 = a2*FIXED_TO_DOUBLE(viewx) + b2*FIXED_TO_DOUBLE(viewy);
|
||||||
|
|
||||||
det = a1*b2 - a2*b1;
|
det = a1*b2 - a2*b1;
|
||||||
|
|
||||||
ds_p->rightpos.x = segright.x = FLOAT_TO_FIXED((b2*c1 - b1*c2)/det);
|
ds_p->rightpos.x = segright.x = DOUBLE_TO_FIXED((b2*c1 - b1*c2)/det);
|
||||||
ds_p->rightpos.y = segright.y = FLOAT_TO_FIXED((a1*c2 - a2*c1)/det);
|
ds_p->rightpos.y = segright.y = DOUBLE_TO_FIXED((a1*c2 - a2*c1)/det);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef FIXED_TO_DOUBLE
|
||||||
|
#undef DOUBLE_TO_FIXED
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue