Skip to content

Commit

Permalink
Merge pull request #823 from pbdot/ec-issue-821
Browse files Browse the repository at this point in the history
Check model radius for clipping and fix other model clipping issues
  • Loading branch information
pbdot authored Jan 11, 2025
2 parents 5786db7 + c8e1896 commit 48ea538
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 112 deletions.
7 changes: 2 additions & 5 deletions source_files/edge/r_md2.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
// opaque handle for rest of the engine
class MD2Model;

MD2Model *MD2Load(epi::File *f);
MD2Model *MD3Load(epi::File *f);
MD2Model *MD2Load(epi::File *f, float& radius);
MD2Model *MD3Load(epi::File *f, float& radius);

short MD2FindFrame(MD2Model *md, const char *name);

Expand All @@ -36,6 +36,3 @@ void MD2RenderModel(MD2Model *md, const Image *skin_img, bool is_weapon, int fra

void MD2RenderModel2D(MD2Model *md, const Image *skin_img, int frame, float x, float y, float xscale, float yscale,
const MapObjectDefinition *info);

//--- editor settings ---
// vi:ts=4:sw=4:noexpandtab
2 changes: 1 addition & 1 deletion source_files/edge/r_mdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// opaque handle for rest of the engine
class MDLModel;

MDLModel *MDLLoad(epi::File *f);
MDLModel *MDLLoad(epi::File *f, float& radius);

short MDLFindFrame(MDLModel *md, const char *name);

Expand Down
23 changes: 18 additions & 5 deletions source_files/edge/r_things.cc
Original file line number Diff line number Diff line change
Expand Up @@ -885,16 +885,28 @@ void BSPWalkThing(DrawSubsector *dsub, MapObject *mo)
float tz = tr_x * view_cosine + tr_y * view_sine;

// thing is behind view plane?
if (clip_scope != kBAMAngle180 && tz <= 0) // && !is_model)
return;
if (!is_model)
{
if (clip_scope != kBAMAngle180 && tz <= 0)
return;
}
else
{
ModelDefinition *md = GetModel(mo->state_->sprite);
EPI_ASSERT(md);
if (clip_scope != kBAMAngle180 && tz < -(md->radius_ * mo->scale_))
{
return;
}
}

float tx = tr_x * view_sine - tr_y * view_cosine;

// too far off the side?
// -ES- 1999/03/13 Fixed clipping to work with large FOVs (up to 176 deg)
// rejects all sprites where angle>176 deg (arctan 32), since those
// sprites would result in overflow in future calculations
if (tz >= kMinimumSpriteDistance && fabs(tx) / 32 > tz)
if (!is_model && (tz >= kMinimumSpriteDistance) && ((fabs(tx) / 32) > tz))
return;

float sink_mult = 0;
Expand Down Expand Up @@ -1168,8 +1180,9 @@ static bool RenderThing(DrawThing *dthing, bool solid)
ModelDefinition *md = GetModel(mo->state_->sprite);
const Image *skin_img = md->skins_[mo->model_skin_];

if ((mo->visibility_ < 0.99f) || (skin_img && skin_img->opacity_ == kOpacityComplex) || mo->hyper_flags_ & kHyperFlagNoZBufferUpdate)
{
if ((mo->visibility_ < 0.99f) || (skin_img && skin_img->opacity_ == kOpacityComplex) ||
mo->hyper_flags_ & kHyperFlagNoZBufferUpdate)
{
is_solid = false;
}

Expand Down
Loading

0 comments on commit 48ea538

Please sign in to comment.