Ejemplo n.º 1
0
static double ene_energy_calcul(p3d_rob *robot)
{
  double totE;

  CalculateEnergy(robot,&totE);
  return totE;
}
Ejemplo n.º 2
0
int Ephemeris::CalculateOrbitalElement(const double mu, const Phase *phase, double *a, double *e)
{
    const double sq3 = 1.0e-14;

	// Calculate energy, h
    double h = CalculateEnergy(mu, *phase);
    if (h >= 0.0)
    {
    	Error::_errMsg = "The energy is positive or zero!";
    	Error::PushLocation(__FILE__, __FUNCTION__, __LINE__);
        return 1;
    }
    Vector r = phase->position;
    Vector v = phase->velocity;

    Vector c = Vector::CrossProduct(r, v);
    /*
    * Calculate eccentricity, e
    */
    double e2 = 1.0 + 2.0 * c.LengthSQR() * h / (mu * mu);
    if (abs(e2) < sq3)
    {
        e2 = 0.0;
    }
    *e = sqrt(e2);
    /*
    * Calculate semi-major axis, a
    */
    *a = -mu / (2.0 * h);

    return 0;
}
/*
* This will be the first function called once the skill is determined
* as useable.
*/
bool AWormHole::Use(int TargetID)
{
    long ChargeTime;
    float EnergyCost = CalculateEnergy(m_SkillLevel, m_SkillRank);

    //allow the ability to be turned off
    if(m_InUse)
    {
        m_Player->SetCurrentSkill();
        m_DamageTaken = 0.0f;
        return false;
    }

    // Remove the energy
    m_Player->RemoveEnergy(EnergyCost);

    ChargeTime = (long) CalculateChargeUpTime(m_SkillLevel, m_SkillRank);

    m_EffectID = GetNet7TickCount();

    // Make sure no one else can use this skill
    m_InUse = true;

    EnergyCost = CalculateEnergy(m_SkillLevel, m_SkillRank);

    // not enough energy
    if (m_Player->GetEnergyValue() < EnergyCost)
    {
        SendError("Not enough energy!");
        m_InUse = false;
        m_DamageTaken = 0;
        return false;
    }

    // Cast time
    SetTimer(ChargeTime);

    return true;
}
Ejemplo n.º 4
0
glm::vec3 Integrator::EstimateDirectLighting(const Intersection &isx, unsigned int &samples_taken, const glm::vec3 &woW)
{
    //for Light source sampling
    //QList<glm::vec3> light_sample_pts;
    glm::vec3 color_temp(0,0,0);
    glm::vec3 color_final(0,0,0);
    Intersection light_sample_isx; //randomly sampled intersection on the light source's surface
    glm::vec3 wiW; // incoming ray in world frame
    Ray light_sample_ray;
    float rand1 = unif_distribution(mersenne_generator);
    float rand2 = unif_distribution(mersenne_generator);

    Intersection obstruction_test;

    //iterate through all the light sources
    for (int i = 0; i < scene->lights.count(); i++)
    {
        for(unsigned int j = 0; j < samples_taken; j++)
        {
            light_sample_isx = scene->lights[i]->GetRandISX(rand1, rand2, isx.normal); //take 1 sample point(intersection) on the light source for now
            wiW = light_sample_isx.point - isx.point; //ray direction going from world point to light source
            light_sample_isx.t = glm::length(wiW);
            wiW = glm::normalize(wiW);
            light_sample_ray = Ray(isx.point, wiW);//remember, the direction is from point in scene to light source
            obstruction_test = intersection_engine->GetIntersection(light_sample_ray);
            //update random point
            rand1 = unif_distribution(mersenne_generator);
            rand2 = unif_distribution(mersenne_generator);

            if (obstruction_test.object_hit == scene->lights[i])
            {
                color_temp = color_temp + CalculateEnergy(light_sample_isx, isx, light_sample_ray, woW);
            }
            else
            {
                //the ray contributes zero energy
            }
        }
        color_temp = color_temp/static_cast<float>(samples_taken); //divide by samples taken
        color_final = color_final + color_temp; // accumulate energy per high source
        color_temp = glm::vec3(0, 0, 0);// zero out color_temp for the next light source
    }

    return color_final;
}
/*
* This will be the first function called once the skill is determined
* as useable.
*/
bool ARechargeShields::Use(int TargetID)
{
	float ChargeTime;
	float EnergyCost;

	if(m_InUse)
	{
		InterruptSkillOnAction(WARPING);
		return false;
	}

	if(m_SkillRank >= 3)
	{
		// Target player
		if(TargetID < 0)
		{
			m_PlayerTarget = m_Player;
		}
		else
		{
			m_PlayerTarget = g_PlayerMgr->GetPlayer(TargetID);
		}

		// If we cant find player return
		if (!m_PlayerTarget)
		{
			m_Player->SetCurrentSkill();
			m_DamageTaken = 0;
			return false;
		}
	}

	if(TargetID <= 0)
	{
		m_PlayerTarget = m_Player;
	}

	m_EffectID = GetNet7TickCount();

	// Make sure no one else can use this skill
	m_InUse = true;

	EnergyCost = CalculateEnergy(m_SkillLevel, m_SkillRank);

	// not enough energy
	if (m_Player->GetEnergyValue() < EnergyCost)
	{
		SendError("Not enough energy!");
		m_Player->SetCurrentSkill();
		m_InUse = false;
		m_DamageTaken = 0;
		return false;
	}

	m_Player->RemoveEnergy(EnergyCost);

	ChargeTime = CalculateChargeUpTime(m_SkillLevel, m_SkillRank);

	//charge up, apply shield charge after charge is finished.
	SetTimer((long)ChargeTime*1000);

	ObjectEffect RechargeChargeEffect;

	memset(&RechargeChargeEffect, 0, sizeof(RechargeChargeEffect));		// Zero out memory

	RechargeChargeEffect.Bitmask = 3;
	RechargeChargeEffect.GameID = m_Player->GameID();
	RechargeChargeEffect.TimeStamp = m_EffectID;
	RechargeChargeEffect.EffectID = m_EffectID;
	RechargeChargeEffect.Duration = (short)ChargeTime;
	RechargeChargeEffect.EffectDescID = 733;
	m_Player->SendObjectEffectRL(&RechargeChargeEffect);

	return true;
}
void MinimalizationSimulation(void)
{
  int j,k;
  REAL Drift,ReferenceEnergy,ran;
  int NumberOfSystemMoves,NumberOfParticleMoves,NumberOfSteps;
  int ran_int;

  Drift=0.0;
  ReferenceEnergy=0.0;
  CurrentSystem=0;

  fprintf(stderr, "Starting minimization\n");

  OpenOutputFile();

  //InitializeNoseHooverAllSystems();

  InitializesEnergiesAllSystems();
  InitializesEnergyAveragesAllSystems();

  InitializeSmallMCStatisticsAllSystems();
  InitializeMCMovesStatisticsAllSystems();

  CalculateTotalEnergyAllSystems();

  PrintPreSimulationStatus();

  for(CurrentSystem=0;CurrentSystem<NumberOfSystems;CurrentSystem++)
  {
    for(k=0;k<NumberOfCycles;k++)
    {
      InitializesEnergiesAllSystems();
      InitializesEnergyAveragesAllSystems();
      CalculateTotalEnergyAllSystems();

      for(CurrentCycle=0;CurrentCycle<NumberOfInitializationCycles;CurrentCycle++)
      {
        if((CurrentCycle%PrintEvery)==0)
          PrintIntervalStatusInit(CurrentCycle,NumberOfInitializationCycles,OutputFilePtr[CurrentSystem]);

        NumberOfSystemMoves=12;
        NumberOfParticleMoves=MAX2(MinimumInnerCycles,NumberOfAdsorbateMolecules[CurrentSystem]+NumberOfCationMolecules[CurrentSystem]);
        NumberOfSteps=(NumberOfSystemMoves+NumberOfParticleMoves)*NumberOfComponents;

        for(j=0;j<NumberOfSteps;j++)
        {
          ran_int=(int)(RandomNumber()*NumberOfSteps);
          switch(ran_int)
          {
            case 0:
              if(RandomNumber()<ProbabilityParallelTemperingMove) ParallelTemperingMove();
              break;
            case 1:
              if(RandomNumber()<ProbabilityHyperParallelTemperingMove) HyperParallelTemperingMove();
              break;
            case 2:
              if(RandomNumber()<ProbabilityParallelMolFractionMove) ParallelMolFractionMove();
              break;
            case 3:
              if(RandomNumber()<ProbabilityChiralInversionMove) ChiralInversionMove();
              break;
            case 4:
              if(RandomNumber()<ProbabilityHybridNVEMove) HybridNVEMove();
              break;
            case 5:
              if(RandomNumber()<ProbabilityHybridNPHMove) HybridNPHMove();
              break;
            case 6:
              if(RandomNumber()<ProbabilityHybridNPHPRMove) HybridNPHPRMove();
              break;
            case 7:
              if(RandomNumber()<ProbabilityVolumeChangeMove) VolumeMove();
              break;
            case 8:
              if(RandomNumber()<ProbabilityBoxShapeChangeMove) BoxShapeChangeMove();
              break;
            case 9:
              if(RandomNumber()<ProbabilityGibbsVolumeChangeMove) GibbsVolumeMove();
              break;
            case 10:
              if(RandomNumber()<ProbabilityFrameworkChangeMove) FrameworkChangeMove();
              break;
            case 11:
              if(RandomNumber()<ProbabilityFrameworkShiftMove) FrameworkShiftMove();
              break;
            default:
              // choose component at random
              CurrentComponent=(int)(RandomNumber()*(REAL)NumberOfComponents);

              // choose the Monte Carlo move at random
              ran=RandomNumber();

              if(ran<Components[CurrentComponent].ProbabilityTranslationMove)
                TranslationMove();
              else if(ran<Components[CurrentComponent].ProbabilityRandomTranslationMove)
                RandomTranslationMove();
              else if(ran<Components[CurrentComponent].ProbabilityRotationMove)
                RotationMove();
              else if(ran<Components[CurrentComponent].ProbabilityPartialReinsertionMove)
                PartialReinsertionMove();
              else if(ran<Components[CurrentComponent].ProbabilityReinsertionMove)
                ReinsertionMove();
              else if(ran<Components[CurrentComponent].ProbabilityReinsertionInPlaceMove)
                ReinsertionInPlaceMove();
              else if(ran<Components[CurrentComponent].ProbabilityReinsertionInPlaneMove)
                ReinsertionInPlaneMove();
              else if(ran<Components[CurrentComponent].ProbabilityIdentityChangeMove)
                IdentityChangeMove();
              else if(ran<Components[CurrentComponent].ProbabilitySwapMove)
              {
                if(RandomNumber()<0.5) SwapAddMove();
                else SwapRemoveMove();
              }
              else if(ran<Components[CurrentComponent].ProbabilityWidomMove)
               ;
              else if(ran<Components[CurrentComponent].ProbabilitySurfaceAreaMove)
               ;
              else if(ran<Components[CurrentComponent].ProbabilityGibbsChangeMove)
                GibbsParticleTransferMove();
              else if(ran<Components[CurrentComponent].ProbabilityGibbsIdentityChangeMove)
               GibbsIdentityChangeMove();
          }
        }

        if(CurrentCycle%1000==0)
          OptimizeTranslationAcceptence();
      }

      // do the minimization
      Minimization(k);

      InitializesEnergiesCurrentSystem();
      CalculateEnergy();
      PrintEnergyStatus(OutputFilePtr[CurrentSystem],"minimization full energy");
    }

    PrintRestartFile();
  }

  PrintPostSimulationStatus();
  CloseOutputFile();
}
Ejemplo n.º 7
0
int Ephemeris::CalculateOrbitalElement(double mu, const Phase *phase, OrbitalElement *orbitalElement)
{
    const double sq2 = 1.0e-14;
    const double sq3 = 1.0e-14;

	// Calculate energy, h
    double h = CalculateEnergy(mu, *phase);
    if (h >= 0.0)
    {
    	Error::_errMsg = "The energy is positive or zero";
    	Error::PushLocation(__FILE__, __FUNCTION__, __LINE__);
        return 1;
    }
    Vector r = phase->position;
    Vector v = phase->velocity;

    Vector c = Vector::CrossProduct(r, v);
	Vector l = (-mu / r.Length()) * (r) + Vector::CrossProduct(v, c);
	double rv = Vector::DotProduct(r, v);
    /*
    * Calculate eccentricity, e
    */
    double e2 = 1.0 + 2.0 * c.LengthSQR() * h / (mu * mu);
    if (abs(e2) < sq3)
    {
        e2 = 0.0;
    }
    double e = sqrt(e2);
    /*
    * Calculate semi-major axis, a
    */
    double a = -mu / (2.0 * h);
    /*
    * Calculate inclination, incl
    */
    double cosi = c.z / c.Length();
    double sini = sqrt(c.x * c.x + c.y * c.y) / c.Length();
    double incl = acos(cosi);
    if (incl < sq2)
    {
        incl = 0.0;
    }
    /*
    * Calculate longitude of node, O
    */
    double node = 0.0;
    if (incl != 0.0)
    {
        double tmpx = -c.y / (c.Length() * sini);
        double tmpy = c.x / (c.Length() * sini);
		node = atan2(tmpy, tmpx);
		ShiftIntoRange(0.0, 2.0*Constants::Pi, node);
    }
    /*
    * Calculate argument of pericenter, w
    */
    double E = 0.0;
    double peri = 0.0;
    if (e2 != 0.0)
    {
        double tmpx = (l.x * cos(node) + l.y * sin(node)) / l.Length();
        double tmpy = (-l.x * sin(node) + l.y * cos(node)) / (l.Length() * cosi);
        peri = atan2(tmpy, tmpx);
        ShiftIntoRange(0.0, 2.0*Constants::Pi, peri);

        tmpx = 1.0 / e * (1.0 - r.Length() / a);
        tmpy = rv / (sqrt(mu * a) * e);
        E = atan2(tmpy, tmpx);
        ShiftIntoRange(0.0, 2.0*Constants::Pi, E);
    }
    else
    {
        peri = 0.0;
        E = atan2(r.y, r.x);
        ShiftIntoRange(0, 2.0*Constants::Pi, E);
    }
    /*
    * Calculate mean anomaly, M
    */
    double M = E - e * sin(E);
    ShiftIntoRange(0, 2.0*Constants::Pi, M);

	orbitalElement->semiMajorAxis			= a;
	orbitalElement->eccentricity			= e;
	orbitalElement->inclination				= incl;
	orbitalElement->argumentOfPericenter	= peri;
	orbitalElement->longitudeOfNode			= node;
	orbitalElement->meanAnomaly				= M;

	return 0;
}
Ejemplo n.º 8
0
bool AudioMixerImpl::GetMixerAudio( webrtc::AudioFrame* audioFrame )
{
    if (m_participants.empty())
    {
        return false;
    }
    // 分类
    bool bMix = false;
    for ( auto& v : m_participants )
    {
        auto participant = v.participant;
        auto audioFrame = PopAudioFrame();
        bool ret = participant->GetAudioFrame( audioFrame );
        if ( !ret )
        {
            v.needMixCount = 0;
            v.weightFactor = 0.0f;
            v.audioFrame = nullptr;
            v.energy = 0;
            v.isMixed = false;
            PushAudioFrame( audioFrame );
            continue;
        }
        bMix = true;
        v.energy = CalculateEnergy( audioFrame );
        v.isSilent = audioFrame->vad_activity_ != webrtc::AudioFrame::kVadActive;
        v.audioFrame = audioFrame;
    }
    if (!bMix)
    {
        return false;
    }
    if (m_participants.size() > (uint32_t)m_limitCount)
    {
        m_participants.sort( [] ( MixerParticipantInfo& lhs, MixerParticipantInfo& rhs )
        {
            return (lhs.energy > rhs.energy);
        } );
    }

    MixerParticipantList mixerlist;
    int nMixframeCounter = 0;
    for ( auto it = m_participants.begin(); it != m_participants.end(); ++it )
    {
        if ( m_limitCount >= nMixframeCounter )
        {
            if (it->energy > 0)
            {
                nMixframeCounter++;
                it->needMixCount = 5;
                it->isMixed = true;
                // 这里系数的调整至关重要,目前先简单的处理下
                if (it->isSilent)
                {
                    it->weightFactor = 0.7f;
                }
                else
                {
                    it->weightFactor = 1.0f;
                }
                mixerlist.push_back(*it);
            }
        }
        else
        {
            if (it->isMixed)
            {
                if ( it->needMixCount-- > 0 )
                    it->weightFactor /= 2; // 渐渐淡出

                mixerlist.push_back( *it );
            }
        }
    }

    MixFrameList( mixerlist, audioFrame );
    for ( auto&v : m_participants )
    {
        if ( v.audioFrame )
            PushAudioFrame( v.audioFrame );
    }
    return true;
}