Esempio n. 1
0
bool CMVEBounce::GetValue(int frame, zeus::CVector3f& pVel, zeus::CVector3f& pPos) const
{
    if (!x14_planePrecomputed)
    {
        /* Compute Hesse normal form of plane (for penetration testing) */
        x8_planeNormal->GetValue(frame, ((zeus::CVector3f&)x18_planeValidatedNormal));
        ((zeus::CVector3f&)x18_planeValidatedNormal).normalize();

        zeus::CVector3f a;
        x4_planePoint->GetValue(frame, a);

        (float&)(x24_planeD) = x18_planeValidatedNormal.dot(a);
    }

    float dot = x18_planeValidatedNormal.dot(pPos);
    if ((dot - x24_planeD) <= 0.0f)
    {
        if (x15_dieOnPenetrate)
            return true;
    }
    else
        return false;

    /* Deflection event */

    if (pVel.magSquared() > 0.0f)
        return false;

    zeus::CVector3f delta = pPos - pVel;
    pPos += zeus::CVector3f{(-((((delta.z * ((delta.x * (delta.y * x18_planeValidatedNormal.y))
                                             + ((pVel.x * (x18_planeValidatedNormal.y * pVel.y)) + x18_planeValidatedNormal.x))) + x18_planeValidatedNormal.z) - x24_planeD)) /
                             ((pVel.z * ((pVel.x * (x18_planeValidatedNormal.y * pVel.y)) + x18_planeValidatedNormal.x)) + x18_planeValidatedNormal.z)) - (
                (x18_planeValidatedNormal.z * ((x18_planeValidatedNormal.x * (x18_planeValidatedNormal.y * pVel.y)) + pVel.x)) +  pVel.z)} * pVel;

    float d = 0.0f;
    x10_restitution->GetValue(frame, d);
    pVel -= d * pVel;

    float c = 0.0f;
    xc_friction->GetValue(frame, c);
    pVel -= zeus::CVector3f{(1.0f + c) * ((x18_planeValidatedNormal.z * (x18_planeValidatedNormal.x * (x18_planeValidatedNormal.y * pVel.y)) + pVel.x) + pVel.x)} * x18_planeValidatedNormal;
    return false;
}
Esempio n. 2
0
void do_sound_event(std::pair<u16, CSfxHandle>& sfxHandle, float& pitch, bool doPitchBend, u32 soundId, float weight,
                    u32 flags, float falloff, float maxDist, float minVol, float maxVol,
                    const zeus::CVector3f& posToCam, const zeus::CVector3f& pos, TAreaId aid, CStateManager& mgr) {
  if (posToCam.magSquared() >= maxDist * maxDist)
    return;

  u16 useSfxId = CSfxManager::TranslateSFXID(u16(soundId));
  u32 useFlags = 0x1; // Continuous parameter update
  if ((flags & 0x8) != 0)
    useFlags |= 0x8; // Doppler effect
  bool useAcoustics = (flags & 0x80) == 0;

  CAudioSys::C3DEmitterParmData parms;
  parms.x0_pos = pos;
  parms.xc_dir = zeus::skUp;
  parms.x18_maxDist = maxDist;
  parms.x1c_distComp = falloff;
  parms.x20_flags = useFlags;
  parms.x24_sfxId = useSfxId;
  parms.x26_maxVol = maxVol;
  parms.x27_minVol = minVol;
  parms.x28_important = false;
  parms.x29_prio = 0x7f;

  if (mgr.GetActiveRandom()->Float() <= weight) {
    if ((soundId & 0x80000000) != 0) {
      if (!sfxHandle.second) {
        CSfxHandle hnd;
        if ((soundId & 0x40000000) != 0)
          hnd = CSfxManager::SfxStart(useSfxId, 1.f, 0.f, true, 0x7f, true, aid);
        else
          hnd = CSfxManager::AddEmitter(parms, useAcoustics, 0x7f, true, aid);
        if (hnd) {
          sfxHandle.first = useSfxId;
          sfxHandle.second = hnd;
          if (doPitchBend)
            CSfxManager::PitchBend(hnd, pitch);
        }
      } else {
        if (sfxHandle.first == useSfxId) {
          CSfxManager::UpdateEmitter(sfxHandle.second, parms.x0_pos, parms.xc_dir, parms.x26_maxVol);
        } else if ((flags & 0x4) != 0) // Pausable
        {
          CSfxManager::RemoveEmitter(sfxHandle.second);
          CSfxHandle hnd = CSfxManager::AddEmitter(parms, useAcoustics, 0x7f, true, aid);
          if (hnd) {
            sfxHandle.first = useSfxId;
            sfxHandle.second = hnd;
            if (doPitchBend)
              CSfxManager::PitchBend(hnd, pitch);
          }
        }
      }
    } else {
      CSfxHandle hnd;
      if ((soundId & 0x40000000) != 0)
        hnd = CSfxManager::SfxStart(useSfxId, 1.f, 0.f, true, 0x7f, false, aid);
      else
        hnd = CSfxManager::AddEmitter(parms, useAcoustics, 0x7f, false, aid);
      if (doPitchBend)
        CSfxManager::PitchBend(hnd, pitch);
    }
  }
}