Added A_SpriteOffset. (#895)

- Coordinates work akin to A_OverlayOffset: +X shifts to the right, +Y shifts down.
This commit is contained in:
MajorCooke 2020-08-27 11:43:09 -05:00 committed by GitHub
parent 3e69e44763
commit 85759e3bd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 16 deletions

View file

@ -995,6 +995,7 @@ public:
DVector3 OldRenderPos; DVector3 OldRenderPos;
DVector3 Vel; DVector3 Vel;
DVector2 SpriteOffset;
double Speed; double Speed;
double FloatSpeed; double FloatSpeed;

View file

@ -365,6 +365,7 @@ void AActor::Serialize(FSerializer &arc)
A("spawntime", SpawnTime) A("spawntime", SpawnTime)
A("spawnorder", SpawnOrder) A("spawnorder", SpawnOrder)
A("friction", Friction) A("friction", Friction)
A("SpriteOffset", SpriteOffset)
A("userlights", UserLights); A("userlights", UserLights);
SerializeTerrain(arc, "floorterrain", floorterrain, &def->floorterrain); SerializeTerrain(arc, "floorterrain", floorterrain, &def->floorterrain);

View file

@ -899,11 +899,10 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
r.Scale(sprscale.X, sprscale.Y); r.Scale(sprscale.X, sprscale.Y);
float rightfac = -r.left; float SpriteOffY = thing->SpriteOffset.Y;
float rightfac = -r.left - thing->SpriteOffset.X;
float leftfac = rightfac - r.width; float leftfac = rightfac - r.width;
float bottomfac = -r.top; z1 = z - r.top - SpriteOffY;
float topfac = bottomfac - r.height;
z1 = z - r.top;
z2 = z1 - r.height; z2 = z1 - r.height;
float spriteheight = sprscale.Y * r.height; float spriteheight = sprscale.Y * r.height;
@ -914,31 +913,39 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
PerformSpriteClipAdjustment(thing, thingpos, spriteheight); PerformSpriteClipAdjustment(thing, thingpos, spriteheight);
} }
float viewvecX;
float viewvecY;
switch (spritetype) switch (spritetype)
{ {
case RF_FACESPRITE: case RF_FACESPRITE:
viewvecX = vp.ViewVector.X; {
viewvecY = vp.ViewVector.Y; float viewvecX = vp.ViewVector.X;
float viewvecY = vp.ViewVector.Y;
x1 = x - viewvecY*leftfac; x1 = x - viewvecY*leftfac;
x2 = x - viewvecY*rightfac; x2 = x - viewvecY*rightfac;
y1 = y + viewvecX*leftfac; y1 = y + viewvecX*leftfac;
y2 = y + viewvecX*rightfac; y2 = y + viewvecX*rightfac;
break; break;
}
case RF_FLATSPRITE: case RF_FLATSPRITE:
{ {
float bottomfac = -r.top - SpriteOffY;
float topfac = bottomfac - r.height;
x1 = x + leftfac; x1 = x + leftfac;
x2 = x + rightfac; x2 = x + rightfac;
y1 = y - topfac; y1 = y - topfac;
y2 = y - bottomfac; y2 = y - bottomfac;
} // [MC] Counteract in case of any potential problems. Tests so far haven't
// shown any outstanding issues but that doesn't mean they won't appear later
// when more features are added.
z1 += SpriteOffY;
z2 += SpriteOffY;
break; break;
}
case RF_WALLSPRITE: case RF_WALLSPRITE:
viewvecX = Angles.Yaw.Cos(); {
viewvecY = Angles.Yaw.Sin(); float viewvecX = Angles.Yaw.Cos();
float viewvecY = Angles.Yaw.Sin();
x1 = x + viewvecY*leftfac; x1 = x + viewvecY*leftfac;
x2 = x + viewvecY*rightfac; x2 = x + viewvecY*rightfac;
@ -947,6 +954,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
break; break;
} }
} }
}
else else
{ {
x1 = x2 = x; x1 = x2 = x;

View file

@ -1004,9 +1004,9 @@ namespace swrenderer
bool RenderOpaquePass::GetThingSprite(AActor *thing, ThingSprite &sprite) bool RenderOpaquePass::GetThingSprite(AActor *thing, ThingSprite &sprite)
{ {
// The X offsetting (SpriteOffset.X) is performed in r_sprite.cpp, in RenderSprite::Project().
sprite.pos = thing->InterpolatedPosition(Thread->Viewport->viewpoint.TicFrac); sprite.pos = thing->InterpolatedPosition(Thread->Viewport->viewpoint.TicFrac);
sprite.pos.Z += thing->GetBobOffset(Thread->Viewport->viewpoint.TicFrac); sprite.pos.Z += thing->GetBobOffset(Thread->Viewport->viewpoint.TicFrac) - thing->SpriteOffset.Y;
sprite.spritenum = thing->sprite; sprite.spritenum = thing->sprite;
sprite.tex = nullptr; sprite.tex = nullptr;
sprite.voxel = nullptr; sprite.voxel = nullptr;

View file

@ -81,8 +81,11 @@ namespace swrenderer
const double thingxscalemul = spriteScale.X / tex->GetScale().X; const double thingxscalemul = spriteScale.X / tex->GetScale().X;
// Calculate billboard line for the sprite // Calculate billboard line for the sprite
double SpriteOffX = (thing) ? thing->SpriteOffset.X : 0.;
DVector2 dir = { viewport->viewpoint.Sin, -viewport->viewpoint.Cos }; DVector2 dir = { viewport->viewpoint.Sin, -viewport->viewpoint.Cos };
DVector2 pt1 = pos.XY() - viewport->viewpoint.Pos.XY() - dir * (((renderflags & RF_XFLIP) ? (tex->GetWidth() - tex->GetLeftOffsetSW() - 1) : tex->GetLeftOffsetSW()) * thingxscalemul); DVector2 trs = pos.XY() - viewport->viewpoint.Pos.XY();
trs = { trs.X + SpriteOffX * dir.X, trs.Y + SpriteOffX * dir.Y };
DVector2 pt1 = trs - dir * (((renderflags & RF_XFLIP) ? (tex->GetWidth() - tex->GetLeftOffsetSW() - 1) : tex->GetLeftOffsetSW()) * thingxscalemul);
DVector2 pt2 = pt1 + dir * (tex->GetWidth() * thingxscalemul); DVector2 pt2 = pt1 + dir * (tex->GetWidth() * thingxscalemul);
FWallCoords wallc; FWallCoords wallc;

View file

@ -1775,6 +1775,7 @@ DEFINE_FIELD_NAMED(AActor, __Pos, pos)
DEFINE_FIELD_NAMED(AActor, __Pos.X, x) DEFINE_FIELD_NAMED(AActor, __Pos.X, x)
DEFINE_FIELD_NAMED(AActor, __Pos.Y, y) DEFINE_FIELD_NAMED(AActor, __Pos.Y, y)
DEFINE_FIELD_NAMED(AActor, __Pos.Z, z) DEFINE_FIELD_NAMED(AActor, __Pos.Z, z)
DEFINE_FIELD(AActor, SpriteOffset)
DEFINE_FIELD(AActor, Prev) DEFINE_FIELD(AActor, Prev)
DEFINE_FIELD(AActor, SpriteAngle) DEFINE_FIELD(AActor, SpriteAngle)
DEFINE_FIELD(AActor, SpriteRotation) DEFINE_FIELD(AActor, SpriteRotation)

View file

@ -95,4 +95,9 @@ extend class Actor
} }
} }
void A_SpriteOffset(double ox = 0.0, double oy = 0.0)
{
SpriteOffset.X = ox;
SpriteOffset.Y = oy;
}
} }

View file

@ -89,6 +89,7 @@ class Actor : Thinker native
native PlayerInfo Player; native PlayerInfo Player;
native readonly vector3 Pos; native readonly vector3 Pos;
native vector3 Prev; native vector3 Prev;
native vector2 SpriteOffset;
native double spriteAngle; native double spriteAngle;
native double spriteRotation; native double spriteRotation;
native double VisibleStartAngle; native double VisibleStartAngle;