Skip to content

Commit

Permalink
fixed RayTest calls to use the fps ray distances
Browse files Browse the repository at this point in the history
Also fixed a minor bug with how grenade radius was being added to classic instead of fps ray distance.  Not sure this will make any noticeable difference but it should be a faster calculation since it searches a smaller volume on each frame.
  • Loading branch information
tra committed Jul 2, 2024
1 parent 367e11e commit f9997af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/game/CGrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ void CGrenade::FrameAction() {
// | /
// |G <- approaching wall at 45° needs sqrt(2)*radius to intersect wall... lower angles might pass collision instead
static Fixed addRad = sqrt(2)*partList[0]->enclosureRadius;
Fixed classicRayLength = NormalizeVector(3, rayHit.direction) + addRad;
rayHit.distance = classicRayLength;
// use the smaller FPS-scaled rayLength to search a much smaller volume
Fixed rayLength = FpsCoefficient2(NormalizeVector(3, rayHit.direction)) + addRad;
rayHit.distance = rayLength;
RayTestWithGround(&rayHit, kSolidBit);

// if the grenade path (ray test) intersects with an object during this frame
Fixed classicRayDistance = ClassicCoefficient2(rayHit.distance);
if (classicRayLength > classicRayDistance) {
if (rayLength > rayHit.distance) {
// scale distance up to Classic so it's backed out properly when adding to location
Fixed classicRayDistance = ClassicCoefficient2(rayHit.distance);
speed[0] = FMul(rayHit.direction[0], classicRayDistance);
speed[1] = FMul(rayHit.direction[1], classicRayDistance);
speed[2] = FMul(rayHit.direction[2], classicRayDistance);
Expand Down
4 changes: 2 additions & 2 deletions src/game/CSmart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ if (IsClassicInterval()) { // indented like this because hope to remove it in th
rayHit.closestHit = NULL;

rayHit.distance = NormalizeVector(3, rayHit.direction);

realSpeed = rayHit.distance;
rayHit.distance = FpsCoefficient2(rayHit.distance);

RayTestWithGround(&rayHit, kSolidBit);

Expand All @@ -336,7 +336,7 @@ if (IsClassicInterval()) { // indented like this because hope to remove it in th
}

if (rayHit.closestHit) {
realSpeed = rayHit.distance;
realSpeed = ClassicCoefficient2(rayHit.distance);
speed[0] = FMul(rayHit.direction[0], realSpeed);
speed[1] = FMul(rayHit.direction[1], realSpeed);
speed[2] = FMul(rayHit.direction[2], realSpeed);
Expand Down

0 comments on commit f9997af

Please sign in to comment.