//------------------------------------------------------------------------------ // weaponDynamics -- default dynamics; using Robot Aircraft (RAC) dynamics //------------------------------------------------------------------------------ void Effects::weaponDynamics(const LCreal dt) { // Useful constant static const LCreal g = ETHG * Basic::Distance::FT2M; // Acceleration of Gravity (m/s/s) // --- // Compute & Set acceleration vector (earth) // --- // First drag osg::Vec3 tmp = getVelocity() * (-dragIndex); // then gravity osg::Vec3 ae1 = tmp; ae1[IDOWN] += g; setAcceleration(ae1); // --- // Comute & set new velocity vectory (earth) // --- osg::Vec3 ve1 = getVelocity() + (ae1 * dt); setVelocity(ve1); // --- // .. Only after setVelocity has been called ... // --- LCreal vp = getTotalVelocity(); LCreal vg = getGroundSpeed(); // --- // Set velocity vector (body) // (total velocity is along X) // --- setVelocityBody(vp, 0.0, 0.0); // --- // Sent angular values // --- LCreal newPsi = lcAtan2(ve1[IEAST],ve1[INORTH]); LCreal newTheta = lcAtan2( -ve1[IDOWN], vg ); setEulerAngles(0.0, newTheta, newPsi); setAngularVelocities(0.0, 0.0, 0.0); }
//------------------------------------------------------------------------------ // weaponDynamics() -- Bullet dynamics //------------------------------------------------------------------------------ void Bullet::weaponDynamics(const LCreal dt) { if (isMode(ACTIVE)) { updateBurstTrajectories(dt); checkForTargetHit(); // This weapon is slaved to the first burst! if (nbt > 0) { // We control the position and altitude! setPosition( bursts[0].bPos[0], bursts[0].bPos[1], bursts[0].bPos[2], true ); setVelocity( bursts[0].bVel ); setAcceleration( 0, 0, 0 ); setEulerAngles( 0, 0, getGroundTrack() ); setAngularVelocities( 0, 0, 0 ); setVelocityBody ( bursts[0].bVel.length(), 0, 0 ); } } }
//------------------------------------------------------------------------------ // weaponDynamics -- default missile dynamics; using Robot Aircraft (RAC) dynamics //------------------------------------------------------------------------------ void Missile::weaponDynamics(const LCreal dt) { static const LCreal g = ETHG; // Acceleration of Gravity // --- // Max turning G (Missiles: Use Gmax) // --- LCreal gmax = maxG; // --- // Computer max turn rate, max/min pitch rates // --- // Turn rate base on vp and g,s LCreal ra_max = gmax * g / getTotalVelocity(); // Set max (pull up) pitch rate same as turn rate LCreal qa_max = ra_max; // Set min (push down) pitch rate LCreal qa_min = -qa_max; // --- // Get old angular values // --- const osg::Vec3 oldRates = getAngularVelocities(); //LCreal pa1 = oldRates[IROLL]; LCreal qa1 = oldRates[IPITCH]; LCreal ra1 = oldRates[IYAW]; // --- // Find pitch rate and update pitch // --- LCreal qa = lcAepcRad(cmdPitch - (LCreal) getPitchR()); if(qa > qa_max) qa = qa_max; if(qa < qa_min) qa = qa_min; // Using Pitch rate, integrate pitch LCreal newTheta = (LCreal) (getPitch() + (qa + qa1) * dt / 2.0); // Find turn rate LCreal ra = lcAepcRad(cmdHeading - (LCreal) getHeadingR()); if(ra > ra_max) ra = ra_max; if(ra < -ra_max) ra = -ra_max; // Use turn rate integrate heading LCreal newPsi = (LCreal) (getHeading() + (ra + ra1) * dt / 2.0); if(newPsi > 2.0f*PI) newPsi -= (LCreal)(2.0*PI); if(newPsi < 0.0f) newPsi += (LCreal)(2.0*PI); // Roll angle proportional to max turn rate - filtered LCreal pa = 0.0; LCreal newPhi = (LCreal) ( 0.98 * getRollR() + 0.02 * ((ra / ra_max) * (Basic::Angle::D2RCC * 60.0)) ); // Sent angular values setEulerAngles(newPhi, newTheta, newPsi); setAngularVelocities(pa, qa, ra); // Find Acceleration LCreal vpdot = (cmdVelocity - getTotalVelocity()); if(vpdot > maxAccel) vpdot = maxAccel; if(vpdot < -maxAccel) vpdot = -maxAccel; // Set acceleration vector osg::Vec3 aa(vpdot, 0.0, 0.0); osg::Vec3 ae = aa * getRotMat(); setAcceleration(ae); // Comute new velocity LCreal newVP = getTotalVelocity() + vpdot * dt; // Set acceleration vector osg::Vec3 ve0 = getVelocity(); osg::Vec3 va(newVP, 0.0, 0.0); osg::Vec3 ve1 = va * getRotMat(); setVelocity(ve1); setVelocityBody(newVP, 0.0, 0.0); }