コード例 #1
0
ファイル: test_hash2D.cpp プロジェクト: ezhangle/vcglib-1
void RandomSeg(vcg::Point2<MyScalarType> &P0,
                vcg::Point2<MyScalarType> &P1,
                MyScalarType SpaceSize=100,
                MyScalarType maxdim=1)
{

    P0=RandomPoint(SpaceSize);
    vcg::Point2<MyScalarType> D=RandomPoint(SpaceSize);
    D.Normalize();
    D*=maxdim;
    P1=P0+D;
}
コード例 #2
0
ファイル: world.cpp プロジェクト: budokaii/ozifi
void TWorld::GeneratePlayerPlanets() {
    for (size_t i = 0; i < (size_t)Players.size(); ++i) {
        QPointF point = RandomPoint();
        while (!IsPossiblePlanetPosition(point, PLAYER_PLANET_RADIUS, MINIMUM_PLAYER_PLANET_DISTANCE)) {
            point = RandomPoint();
        }
        TPlanet planet;
        planet.Id = Planets.size();
        planet.Position = point;
        planet.PlayerId = Players[i].Id;
        planet.Energy = PLAYER_PLANET_ENERGY;
        planet.Radius = PLAYER_PLANET_RADIUS;
        Planets[planet.Id] = planet;
    }
}
コード例 #3
0
ファイル: IsingMC.cpp プロジェクト: jjdredd/IsingQt
void IsingMC::Step() {

	unsigned i, j;

	while (true) {
		RandomPoint(i, j);

		double de = EnergyDiff(i, j);

		// {
		// 	double E_1 = Energy();
		// 	Lattice[i][j] = -Lattice[i][j];
		// 	de = Energy() - E_1;
		// 	Lattice[i][j] = -Lattice[i][j];
		// }

		if (de < 0
		    || ((static_cast<double> (random()) / RAND_MAX)
			< exp(-beta * de) ) ) {

			Lattice[i][j] = -Lattice[i][j];
			return;
		}
	}
}
コード例 #4
0
ファイル: EnvBeam.cpp プロジェクト: xxauroraxx/Source.Python
//-----------------------------------------------------------------------------
// Purpose: Think function for striking at intervals.
//-----------------------------------------------------------------------------
void CEnvBeam::StrikeThink( void )
{
	if ( m_life != 0 )
	{
		if ( m_spawnflags & SF_BEAM_RANDOM )
			SetNextThink( gpGlobals->curtime + m_life + random->RandomFloat( 0, m_restrike ) );
		else
			SetNextThink( gpGlobals->curtime + m_life + m_restrike );
	}
	m_active = 1;

	if (!m_iszEndEntity)
	{
		if (!m_iszStartEntity)
		{
			RandomArea( );
		}
		else
		{
			CBaseEntity *pStart = RandomTargetname( STRING(m_iszStartEntity) );
			if (pStart != NULL)
			{
				RandomPoint( pStart->GetAbsOrigin() );
			}
			else
			{
				Msg( "env_beam: unknown entity \"%s\"\n", STRING(m_iszStartEntity) );
			}
		}
		return;
	}

	Strike();
}
コード例 #5
0
ファイル: test_hash2D.cpp プロジェクト: ezhangle/vcglib-1
void TestClosest(int num_test=100000,
                  MyScalarType SpaceSize=100)
{

    int numWrong=0;
    for (int i=0;i<num_test;i++)
    {
        vcg::Point2<MyScalarType> P0=RandomPoint(SpaceSize);

        vcg::Point2<MyScalarType> closest0;
        MySegmentType* result0=GetClosestSegment(P0,closest0);

        vcg::Point2<MyScalarType> closest1;
        MySegmentType* result1=GetClosesestSegmentBruteF(P0,closest1);


        if (result0!=result1)
        {
            numWrong++;
            printf("D0 %5.5f  \n",(closest0-P0).Norm());
            printf("D1 %5.5f  \n",(closest1-P0).Norm());
            fflush(stdout);
        }
    }
    printf("WRONG TESTS CLOSEST %d ON %d \n",numWrong,num_test);
    fflush(stdout);
}
コード例 #6
0
ファイル: world.cpp プロジェクト: budokaii/ozifi
void TWorld::GenerateRandomPlanets() {
    size_t planetsNumber = PLANETS_MIN_NUMBER + rand() % (PLANETS_MAX_NUMBER - PLANETS_MIN_NUMBER);
    for (size_t i = 0; i < planetsNumber; ++i) {
        QPointF point = RandomPoint();
        float radius = PLANET_MIN_RADIUS + rand() % size_t(PLANET_MAX_RADIUS - PLANET_MIN_RADIUS);
        while (!IsPossiblePlanetPosition(point, radius, MINIMUM_PLANET_DISTANCE)) {
            point = RandomPoint();
            radius = PLANET_MIN_RADIUS + rand() % size_t(PLANET_MAX_RADIUS - PLANET_MIN_RADIUS);
        }
        TPlanet planet;
        planet.Id = Planets.size();
        planet.Position = point;
        planet.PlayerId = -1;
        planet.Energy = PLANET_MIN_ENERGY + rand() % size_t(PLANET_MAX_ENERGY - PLANET_MIN_ENERGY);
        planet.Radius = radius;
        Planets[planet.Id] = planet;
    }
}
コード例 #7
0
ファイル: test_hash2D.cpp プロジェクト: ezhangle/vcglib-1
void TestRay(int num_test=100000,
             MyScalarType SpaceSize=100)
{
    int numWrong=0;
    int NUll0=0;
    int NUll1=0;
    for (int i=0;i<num_test;i++)
    {
        vcg::Point2<MyScalarType> P0=RandomPoint(SpaceSize);
        vcg::Point2<MyScalarType> P1=RandomPoint(SpaceSize);
        vcg::Point2<MyScalarType> Orig=P0;
        vcg::Point2<MyScalarType> Dir=P1-P0;
        Dir.Normalize();

        MyRayType r(Orig,Dir);

        vcg::Point2<MyScalarType> closest0;
        MySegmentType* result0=DoRay(r,closest0);

        vcg::Point2<MyScalarType> closest1;
        MySegmentType* result1=DoRayBruteF(r,closest1);


        if (result0!=result1)
        {
            numWrong++;
//            printf("D0 %5.5f  \n",(closest0-P0).Norm());
//            printf("D1 %5.5f  \n",(closest1-P0).Norm());
//            fflush(stdout);
        }
        if (result0==NULL) NUll0++;
        if (result1==NULL) NUll1++;
    }
    printf("WRONG TESTS DORAY %d ON %d \n",numWrong,num_test);
    printf("NULL0 %d \n",NUll0);
    printf("NULL1 %d \n",NUll1);
    fflush(stdout);
}
コード例 #8
0
ファイル: test_hash2D.cpp プロジェクト: ezhangle/vcglib-1
void TestBox(int num_test=100000,
             MyScalarType SpaceSize=100)
{
    int numWrong=0;

    for (int i=0;i<num_test;i++)
    {
        vcg::Point2<MyScalarType> P0=RandomPoint(SpaceSize);
        vcg::Point2<MyScalarType> P1=RandomPoint(SpaceSize);
        vcg::Box2<MyScalarType> bbox;
        bbox.Add(P0);
        bbox.Add(P1);
        std::vector<MySegmentType*> result0;
        GetInBoxSegments(bbox,result0);

        std::vector<MySegmentType*> result1;
        GetInBoxSegmentsBruteF(bbox,result1);

        std::sort(result0.begin(),result0.end());
        std::sort(result1.begin(),result1.end());

        std::vector<MySegmentType*>::iterator new_end=std::unique(result1.begin(),result1.end());
        int dist=distance(result1.begin(),new_end);
        result1.resize(dist);

        if (result0.size()!=result1.size())numWrong++;

        for (size_t j = 0; j < result0.size(); j++)
            if (result0[j] != result1[j])
            {
                numWrong++;
            }
    }
    printf("WRONG TESTS BBOX %d ON %d \n",numWrong,num_test);
    fflush(stdout);
}
コード例 #9
0
void CLightning::StrikeThink( void )
{
	if ( m_life != 0 )
	{
		if ( pev->spawnflags & SF_BEAM_RANDOM )
			pev->nextthink = gpGlobals->time + m_life + RANDOM_FLOAT( 0, m_restrike );
		else
			pev->nextthink = gpGlobals->time + m_life + m_restrike;
	}
	m_active = 1;

	if (FStringNull(m_iszEndEntity))
	{
		if (FStringNull(m_iszStartEntity))
		{
			RandomArea( );
		}
		else
		{
			CBaseEntity *pStart = RandomTargetname( STRING(m_iszStartEntity) );
			if (pStart != NULL)
				RandomPoint( pStart->pev->origin );
			else
				ALERT( at_console, "env_beam: unknown entity \"%s\"\n", STRING(m_iszStartEntity) );
		}
		return;
	}

	CBaseEntity *pStart = RandomTargetname( STRING(m_iszStartEntity) );
	CBaseEntity *pEnd = RandomTargetname( STRING(m_iszEndEntity) );

	if ( pStart != NULL && pEnd != NULL )
	{
		if ( IsPointEntity( pStart ) || IsPointEntity( pEnd ) )
		{
			if ( pev->spawnflags & SF_BEAM_RING)
			{
				// don't work
				return;
			}
		}
		MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
			if ( IsPointEntity( pStart ) || IsPointEntity( pEnd ) )
			{
				if ( !IsPointEntity( pEnd ) )	// One point entity must be in pEnd
				{
					CBaseEntity *pTemp;
					pTemp = pStart;
					pStart = pEnd;
					pEnd = pTemp;
				}
				if ( !IsPointEntity( pStart ) )	// One sided
				{
					WRITE_BYTE( TE_BEAMENTPOINT );
					WRITE_SHORT( pStart->entindex() );
					WRITE_COORD( pEnd->pev->origin.x);
					WRITE_COORD( pEnd->pev->origin.y);
					WRITE_COORD( pEnd->pev->origin.z);
				}
				else
				{
					WRITE_BYTE( TE_BEAMPOINTS);
					WRITE_COORD( pStart->pev->origin.x);
					WRITE_COORD( pStart->pev->origin.y);
					WRITE_COORD( pStart->pev->origin.z);
					WRITE_COORD( pEnd->pev->origin.x);
					WRITE_COORD( pEnd->pev->origin.y);
					WRITE_COORD( pEnd->pev->origin.z);
				}


			}
			else
			{
				if ( pev->spawnflags & SF_BEAM_RING)
					WRITE_BYTE( TE_BEAMRING );
				else
					WRITE_BYTE( TE_BEAMENTS );
				WRITE_SHORT( pStart->entindex() );
				WRITE_SHORT( pEnd->entindex() );
			}

			WRITE_SHORT( m_spriteTexture );
			WRITE_BYTE( m_frameStart ); // framestart
			WRITE_BYTE( (int)pev->framerate); // framerate
			WRITE_BYTE( (int)(m_life*10.0) ); // life
			WRITE_BYTE( m_boltWidth );  // width
			WRITE_BYTE( m_noiseAmplitude );   // noise
			WRITE_BYTE( (int)pev->rendercolor.x );   // r, g, b
			WRITE_BYTE( (int)pev->rendercolor.y );   // r, g, b
			WRITE_BYTE( (int)pev->rendercolor.z );   // r, g, b
			WRITE_BYTE( pev->renderamt );	// brightness
			WRITE_BYTE( m_speed );		// speed
		MESSAGE_END();
		DoSparks( pStart->pev->origin, pEnd->pev->origin );
		if ( pev->dmg > 0 )
		{
			TraceResult tr;
			UTIL_TraceLine( pStart->pev->origin, pEnd->pev->origin, dont_ignore_monsters, NULL, &tr );
			BeamDamageInstant( &tr, pev->dmg );
		}
	}
}
コード例 #10
0
ファイル: Main.cpp プロジェクト: a1502020/hello-siv3d
void Main()
{
	Chiritori me;
	std::list<Circle> trash;
	Color trashCol = { 200, 200, 200, 255 };
	int32 score = 0;
	Font font(20);

	while (System::Update())
	{
		Vec2 angle(cos(me.angle), sin(me.angle));

		// ゴミ出現
		if (RandomBool(1.0 / 50)) {
			Point p = RandomPoint({ 15, 15, Window::Width() - 15, Window::Height() - 15 });
			trash.push_back(Circle(p, 15));
		}

		// 操作
		if (Input::KeySpace.pressed) {
			me.pos.x += me.v * angle.x;
			me.pos.y += me.v * angle.y;
			if (me.pos.y - me.r < 0 || me.pos.y + me.r >= Window::Height()) {
				me.angle = -me.angle;
			}
			if (me.pos.x - me.r < 0 || me.pos.x + me.r >= Window::Width()) {
				me.angle = Pi - me.angle;
			}
		}
		else {
			me.angle += me.angleV;
		}

		// ゴミ回収
		for (auto it = trash.begin(); it != trash.end(); ) {
			if (Circle(me.pos, me.r).intersects(*it)) {
				it = trash.erase(it);
				++score;
			}
			else {
				++it;
			}
		}

		// ゴミ増えすぎどっかーん
		if (trash.size() >= 30) {
			trash.clear();
			score = 0;
			me = Chiritori();
		}

		// 描画
		uint32 bk = 0;
		if (trash.size() > 20) {
			bk = (trash.size() - 20) * 25;
		}
		Graphics::SetBackground({ bk, bk, 0, 255 });
		Circle(me.pos, me.r).draw(me.color);
		Circle({ me.pos.x + me.r * 0.6 * angle.x, me.pos.y + me.r * 0.6 * angle.y }, me.r * 0.2).draw({ 255, 255, 255, 255 });
		for each (Circle c in trash)
		{
			c.draw(trashCol);
		}
		font(ToString(score)).draw();
	}
コード例 #11
0
ファイル: MathMiser.cpp プロジェクト: ernfrid/polymutt
double MathMiser::Integrate(Matrix & volume)
   {
   double average = 0.0, variance = 0.0;
   unsigned long seed = 0;

   sobol.Init(volume.cols);

   midpoint.Dimension(volume.cols);
   point.Dimension(volume.cols);
   minl.Dimension(volume.cols);
   minr.Dimension(volume.cols);
   maxl.Dimension(volume.cols);
   maxr.Dimension(volume.cols);

   stack[0].points = ncall;
   stack[0].weight = 1.0;
   stack[0].region = volume;

   for (int ptr = 1; ptr--; )
      {
      MiserStack & top = stack[ptr];

      // If very few points are left do straight MC over the region
      if (top.points < MINNODE)
         {
         double sum = 0.0, sum2 = 0.0;
         for (int n = 0; n < top.points; n++)
            {
            RandomPoint(top.region, point);
            double fval = func(point);
            sum += fval;
            sum2 += fval * fval;
            }
         average += top.weight * sum / top.points;
         variance += (top.weight * top.weight) *
            max(0.0, (sum2 - sum*sum/top.points) / (top.points * top.points));
         continue;
         }

      // Caculate midpoint for the current region
      for (int j = 0; j < midpoint.dim; j++)
         midpoint[j] = 0.5 * (top.region[0][j] + top.region[1][j]);

      // Explore the variance of the function in this region...
      int quota = min(max((int) (top.points * R_D_FRAC), R_D_MIN), R_D_MAX);
      top.points -= quota;

      minr.Set(FPMAX);
      minl.Set(FPMAX);
      maxr.Set(-FPMAX);
      maxl.Set(-FPMAX);

      for (int n = 0; n < quota; n++)
         {
         RandomPoint(top.region, point);
         double fval = func(point);

         for (int j = 0; j < point.dim; j++)
            if (point[j] <= midpoint[j])
               {
               minl[j] = min(minl[j], fval);
               maxl[j] = max(maxl[j], fval);
               }
            else
               {
               minr[j] = min(minr[j], fval);
               maxr[j] = max(maxr[j], fval);
               }
         }

      // Choose the region giving biggest reduction in the variance
      double bestvar = FPMAX, varl;
      int    bestdir = -1;

      for (int j = 0; j < point.dim; j++)
         {
         // have we got two points on each half of the region?
         if (maxl[j] > minl[j] && maxr[j] > minr[j])
            {
            double sigmal = max (TINY, pow(maxl[j] - minl[j], 2.0 / 3.0));
            double sigmar = max (TINY, pow(maxr[j] - minr[j], 2.0 / 3.0));
            double sigma = sigmal + sigmar;
            if (sigma < bestvar)
               {
               bestvar = sigma;
               bestdir = j;
               varl = sigmal;
               }
            }
         }

      if (bestdir == -1) { varl = 1.0; bestdir = RAND(seed) % point.dim; }

      // Divide the remaining points among the two regions
      int pointsl = MINLEAF + int ((top.points - 2*MINLEAF) * varl / bestvar);
      int pointsr = top.points - pointsl;

      // Integrate the two sub regions, starting with the smallest one
      stack[ptr + 1].region = stack[ptr].region;
      stack[ptr + 1].weight = stack[ptr].weight *= 0.5;

      if (pointsl > pointsr)
         {
         stack[ptr].points = pointsl;
         stack[ptr++].region[1][bestdir] = midpoint[bestdir];
         stack[ptr].points = pointsr;
         stack[ptr++].region[0][bestdir] = midpoint[bestdir];
         }
      else
         {
         stack[ptr].points = pointsr;
         stack[ptr++].region[0][bestdir] = midpoint[bestdir];
         stack[ptr].points = pointsl;
         stack[ptr++].region[1][bestdir] = midpoint[bestdir];
         }
      }

   tgral = 1.0;
   for (int j = 0; j < point.dim; j++)
      tgral *= (volume[1][j] - volume[0][j]);

   stdev  = tgral * sqrt(variance);
   tgral *= average;

   return tgral;
   }