diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 8d7c3fd02..46868dd12 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -108,6 +108,7 @@ typedef struct #else FLOAT anglex,angley; // aimingangle / viewangle #endif + FLOAT facing; // angle based on spritedef FLOAT scalex,scaley,scalez; FLOAT fovxangle, fovyangle; UINT8 splitscreen; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 6afa01586..4efb4cc4b 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1577,16 +1577,13 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) sprframe = &sprdef->spriteframes[spr->mobj->frame & FF_FRAMEMASK]; + p.angley = FIXED_TO_FLOAT(AngleFixed(mobjangle)); if (sprframe->rotate || papersprite) - { - fixed_t anglef = AngleFixed(mobjangle); - - p.angley = FIXED_TO_FLOAT(anglef); - } + p.facing = p.angley; else { const fixed_t anglef = AngleFixed((R_PointToAngle(spr->mobj->x, spr->mobj->y))-ANGLE_180); - p.angley = FIXED_TO_FLOAT(anglef); + p.facing = FIXED_TO_FLOAT(anglef); } p.rollangle = 0.0f; @@ -1598,10 +1595,6 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) p.rollangle = FIXED_TO_FLOAT(anglef); p.roll = true; - // rotation pivot - p.centerx = FIXED_TO_FLOAT(spr->mobj->radius/2); - p.centery = FIXED_TO_FLOAT(spr->mobj->height/(flip ? -2 : 2)); - // rotation axis if (sprinfo->available) p.rotaxis = (UINT8)(sprinfo->pivot[(spr->mobj->frame & FF_FRAMEMASK)].rotaxis); @@ -1617,8 +1610,11 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) p.rollflip *= -1; } - p.anglex = 0.0f; + // rotation pivot + p.centerx = FIXED_TO_FLOAT(spr->mobj->radius/2); + p.centery = FIXED_TO_FLOAT(spr->mobj->height/(flip ? -2 : 2)); + p.anglex = 0.0f; #ifdef USE_FTRANSFORM_ANGLEZ p.anglez = 0.0f; #ifdef STANDINGSLOPE_MODEL_ROTATION @@ -1633,13 +1629,17 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) p.anglez = FIXED_TO_FLOAT(tempangle); tempangle = -AngleFixed(R_PointToAngle2(0, 0, tempz, tempy)); p.anglex = FIXED_TO_FLOAT(tempangle); + p.roll = true; } -#endif - if (spr->mobj->roll) - p.anglex += FIXED_TO_FLOAT(AngleFixed(spr->mobj->roll)); - if (spr->mobj->pitch) - p.anglez -= FIXED_TO_FLOAT(AngleFixed(spr->mobj->pitch)); -#endif +#endif // STANDINGSLOPE_MODEL_ROTATION + if (spr->mobj->roll || spr->mobj->pitch) + { + SINT8 flipfactor = flip ? -1 : 1; + p.anglex += flipfactor*FIXED_TO_FLOAT(AngleFixed(spr->mobj->roll)); + p.anglez -= flipfactor*FIXED_TO_FLOAT(AngleFixed(spr->mobj->pitch)); + p.roll = true; + } +#endif // USE_FTRANSFORM_ANGLEZ // SRB2CBTODO: MD2 scaling support finalscale *= FIXED_TO_FLOAT(spr->mobj->scale); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index de746467b..c2aec0a22 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2800,24 +2800,31 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 scalez = -scalez; pglRotatef(pos->angley, 0.0f, -1.0f, 0.0f); - pglRotatef(pos->anglex, 1.0f, 0.0f, 0.0f); -#ifdef USE_FTRANSFORM_ANGLEZ - pglRotatef(pos->anglez, 0.0f, 0.0f, -1.0f); // rotate by slope from Kart -#endif if (pos->roll) { float roll = (1.0f * pos->rollflip); pglTranslatef(pos->centerx, pos->centery, 0); + + // rotate model for pitch and roll + pglRotatef(pos->anglex, 1.0f, 0.0f, 0.0f); +#ifdef USE_FTRANSFORM_ANGLEZ + pglRotatef(pos->anglez, 0.0f, 0.0f, -1.0f); // rotate by slope from Kart +#endif + + // rotate model for rollangle if (pos->rotaxis == 2) // Z pglRotatef(pos->rollangle, 0.0f, 0.0f, roll); else if (pos->rotaxis == 1) // Y pglRotatef(pos->rollangle, 0.0f, roll, 0.0f); else // X pglRotatef(pos->rollangle, roll, 0.0f, 0.0f); + pglTranslatef(-pos->centerx, -pos->centery, 0); } + pglRotatef(pos->facing - pos->angley, 0.0f, -1.0f, 0.0f); + pglScalef(scalex, scaley, scalez); useTinyFrames = model->meshes[0].tinyframes != NULL;