void Wander::getSteering(SteeringOutput* output) { // Make sure we have a target if (target->squareMagnitude() == 0) { internal_target = character->position; internal_target.x += volatility; } Vector3 offset = *target - character->position; real angle; if (offset.x*offset.x + offset.z*offset.z > 0) { // Work out the angle to the target from the character angle = real_atan2(offset.z, offset.x); } else { // We're on top of the target, move it away a little. angle = 0; } // Move the target to the boundary of the volatility circle. internal_target = character->position; internal_target.x += volatility * real_cos(angle); internal_target.z += volatility * real_sin(angle); // Add the turn to the target internal_target.x += randomBinomial(turnSpeed); internal_target.z += randomBinomial(turnSpeed); Seek::getSteering(output); }
void game_physics_engine::CParticalFakeSpring::UpdateForce( CPartical* pPartical, const real duration ) { if (!pPartical->HasFiniteMass()) { return; } CVector3 position = pPartical->GetPosition(); position -= *m_pAnchor; real gamma = 0.5f * (real_sqrt(4 * m_fSpringConstant - m_fDamping * m_fDamping)); CVector3 c = position * (m_fDamping / (2 * gamma)) + pPartical->GetVelocity() * (1.0f / gamma); CVector3 target = position * real_cos(gamma * duration) + c * real_sin(gamma * duration); target *= real_exp(-0.5f * duration * m_fDamping); CVector3 accel = (target - position) * (1.0f / duration * duration) - pPartical->GetVelocity() * duration; pPartical->AddForce(accel * pPartical->GetMass()); }
Vector3 Location::getOrientationAsVector() const { return Vector3(real_sin(orientation), 0, real_cos(orientation)); }