mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-13 07:58:04 +00:00
new m32 aiming: changed the way distance is determined, so it also handles parallaxed sectors.
git-svn-id: https://svn.eduke32.com/eduke32@1464 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
8f0da12b76
commit
ce3d64d971
1 changed files with 161 additions and 143 deletions
|
@ -1919,13 +1919,15 @@ void polymer_alt_editorselect(void)
|
|||
GLdouble proj[16];
|
||||
GLint view[4];
|
||||
|
||||
GLdouble x,y,z, viewx,viewy,viewz;
|
||||
GLdouble x,y,z;
|
||||
GLdouble scrx,scry,scrz;
|
||||
GLfloat scr[3], scrv[3];
|
||||
GLfloat dadepth;
|
||||
|
||||
int8_t bestwhat = -1;
|
||||
int16_t bestsec = -1;
|
||||
int16_t bestwall = -1;
|
||||
GLfloat bestdist = 1000; //todo: tweak...
|
||||
GLfloat bestdist = FLT_MAX;
|
||||
|
||||
#ifdef M32_SHOWDEBUG
|
||||
GLfloat col1[3]={1.0,0.0,0.0};
|
||||
|
@ -1942,7 +1944,18 @@ void polymer_alt_editorselect(void)
|
|||
|
||||
bglReadPixels(searchx, ydimen-searchy, 1,1, GL_DEPTH_COMPONENT, GL_FLOAT, &dadepth);
|
||||
bgluUnProject(searchx, ydimen-searchy, dadepth, model, proj, view, &x, &y, &z);
|
||||
bgluUnProject(searchx, ydimen-searchy, 0.0, model, proj, view, &viewx, &viewy, &viewz);
|
||||
bgluUnProject(searchx, ydimen-searchy, 0.0, model, proj, view, &scrx, &scry, &scrz);
|
||||
|
||||
#ifdef M32_SHOWDEBUG
|
||||
if (m32_numdebuglines < 64)
|
||||
Bsprintf(m32_debugstr[m32_numdebuglines++], "x=%.02f, y=%.02f, z/16=%.02f (BUILD)", -z, x, -y);
|
||||
#endif
|
||||
|
||||
scr[0]=scrx, scr[1]=scry, scr[2]=scrz;
|
||||
|
||||
scrv[0] = x-scrx;
|
||||
scrv[1] = y-scry;
|
||||
scrv[2] = z-scrz;
|
||||
|
||||
for (i=0; i<numwalls; i++)
|
||||
{
|
||||
|
@ -1960,24 +1973,33 @@ void polymer_alt_editorselect(void)
|
|||
GLdouble a=pl[0], b=pl[1], c=pl[2], d=pl[3];
|
||||
GLdouble nnormsq = a*a + b*b + c*c;
|
||||
GLdouble nnorm = sqrt(nnormsq);
|
||||
GLdouble dist;
|
||||
GLfloat t, svcoeff, dist;
|
||||
|
||||
GLfloat npl[3] = {a/nnorm, b/nnorm, c/nnorm};
|
||||
GLfloat scrv[3] = {x-viewx, y-viewy, z-viewz};
|
||||
|
||||
dist = fabs(a*x + b*y + c*z + d)/nnorm;
|
||||
t = dot3f(pl,scrv);
|
||||
if (t==0)
|
||||
continue;
|
||||
|
||||
svcoeff = -(dot3f(pl,scr)+d)/t;
|
||||
if (svcoeff < 0)
|
||||
continue;
|
||||
|
||||
dist = svcoeff * sqrt(dot3f(scrv,scrv));
|
||||
if (dist > bestdist)
|
||||
continue;
|
||||
|
||||
// TODO: the parallax cases...
|
||||
for (what=(wal->nextsector>=0?2:0); what>=0; what--)
|
||||
{
|
||||
GLfloat v1[3], v2[3], v3[3], v4[3], v12[3], v34[3], v1p_r[3], v3p_r[3];
|
||||
GLfloat v23[3], v41[3], v2p_r[3], v4p_r[3];
|
||||
GLfloat tp[3]={x,y,z};
|
||||
GLfloat tp[3];
|
||||
_prplane *pp;
|
||||
|
||||
tp[0] = scrx + svcoeff*scrv[0];
|
||||
tp[1] = scry + svcoeff*scrv[1];
|
||||
tp[2] = scrz + svcoeff*scrv[2];
|
||||
|
||||
pp=wp;
|
||||
if (what==0)
|
||||
{
|
||||
|
@ -1997,7 +2019,7 @@ void polymer_alt_editorselect(void)
|
|||
pp=&w->mask;
|
||||
}
|
||||
|
||||
if (-dot3f(scrv,pl)<0 && !(what==2 && (wal->cstat&16)))
|
||||
if (-t<0 && !(what==2 && (wal->cstat&16)))
|
||||
goto nextwall;
|
||||
|
||||
Bmemcpy(v1, &pp->buffer[0], 3*sizeof(GLfloat));
|
||||
|
@ -2066,8 +2088,7 @@ nextwall:;
|
|||
for (what=1; what<=2; what++)
|
||||
{
|
||||
GLfloat *pl;
|
||||
GLdouble a, b, c, d;
|
||||
GLfloat scrv[3] = {x-viewx, y-viewy, z-viewz};
|
||||
GLfloat t, svcoeff, dist, p[2];
|
||||
|
||||
if (what==1)
|
||||
cfp = &s->ceil;
|
||||
|
@ -2076,32 +2097,21 @@ nextwall:;
|
|||
|
||||
pl = cfp->plane;
|
||||
|
||||
if (-dot3f(scrv,pl)<0)
|
||||
t = dot3f(pl,scrv);
|
||||
if (-t<=0)
|
||||
continue;
|
||||
|
||||
a=pl[0], b=pl[1], c=pl[2], d=pl[3];
|
||||
|
||||
{
|
||||
GLdouble nnormsq = a*a + b*b + c*c;
|
||||
GLdouble nnorm = sqrt(nnormsq);
|
||||
GLdouble dist = dist = fabs(a*x + b*y + c*z + d)/nnorm;
|
||||
svcoeff = -(dot3f(pl,scr)+pl[3])/t;
|
||||
if (svcoeff < 0)
|
||||
continue;
|
||||
|
||||
dist = svcoeff * sqrt(dot3f(scrv,scrv));
|
||||
if (dist > bestdist)
|
||||
continue;
|
||||
|
||||
{
|
||||
// projected point
|
||||
GLfloat p[2] =
|
||||
{
|
||||
//x,
|
||||
((b*b+c*c)*x - a*b*y - a*c*z - a*d)/nnormsq,
|
||||
|
||||
//y,
|
||||
//(-a*b*x + (a*a+c*c)*y - b*c*z - b*d)/nnormsq,
|
||||
|
||||
//z
|
||||
(-a*c*x - b*c*y + (a*a+b*b)*z - c*d)/nnormsq
|
||||
};
|
||||
// point on plane (x and z)
|
||||
p[0] = scrx + svcoeff*scrv[0];
|
||||
p[1] = scrz + svcoeff*scrv[2];
|
||||
|
||||
// implementation using a loop over all triangles
|
||||
for (j=0; j<s->indicescount; j+=3)
|
||||
|
@ -2210,27 +2220,35 @@ nextsector:
|
|||
} // determine searchwall
|
||||
} // ceiling or floor
|
||||
} // loop over sectors
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<m32_numdrawnsprites; i++)
|
||||
{
|
||||
GLfloat *pl = m32_drawnsprites[i].plane;
|
||||
GLdouble a=pl[0], b=pl[1], c=pl[2], d=pl[3];
|
||||
GLdouble nnormsq = a*a + b*b + c*c;
|
||||
GLdouble nnorm = sqrt(nnormsq);
|
||||
GLdouble dist = fabs(a*x + b*y + c*z + d)/nnorm;
|
||||
GLfloat scrv[3] = {x-viewx, y-viewy, z-viewz};
|
||||
GLfloat t, svcoeff, dist;
|
||||
int16_t sn = m32_drawnsprites[i].owner;
|
||||
|
||||
if (dist > bestdist+1.01 || ((sprite[sn].cstat&64) && -dot3f(scrv,pl)<0))
|
||||
t = dot3f(pl,scrv);
|
||||
if (t==0 || ((sprite[sn].cstat&64) && -t<0))
|
||||
continue;
|
||||
|
||||
svcoeff = -(dot3f(pl,scr)+pl[3])/t;
|
||||
if (svcoeff < 0)
|
||||
continue;
|
||||
|
||||
dist = svcoeff * sqrt(dot3f(scrv,scrv));
|
||||
if (dist > bestdist+1.01)
|
||||
continue;
|
||||
|
||||
{
|
||||
GLfloat tp[3] = {x,y,z};
|
||||
GLfloat *v = m32_drawnsprites[i].verts;
|
||||
GLfloat v12_r[3], v23_r[3], v34_r[3], v41_r[3];
|
||||
GLfloat v1p[3], v2p[3], v3p[3], v4p[3];
|
||||
GLfloat tp[3];
|
||||
|
||||
tp[0] = scrx + svcoeff*scrv[0];
|
||||
tp[1] = scry + svcoeff*scrv[1];
|
||||
tp[2] = scrz + svcoeff*scrv[2];
|
||||
|
||||
relvec3f(&v[3*3],&v[0*3], v12_r);
|
||||
relvec3f(&v[0*3],&v[1*3], v23_r);
|
||||
relvec3f(&v[1*3],&v[2*3], v34_r);
|
||||
|
|
Loading…
Reference in a new issue