bool Ned3DObjectManager::interactEnemyTerrain(EnemyObject &enemy, TerrainObject &terrain)
{
  Terrain *terr = terrain.getTerrain();
  if(terr == NULL) return false;

  //test for enemy collision with terrain
  Vector3 enemyPos = enemy.getPosition();
    
  float terrainHeight = terr->getHeight(enemyPos.x,enemyPos.z);
  if (enemyPos.y < terrainHeight)
  {
    enemyPos.y = terrainHeight;
    //enemy.setPPosition(enemyPos);       
    int tmpHndl = gParticle.createSystem("enemyfeatherssplat");
    gParticle.setSystemPos(tmpHndl, enemyPos);

    int thumpSound = gSoundManager.requestSoundHandle("Thump.wav");
    int instance = gSoundManager.requestInstance(thumpSound);
     if(thumpSound != SoundManager::NOINSTANCE)
  {
    gSoundManager.setPosition(thumpSound,instance,enemyPos);
    gSoundManager.play(thumpSound,instance);
    gSoundManager.releaseInstance(thumpSound,instance);
  }
    
    enemy.killObject();

    return true;
  }
  return false;
}
bool Ned3DObjectManager::interactCrowTerrain(CrowObject &crow, TerrainObject &terrain)
{
  Terrain *terr = terrain.getTerrain();
  if(terr == NULL) return false;

  //test for crow collision with terrain
  Vector3 crowPos = crow.getPosition();
    
  float terrainHeight = terr->getHeight(crowPos.x,crowPos.z);
  if (crowPos.y < terrainHeight)
  {
    crowPos.y = terrainHeight;
    crow.setPosition(crowPos);       
    int tmpHndl = gParticle.createSystem("crowfeatherssplat");
    gParticle.setSystemPos(tmpHndl, crowPos);

    int thumpSound = gSoundManager.requestSoundHandle("Thump.wav");
    int instance = gSoundManager.requestInstance(thumpSound);
     if(thumpSound != SoundManager::NOINSTANCE)
  {
    gSoundManager.setPosition(thumpSound,instance,crowPos);
    gSoundManager.play(thumpSound,instance);
    gSoundManager.releaseInstance(thumpSound,instance);
  }
    
    crow.killObject();

    return true;
  }
  return false;
}
bool Ned3DObjectManager::interactPlaneTerrain(PlaneObject &plane, TerrainObject &terrain)
{
  Terrain *terr = terrain.getTerrain();
  if(terr == NULL) return false;

  //test for plane collision with terrain
  Vector3 planePos = plane.getPosition();
  EulerAngles planeOrient = plane.getOrientation();
  Vector3 disp = planePos - disp;
  RotationMatrix planeMatrix;
  planeMatrix.setup(plane.getOrientation()); // get plane's orientation

  float planeBottom = plane.getBoundingBox().min.y;
  float terrainHeight = terr->getHeight(planePos.x,planePos.z);
  if(plane.isPlaneAlive() && planeBottom < terrainHeight)
  { //collision
    Vector3 viewVector = planeMatrix.objectToInertial(Vector3(0,0,1));
    if(viewVector * terr->getNormal(planePos.x,planePos.z) < -0.5f // dot product
      || plane.isCrashing())
    { 
      plane.killPlane();
      int partHndl = gParticle.createSystem("planeexplosion");
      gParticle.setSystemPos(partHndl, plane.getPosition());
      int boomHndl = gSoundManager.requestSoundHandle("Boom.wav");
      int boomInst = gSoundManager.requestInstance(boomHndl);
      if(boomInst != SoundManager::NOINSTANCE)
      {
        gSoundManager.setPosition(boomHndl,boomInst,plane.getPosition());
        gSoundManager.play(boomHndl,boomInst);
        gSoundManager.releaseInstance(boomHndl,boomInst);
      }
      plane.setSpeed(0.0f);
      planePos += 2.0f * viewVector;
      planeOrient.pitch = kPi / 4.0f;
      planeOrient.bank = kPi / 4.0f;
      plane.setOrientation(planeOrient);
    }
    else planePos.y = terrainHeight + planePos.y - planeBottom;
    //plane.setPPosition(planePos);
    return true;
  }
  return false;
}