Commit 66e1678a authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: fix "twitching" of models drawn with rotatesprite when the viewangle...

engine: fix "twitching" of models drawn with rotatesprite when the viewangle changes in polymost and polymer
parent e8ea24b8
......@@ -1859,8 +1859,18 @@ void md3_vox_calcmat_common(tspriteptr_t tspr, const vec3f_t *a0, float f, float
k1 = ((float)(tspr->y+spriteext[tspr->owner].mdposition_offset.y-globalposy))*f*(1.f/1024.f);
f = gcosang2*gshang/gvrcorrection;
g = gsinang2*gshang/gvrcorrection;
k4 = (float)sintable[(tspr->ang+spriteext[tspr->owner].mdangoff+1024)&2047] * (1.f/16384.f);
k5 = (float)sintable[(tspr->ang+spriteext[tspr->owner].mdangoff+ 512)&2047] * (1.f/16384.f);
if (tspriteptr[maxspritesonscreen] == tspr)
{
k4 = sinf(fix16_to_float((fix16_from_int((tspr->ang - globalang + spriteext[tspr->owner].mdangoff + 1024) & 2047) + qglobalang) & 0x7FFFFFF) * BANG2RAD);
k5 = sinf(fix16_to_float((fix16_from_int((tspr->ang - globalang + spriteext[tspr->owner].mdangoff + 512) & 2047) + qglobalang) & 0x7FFFFFF) * BANG2RAD);
}
else
{
k4 = (float)sintable[(tspr->ang+spriteext[tspr->owner].mdangoff+1024)&2047] * (1.f/16384.f);
k5 = (float)sintable[(tspr->ang+spriteext[tspr->owner].mdangoff+ 512)&2047] * (1.f/16384.f);
}
k2 = k0*(1-k4)+k1*k5;
k3 = k1*(1-k4)-k0*k5;
k6 = f*gstang - gsinang*gctang; k7 = g*gstang + gcosang*gctang;
......
......@@ -4401,7 +4401,7 @@ static void polymer_drawskybox(int16_t tilenum, char palnum, int8_t shad
}
// MDSPRITES
static void polymer_drawmdsprite(tspriteptr_t tspr)
void polymer_drawmdsprite(tspriteptr_t tspr)
{
md3model_t* m;
mdskinmap_t* sk;
......@@ -4429,38 +4429,39 @@ static void polymer_drawmdsprite(tspriteptr_t tspr)
// Hackish, but that means it's a model drawn by rotatesprite.
if (tspriteptr[maxspritesonscreen] == tspr) {
float x, y, z;
spos[0] = fglobalposy;
spos[1] = fglobalposz * (-1.f/16.f);
spos[2] = -fglobalposx;
// The coordinates are actually floats disguised as int in this case
memcpy(&x, &tspr->x, sizeof(float));
memcpy(&y, &tspr->y, sizeof(float));
memcpy(&z, &tspr->z, sizeof(float));
vec3f_t v = *(vec3f_t*)&tspr->xyz;
spos2[0] = v.y - fglobalposy;
spos2[1] = (v.z - fglobalposz) * (-1.f/16.f);
spos2[2] = fglobalposx - v.x;
spos2[0] = y - globalposy;
spos2[1] = (z - fglobalposz) * (-1.f/16.f);
spos2[2] = fglobalposx - x;
ang = fix16_to_float((fix16_from_int((tspr->ang+spriteext[tspr->owner].mdangoff-globalang) & 2047) + qglobalang) & 0x7FFFFFF) * (360.f/2048.f);
} else {
spos[0] = (float)tspr->y+spriteext[tspr->owner].mdposition_offset.y;
spos[1] = -(float)(tspr->z+spriteext[tspr->owner].mdposition_offset.z) * (1.f/16.f);
spos[2] = -(float)(tspr->x+spriteext[tspr->owner].mdposition_offset.x);
spos2[0] = spos2[1] = spos2[2] = 0.0f;
ang = (float)((tspr->ang+spriteext[tspr->owner].mdangoff) & 2047) * (360.f/2048.f);
}
ang = (float)((tspr->ang+spriteext[tspr->owner].mdangoff) & 2047) * (360.f/2048.f);
ang -= 90.0f;
if (((tspr->cstat>>4) & 3) == 2)
ang -= 90.0f;
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
scale = (1.0/4.0);
scale *= m->scale;
scale = m->scale * 0.25f;
if (pr_overridemodelscale) {
scale *= pr_overridemodelscale;
} else {
......@@ -4468,13 +4469,11 @@ static void polymer_drawmdsprite(tspriteptr_t tspr)
}
if (tspriteptr[maxspritesonscreen] == tspr) {
float playerang, radplayerang, cosminusradplayerang, sinminusradplayerang, hudzoom;
playerang = (globalang & 2047) * (360.f/2048.f) - 90.0f;
radplayerang = (globalang & 2047) * (2.0f * fPI / 2048.0f);
cosminusradplayerang = cos(-radplayerang);
sinminusradplayerang = sin(-radplayerang);
hudzoom = 65536.0 / spriteext[tspr->owner].mdpivot_offset.z;
float playerang = fix16_to_float(qglobalang & 0x7FFFFFF) * (360.f/2048.f) - 90.0f;
float radplayerang = fix16_to_float(qglobalang & 0x7FFFFFF) * (2.0f * fPI / 2048.0f);
float cosminusradplayerang = cosf(-radplayerang);
float sinminusradplayerang = sinf(-radplayerang);
float hudzoom = 65536.f / spriteext[tspr->owner].mdpivot_offset.z;
glTranslatef(spos[0], spos[1], spos[2]);
glRotatef(horizang, -cosminusradplayerang, 0.0f, sinminusradplayerang);
......
......@@ -9015,6 +9015,8 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a,
polymost_setFogEnabled(false);
tspriteptr[maxspritesonscreen] = &tspr;
if (videoGetRenderMode() == REND_POLYMOST)
polymost_mddraw(&tspr);
# ifdef POLYMER
......@@ -9022,7 +9024,6 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a,
{
int32_t fov;
tspriteptr[maxspritesonscreen] = &tspr;
buildgl_setEnabled(GL_ALPHA_TEST);
buildgl_setEnabled(GL_BLEND);
......@@ -9046,12 +9047,14 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a,
spriteext[tspr.owner].mdpivot_offset.z = 0;
spriteext[tspr.owner].mdroll = 0;
tspriteptr[maxspritesonscreen] = nullptr;
buildgl_setDisabled(GL_ALPHA_TEST);
buildgl_setDisabled(GL_BLEND);
}
# endif
tspriteptr[maxspritesonscreen] = nullptr;
if (!nofog) polymost_setFogEnabled(true);
gvrcorrection = ogvrcorrection;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment