MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / getHitCorrection

Method getHitCorrection

src/clientbase/Player.cpp:1692–1908  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1690
1691
1692bool Player::getHitCorrection(const fvec3& startPos, const float startAzimuth,
1693 const fvec3& /*endPos*/, const float /*endAzimuth*/,
1694 const fvec3& startVelocity, double dt,
1695 float groundLimit, fvec3& velocity, fvec3& position,
1696 float* azimuth) {
1697 // constants
1698 static const float MinSearchStep = 0.0001f;
1699 static const int MaxSearchSteps = 7;
1700 static const int MaxSteps = 4;
1701 static const float TinyDistance = 0.0001f;
1702
1703 fvec3 newPos;
1704 fvec3 newVelocity;
1705 float newAzimuth;
1706 float newAngVel;
1707 bool hitWall;
1708 const Obstacle* obstacle;
1709 bool expel;
1710 float timeStep = (float)dt;
1711
1712 newPos = startPos;
1713 newVelocity = startVelocity;
1714 newAngVel = state.angVel;
1715 newAzimuth = startAzimuth;
1716 hitWall = false;
1717
1718 bool phased = !isSolid();
1719
1720 for (int numSteps = 0; numSteps < MaxSteps; numSteps++) {
1721 // record position at beginning of time step
1722 fvec3 tmpPos;
1723 float tmpAzimuth;
1724 tmpAzimuth = newAzimuth;
1725 tmpPos = newPos;
1726
1727 // get position at end of time step
1728 newAzimuth = tmpAzimuth + timeStep * newAngVel;
1729 newPos = tmpPos + (timeStep * newVelocity);
1730 if ((newPos.z < groundLimit) && (newVelocity.z < 0)) {
1731 // Hit lower limit, stop falling
1732 newPos.z = groundLimit;
1733 if ((state.status & PlayerState::Exploding) != 0) {
1734 // tank pieces reach the ground, friction
1735 // stop them, & mainly player view
1736 newPos.x = tmpPos.x;
1737 newPos.y = tmpPos.y;
1738 }
1739 }
1740
1741 // see if we hit anything. if not then we're done.
1742 obstacle = getHitBuilding(tmpPos, tmpAzimuth, newPos, newAzimuth,
1743 phased, expel);
1744
1745 if (!obstacle || !expel) {
1746 break;
1747 }
1748
1749 static BZDB_float maxBumpHeight(BZDBNAMES.MAXBUMPHEIGHT);

Callers

nothing calls this directly

Calls 8

moveFunction · 0.85
getStatusFunction · 0.85
getTopNeighborMethod · 0.80
getPositionMethod · 0.45
getHeightMethod · 0.45
isFlatTopMethod · 0.45
getTypeIDMethod · 0.45
getNormalMethod · 0.45

Tested by

no test coverage detected