Skip to content

Commit

Permalink
Add X, Y and Z offsets for VOXELDEF. Needed for voxelized weapons whi…
Browse files Browse the repository at this point in the history
…ch would typically be very large and take up the majority of the 256x256x256 canvas, therefore making precise positioning of the models relative to the screen pretty much impossible without tweakable offsets.
  • Loading branch information
nashmuhandes authored and RicardoLuis0 committed Jun 21, 2024
1 parent 13b9ffd commit 2e4bf69
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/common/models/voxels.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ struct FVoxelDef
int VoxeldefIndex; // Needed by GZDoom
double Scale;
DAngle AngleOffset;// added to actor's angle to compensate for wrong-facing voxels
double xoffset;
double yoffset;
double zoffset;
bool PitchFromMomentum;
bool UseActorPitch;
bool UseActorRoll;
Expand Down
3 changes: 3 additions & 0 deletions src/r_data/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ void InitModels()
smf.animationIDs[0] = -1;
smf.xscale = smf.yscale = smf.zscale = VoxelDefs[i]->Scale;
smf.angleoffset = VoxelDefs[i]->AngleOffset.Degrees();
smf.xoffset = VoxelDefs[i]->xoffset;
smf.yoffset = VoxelDefs[i]->yoffset;
smf.zoffset = VoxelDefs[i]->zoffset;
// this helps catching uninitialized data.
assert(VoxelDefs[i]->PitchFromMomentum == true || VoxelDefs[i]->PitchFromMomentum == false);
if (VoxelDefs[i]->PitchFromMomentum) smf.flags |= MDL_PITCHFROMMOMENTUM;
Expand Down
54 changes: 54 additions & 0 deletions src/r_data/voxeldef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ struct VoxelOptions
int PlacedSpin = 0;
double Scale = 1;
DAngle AngleOffset = DAngle90;
double xoffset = 0.0;
double yoffset = 0.0;
double zoffset = 0.0;
bool OverridePalette = false;
bool PitchFromMomentum = false;
bool UseActorPitch = false;
Expand Down Expand Up @@ -177,6 +180,54 @@ static void VOX_ReadOptions(FScanner &sc, VoxelOptions &opts)
}
opts.AngleOffset = DAngle::fromDeg(mul * sc.Float + 90.);
}
else if (sc.Compare("xoffset"))
{
int mul = 1;
sc.MustGetToken('=');
if (sc.CheckToken('-')) mul = -1;
sc.MustGetAnyToken();
if (sc.TokenType == TK_IntConst)
{
sc.Float = sc.Number;
}
else
{
sc.TokenMustBe(TK_FloatConst);
}
opts.xoffset = sc.Float * mul;
}
else if (sc.Compare("yoffset"))
{
int mul = 1;
sc.MustGetToken('=');
if (sc.CheckToken('-')) mul = -1;
sc.MustGetAnyToken();
if (sc.TokenType == TK_IntConst)
{
sc.Float = sc.Number;
}
else
{
sc.TokenMustBe(TK_FloatConst);
}
opts.yoffset = sc.Float * mul;
}
else if (sc.Compare("zoffset"))
{
int mul = 1;
sc.MustGetToken('=');
if (sc.CheckToken('-')) mul = -1;
sc.MustGetAnyToken();
if (sc.TokenType == TK_IntConst)
{
sc.Float = sc.Number;
}
else
{
sc.TokenMustBe(TK_FloatConst);
}
opts.zoffset = sc.Float * mul;
}
else if (sc.Compare("overridepalette"))
{
opts.OverridePalette = true;
Expand Down Expand Up @@ -262,6 +313,9 @@ void R_InitVoxels()
def->DroppedSpin = opts.DroppedSpin;
def->PlacedSpin = opts.PlacedSpin;
def->AngleOffset = opts.AngleOffset;
def->xoffset = opts.xoffset;
def->yoffset = opts.yoffset;
def->zoffset = opts.zoffset;
def->PitchFromMomentum = opts.PitchFromMomentum;
def->UseActorPitch = opts.UseActorPitch;
def->UseActorRoll = opts.UseActorRoll;
Expand Down
3 changes: 3 additions & 0 deletions src/rendering/swrenderer/things/r_voxel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ namespace swrenderer

vis->depth = (float)tz;
vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z };
vis->gpos.X += (float)voxel->xoffset;
vis->gpos.Y += (float)voxel->yoffset;
vis->gpos.Z += (float)voxel->zoffset;
vis->gzb = (float)gzb; // [RH] use gzb, not thing->z
vis->gzt = (float)gzt; // killough 3/27/98
vis->deltax = float(pos.X - thread->Viewport->viewpoint.Pos.X);
Expand Down

0 comments on commit 2e4bf69

Please sign in to comment.