mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-10 14:51:46 +00:00
- some more weapon code extracted.
This commit is contained in:
parent
c2ac985357
commit
ebc1c5741b
3 changed files with 102 additions and 80 deletions
|
@ -50,7 +50,6 @@
|
|||
EXTERN_CVAR (Bool, r_drawplayersprites)
|
||||
EXTERN_CVAR (Bool, r_deathcamera)
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// R_DrawPSprite
|
||||
|
@ -59,91 +58,20 @@ EXTERN_CVAR (Bool, r_deathcamera)
|
|||
|
||||
void GLSceneDrawer::DrawPSprite (player_t * player,DPSprite *psp, float sx, float sy, int OverrideShader, bool alphatexture)
|
||||
{
|
||||
float fU1,fV1;
|
||||
float fU2,fV2;
|
||||
float tx;
|
||||
float x1,y1,x2,y2;
|
||||
float scale;
|
||||
float scalex;
|
||||
float ftexturemid;
|
||||
WeaponRect rc;
|
||||
|
||||
// decide which patch to use
|
||||
bool mirror;
|
||||
FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., &mirror);
|
||||
if (!lump.isValid()) return;
|
||||
|
||||
FMaterial * tex = FMaterial::ValidateTexture(lump, true, false);
|
||||
if (!tex) return;
|
||||
|
||||
gl_RenderState.SetMaterial(tex, CLAMP_XY_NOMIP, 0, OverrideShader, alphatexture);
|
||||
|
||||
float vw = (float)viewwidth;
|
||||
float vh = (float)viewheight;
|
||||
|
||||
FloatRect r;
|
||||
tex->GetSpriteRect(&r);
|
||||
|
||||
// calculate edges of the shape
|
||||
scalex = (320.0f / (240.0f * r_viewwindow.WidescreenRatio)) * vw / 320;
|
||||
|
||||
tx = (psp->Flags & PSPF_MIRROR) ? ((160 - r.width) - (sx + r.left)) : (sx - (160 - r.left));
|
||||
x1 = tx * scalex + vw/2;
|
||||
if (x1 > vw) return; // off the right side
|
||||
x1 += viewwindowx;
|
||||
|
||||
tx += r.width;
|
||||
x2 = tx * scalex + vw / 2;
|
||||
if (x2 < 0) return; // off the left side
|
||||
x2 += viewwindowx;
|
||||
|
||||
// killough 12/98: fix psprite positioning problem
|
||||
ftexturemid = 100.f - sy - r.top;
|
||||
|
||||
AWeapon * wi=player->ReadyWeapon;
|
||||
if (wi && wi->YAdjust != 0)
|
||||
{
|
||||
float fYAd = wi->YAdjust;
|
||||
if (screenblocks >= 11)
|
||||
{
|
||||
ftexturemid -= fYAd;
|
||||
}
|
||||
else
|
||||
{
|
||||
ftexturemid -= StatusBar->GetDisplacement () * fYAd;
|
||||
}
|
||||
}
|
||||
|
||||
scale = (SCREENHEIGHT*vw) / (SCREENWIDTH * 200.0f);
|
||||
y1 = viewwindowy + vh / 2 - (ftexturemid * scale);
|
||||
y2 = y1 + (r.height * scale) + 1;
|
||||
|
||||
|
||||
if (!(mirror) != !(psp->Flags & (PSPF_FLIP)))
|
||||
{
|
||||
fU2 = tex->GetSpriteUL();
|
||||
fV1 = tex->GetSpriteVT();
|
||||
fU1 = tex->GetSpriteUR();
|
||||
fV2 = tex->GetSpriteVB();
|
||||
}
|
||||
else
|
||||
{
|
||||
fU1 = tex->GetSpriteUL();
|
||||
fV1 = tex->GetSpriteVT();
|
||||
fU2 = tex->GetSpriteUR();
|
||||
fV2 = tex->GetSpriteVB();
|
||||
|
||||
}
|
||||
|
||||
if (tex->tex->GetTranslucency() || OverrideShader != -1)
|
||||
if (!GetWeaponRect(psp, sx, sy, player, rc)) return;
|
||||
gl_RenderState.SetMaterial(rc.tex, CLAMP_XY_NOMIP, 0, OverrideShader, alphatexture);
|
||||
if (rc.tex->tex->GetTranslucency() || OverrideShader != -1)
|
||||
{
|
||||
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
|
||||
}
|
||||
gl_RenderState.Apply();
|
||||
FQuadDrawer qd;
|
||||
qd.Set(0, x1, y1, 0, fU1, fV1);
|
||||
qd.Set(1, x1, y2, 0, fU1, fV2);
|
||||
qd.Set(2, x2, y1, 0, fU2, fV1);
|
||||
qd.Set(3, x2, y2, 0, fU2, fV2);
|
||||
qd.Set(0, rc.x1, rc.y1, 0, rc.u1, rc.v1);
|
||||
qd.Set(1, rc.x1, rc.y2, 0, rc.u1, rc.v2);
|
||||
qd.Set(2, rc.x2, rc.y1, 0, rc.u2, rc.v1);
|
||||
qd.Set(3, rc.x2, rc.y2, 0, rc.u2, rc.v2);
|
||||
qd.Render(GL_TRIANGLE_STRIP);
|
||||
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.5f);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "g_levellocals.h"
|
||||
#include "hw_weapon.h"
|
||||
#include "hw_fakeflat.h"
|
||||
#include "hwrenderer/textures/hw_material.h"
|
||||
#include "hwrenderer/utility/hw_lighting.h"
|
||||
#include "hwrenderer/utility/hw_cvars.h"
|
||||
|
||||
|
@ -282,3 +283,85 @@ WeaponRenderStyle GetWeaponRenderStyle(DPSprite *psp, AActor *playermo)
|
|||
return r;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Coordinates
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
bool GetWeaponRect(DPSprite *psp, float sx, float sy, player_t *player, WeaponRect &rc)
|
||||
{
|
||||
float tx;
|
||||
float x1, x2;
|
||||
float scale;
|
||||
float scalex;
|
||||
float ftexturemid;
|
||||
|
||||
// decide which patch to use
|
||||
bool mirror;
|
||||
FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., &mirror);
|
||||
if (!lump.isValid()) return false;
|
||||
|
||||
FMaterial * tex = FMaterial::ValidateTexture(lump, true, false);
|
||||
if (!tex) return false;
|
||||
|
||||
float vw = (float)viewwidth;
|
||||
float vh = (float)viewheight;
|
||||
|
||||
FloatRect r;
|
||||
tex->GetSpriteRect(&r);
|
||||
|
||||
// calculate edges of the shape
|
||||
scalex = (320.0f / (240.0f * r_viewwindow.WidescreenRatio)) * vw / 320;
|
||||
|
||||
tx = (psp->Flags & PSPF_MIRROR) ? ((160 - r.width) - (sx + r.left)) : (sx - (160 - r.left));
|
||||
x1 = tx * scalex + vw / 2;
|
||||
if (x1 > vw) return false; // off the right side
|
||||
rc.x1 = x1 + viewwindowx;
|
||||
|
||||
|
||||
tx += r.width;
|
||||
x2 = tx * scalex + vw / 2;
|
||||
if (x2 < 0) return false; // off the left side
|
||||
rc.x2 = x2 + viewwindowx;
|
||||
|
||||
// killough 12/98: fix psprite positioning problem
|
||||
ftexturemid = 100.f - sy - r.top;
|
||||
|
||||
AWeapon * wi = player->ReadyWeapon;
|
||||
if (wi && wi->YAdjust != 0)
|
||||
{
|
||||
float fYAd = wi->YAdjust;
|
||||
if (screenblocks >= 11)
|
||||
{
|
||||
ftexturemid -= fYAd;
|
||||
}
|
||||
else
|
||||
{
|
||||
ftexturemid -= float(StatusBar->GetDisplacement()) * fYAd;
|
||||
}
|
||||
}
|
||||
|
||||
scale = (SCREENHEIGHT*vw) / (SCREENWIDTH * 200.0f);
|
||||
rc.y1 = viewwindowy + vh / 2 - (ftexturemid * scale);
|
||||
rc.y2 = rc.y1 + (r.height * scale) + 1;
|
||||
|
||||
|
||||
if (!(mirror) != !(psp->Flags & (PSPF_FLIP)))
|
||||
{
|
||||
rc.u2 = tex->GetSpriteUL();
|
||||
rc.v1 = tex->GetSpriteVT();
|
||||
rc.u1 = tex->GetSpriteUR();
|
||||
rc.v2 = tex->GetSpriteVB();
|
||||
}
|
||||
else
|
||||
{
|
||||
rc.u1 = tex->GetSpriteUL();
|
||||
rc.v1 = tex->GetSpriteVT();
|
||||
rc.u2 = tex->GetSpriteUR();
|
||||
rc.v2 = tex->GetSpriteVB();
|
||||
}
|
||||
rc.tex = tex;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,9 +28,20 @@ struct WeaponRenderStyle
|
|||
int OverrideShader;
|
||||
};
|
||||
|
||||
struct WeaponRect
|
||||
{
|
||||
FMaterial *tex;
|
||||
float x1, y1;
|
||||
float x2, y2;
|
||||
float u1, v1;
|
||||
float u2, v2;
|
||||
};
|
||||
|
||||
|
||||
|
||||
bool isBright(DPSprite *psp);
|
||||
WeaponPosition GetWeaponPosition(player_t *player);
|
||||
FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp);
|
||||
WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int FixedColormap, area_t in_area, const DVector3 &playerpos );
|
||||
WeaponRenderStyle GetWeaponRenderStyle(DPSprite *psp, AActor *playermo);
|
||||
bool GetWeaponRect(DPSprite *psp, float sx, float sy, player_t *player, WeaponRect &rc);
|
||||
|
|
Loading…
Reference in a new issue