mirror of
https://github.com/DrBeef/Raze.git
synced 2025-02-16 17:01:39 +00:00
- SW: cleaned up SlopeBounce and fixed some bad math.
This commit is contained in:
parent
2e35d6a6a8
commit
ae6af08cf1
1 changed files with 8 additions and 22 deletions
|
@ -8287,7 +8287,7 @@ void WallBounce(DSWActor* actor, DAngle ang)
|
||||||
bool SlopeBounce(DSWActor* actor, bool* hit_wall)
|
bool SlopeBounce(DSWActor* actor, bool* hit_wall)
|
||||||
{
|
{
|
||||||
double hiz, loz;
|
double hiz, loz;
|
||||||
int slope;
|
double slope;
|
||||||
|
|
||||||
auto hit_sector = actor->user.coll.hitSector;
|
auto hit_sector = actor->user.coll.hitSector;
|
||||||
|
|
||||||
|
@ -8299,48 +8299,34 @@ bool SlopeBounce(DSWActor* actor, bool* hit_wall)
|
||||||
if (!(hit_sector->ceilingstat & CSTAT_SECTOR_SLOPE))
|
if (!(hit_sector->ceilingstat & CSTAT_SECTOR_SLOPE))
|
||||||
slope = 0;
|
slope = 0;
|
||||||
else
|
else
|
||||||
slope = hit_sector->ceilingheinum;
|
slope = hit_sector->ceilingheinum / SLOPEVAL_FACTOR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!(hit_sector->floorstat & CSTAT_SECTOR_SLOPE))
|
if (!(hit_sector->floorstat & CSTAT_SECTOR_SLOPE))
|
||||||
slope = 0;
|
slope = 0;
|
||||||
else
|
else
|
||||||
slope = hit_sector->floorheinum;
|
slope = hit_sector->floorheinum / SLOPEVAL_FACTOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!slope)
|
if (!slope)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// if greater than a 45 degree angle
|
// if greater than a 45 degree angle
|
||||||
if (abs(slope) > SLOPEVAL_FACTOR)
|
*hit_wall = (abs(slope) > 1);
|
||||||
*hit_wall = true;
|
|
||||||
else
|
|
||||||
*hit_wall = false;
|
|
||||||
|
|
||||||
// get angle of the first wall of the sector
|
// get angle of the first wall of the sector
|
||||||
auto wallp = hit_sector->walls.Data();
|
auto wallp = hit_sector->walls.Data();
|
||||||
DAngle daang = wallp->delta().Angle();
|
auto angle = wallp->delta().Angle();
|
||||||
|
|
||||||
// k is now the slope of the ceiling or floor
|
// k is now the slope of the ceiling or floor
|
||||||
|
|
||||||
// normal vector of the slope
|
// normal vector of the slope
|
||||||
double dax = slope * daang.Sin();
|
DVector3 normal(slope * angle.Sin(), slope * -angle.Cos(), 1);
|
||||||
double day = slope * -daang.Cos();
|
|
||||||
double daz = 256; // 4096/256 = 45 degrees
|
|
||||||
|
|
||||||
// reflection code
|
// reflection code
|
||||||
double k = actor->user.change.X * dax + actor->user.change.Y * day + actor->user.change.Z * daz;
|
double k = actor->user.change.dot(normal) / normal.LengthSquared();
|
||||||
double l = (dax * dax) + (day * day) + (daz * daz);
|
actor->user.change -= k * normal;
|
||||||
|
|
||||||
k /= l;
|
|
||||||
|
|
||||||
actor->user.change.X = dax * k;
|
|
||||||
actor->user.change.Y = day * k;
|
|
||||||
actor->user.change.Z = daz * k * 16;
|
|
||||||
|
|
||||||
SetAngleFromChange(actor);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue