Skip to content

Commit 2e4bf69

Browse files
nashmuhandesRicardoLuis0
authored andcommitted
Add X, Y and Z offsets for VOXELDEF. Needed for voxelized weapons which 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.
1 parent 13b9ffd commit 2e4bf69

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

src/common/models/voxels.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ struct FVoxelDef
7373
int VoxeldefIndex; // Needed by GZDoom
7474
double Scale;
7575
DAngle AngleOffset;// added to actor's angle to compensate for wrong-facing voxels
76+
double xoffset;
77+
double yoffset;
78+
double zoffset;
7679
bool PitchFromMomentum;
7780
bool UseActorPitch;
7881
bool UseActorRoll;

src/r_data/models.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ void InitModels()
616616
smf.animationIDs[0] = -1;
617617
smf.xscale = smf.yscale = smf.zscale = VoxelDefs[i]->Scale;
618618
smf.angleoffset = VoxelDefs[i]->AngleOffset.Degrees();
619+
smf.xoffset = VoxelDefs[i]->xoffset;
620+
smf.yoffset = VoxelDefs[i]->yoffset;
621+
smf.zoffset = VoxelDefs[i]->zoffset;
619622
// this helps catching uninitialized data.
620623
assert(VoxelDefs[i]->PitchFromMomentum == true || VoxelDefs[i]->PitchFromMomentum == false);
621624
if (VoxelDefs[i]->PitchFromMomentum) smf.flags |= MDL_PITCHFROMMOMENTUM;

src/r_data/voxeldef.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ struct VoxelOptions
5858
int PlacedSpin = 0;
5959
double Scale = 1;
6060
DAngle AngleOffset = DAngle90;
61+
double xoffset = 0.0;
62+
double yoffset = 0.0;
63+
double zoffset = 0.0;
6164
bool OverridePalette = false;
6265
bool PitchFromMomentum = false;
6366
bool UseActorPitch = false;
@@ -177,6 +180,54 @@ static void VOX_ReadOptions(FScanner &sc, VoxelOptions &opts)
177180
}
178181
opts.AngleOffset = DAngle::fromDeg(mul * sc.Float + 90.);
179182
}
183+
else if (sc.Compare("xoffset"))
184+
{
185+
int mul = 1;
186+
sc.MustGetToken('=');
187+
if (sc.CheckToken('-')) mul = -1;
188+
sc.MustGetAnyToken();
189+
if (sc.TokenType == TK_IntConst)
190+
{
191+
sc.Float = sc.Number;
192+
}
193+
else
194+
{
195+
sc.TokenMustBe(TK_FloatConst);
196+
}
197+
opts.xoffset = sc.Float * mul;
198+
}
199+
else if (sc.Compare("yoffset"))
200+
{
201+
int mul = 1;
202+
sc.MustGetToken('=');
203+
if (sc.CheckToken('-')) mul = -1;
204+
sc.MustGetAnyToken();
205+
if (sc.TokenType == TK_IntConst)
206+
{
207+
sc.Float = sc.Number;
208+
}
209+
else
210+
{
211+
sc.TokenMustBe(TK_FloatConst);
212+
}
213+
opts.yoffset = sc.Float * mul;
214+
}
215+
else if (sc.Compare("zoffset"))
216+
{
217+
int mul = 1;
218+
sc.MustGetToken('=');
219+
if (sc.CheckToken('-')) mul = -1;
220+
sc.MustGetAnyToken();
221+
if (sc.TokenType == TK_IntConst)
222+
{
223+
sc.Float = sc.Number;
224+
}
225+
else
226+
{
227+
sc.TokenMustBe(TK_FloatConst);
228+
}
229+
opts.zoffset = sc.Float * mul;
230+
}
180231
else if (sc.Compare("overridepalette"))
181232
{
182233
opts.OverridePalette = true;
@@ -262,6 +313,9 @@ void R_InitVoxels()
262313
def->DroppedSpin = opts.DroppedSpin;
263314
def->PlacedSpin = opts.PlacedSpin;
264315
def->AngleOffset = opts.AngleOffset;
316+
def->xoffset = opts.xoffset;
317+
def->yoffset = opts.yoffset;
318+
def->zoffset = opts.zoffset;
265319
def->PitchFromMomentum = opts.PitchFromMomentum;
266320
def->UseActorPitch = opts.UseActorPitch;
267321
def->UseActorRoll = opts.UseActorRoll;

src/rendering/swrenderer/things/r_voxel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ namespace swrenderer
148148

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

0 commit comments

Comments
 (0)