void BallLocalizer::Ball::updateVisible(float newX, float newY, float dt) { double currentTime = Util::millitime(); double timeSinceLastUpdate = currentTime - updatedTime; if (timeSinceLastUpdate <= Config::velocityUpdateMaxTime) { float newVelocityX = (newX - x) / dt; float newVelocityY = (newY - y) / dt; if (Math::abs(newVelocityX) <= Config::objectMaxVelocity && Math::abs(newVelocityY) <= Config::objectMaxVelocity) { velocityX = newVelocityX; velocityY = newVelocityY; } else applyDrag(dt); } else applyDrag(dt); x = newX; y = newY; updatedTime = currentTime; visible = true; if (removeTime != -1 && resurrectable) removeTime = -1; }
void BallLocalizer::Ball::updateInvisible(float dt) { x += velocityX * dt; y += velocityY * dt; applyDrag(dt); visible = false; }
void Racer::applyForces(float seconds) { hkVector4 aVel, vel = body->getLinearVelocity(); float dot = vel.dot3(vel); aVel = body->getAngularVelocity(); float aDot = aVel.dot3(aVel); // Only want to be automatically braking if the player // isn't trying to move or already moving if (((dot > 0.0f) && (dot < 6.0f) && (aDot != 0.0f)) && (currentAcceleration == 0.0f)) { brake(seconds); } else { applyFriction(seconds); } applyTireRaycast(); applySprings(seconds); applyDrag(seconds); if (laserTime > 0.0f) { laserTime -= seconds; } if (respawnTimer > 0.0f) { respawnTimer -= seconds; SmokeParticle* smoke = new SmokeParticle(); hkVector4 pos = body->getPosition(); smoke->setPosition(&pos); SmokeSystem::system->addSmoke(ROCKET_SMOKE, smoke); smoke = NULL; } else if (!respawned && (respawnTimer <= 0.0f)) { respawnTimer = 0.0f; respawned = true; respawn(); } }