void
FCUTestWindow::onSpeedValueChanged(int newValue)
{
   if (newValue > _speedSpinBox->minimum())
   {
      _fcu->setSpeedValue((_fcu->speedUnits() == Speed::UNITS_KT)
                          ? Speed(newValue)
                          : Speed(newValue / 100.0f, Speed::UNITS_MACH));
   }
}
Exemple #2
0
void Polar::CalculateVMG(int VWi)
{
    SailingWindSpeed &ws = wind_speeds[VWi];
    // limits for port/starboard upwind/downwind
    const double limits[4][2] = {{270, 360}, {0, 90}, {180, 270}, {90, 180}};
    for(int i=0; i<4; i++) {
        double upwind = i < 2 ? 1 : -1;
        double maxVB = 0;
        float maxW = NAN;
        unsigned int maxWi = 0;
        for(unsigned int Wi = 0; Wi < degree_steps.size(); Wi++) {
            double W = degree_steps[Wi];

            if(W < limits[i][0] || W > limits[i][1])
                continue;

            double VB = upwind*cos(deg2rad(W))*ws.speeds[Wi];// original speed before optimizing
            if(VB > maxVB) {
                maxVB = VB;
                maxW = W;
                maxWi = Wi;
            }
        }

        // interpolate the best vmg (as it often lies between entries in the polar
        if(!isnan(maxW)) {
            unsigned int Wi1 = maxWi > 0 ? maxWi - 1 : degree_steps.size() - 1;
            unsigned int Wi2 = maxWi < degree_steps.size() - 1 ? maxWi + 1 : 0;
            double dsmaxWi = degree_steps[maxWi];
            double step = wxMax(fabsf(dsmaxWi - degree_steps[Wi1]),
                                fabsf(dsmaxWi - degree_steps[Wi2])) / 4;

            while(step > 2e-3) {
                double W1 = wxMax(maxW-step, limits[i][0]), W2 = wxMin(maxW+step, limits[i][1]);
                double VB1 = upwind*cos(deg2rad(W1))*Speed(W1, ws.VW);
                double VB2 = upwind*cos(deg2rad(W2))*Speed(W2, ws.VW);

                if(VB1 > VB2)
                    maxW = (W1 + maxW) / 2;
                else
                    maxW = (W2 + maxW) / 2;

                step /= 2;
            }
        }

        ws.VMG.values[i] = maxW;
    }

    // for symmetric polars
    if(degree_steps[degree_steps.size()-1] <= 180) {
        ws.VMG.values[0] = ws.VMG.values[1];
        ws.VMG.values[2] = ws.VMG.values[3];
    }
}
/* instead of traveling in the direction given, allow traveling at angles
   closer to +- 90.  Basically we are trying every two tack angles and combining
   to determine if alternating between these two courses is actually faster than
   the current strategy for the given course, and if so, use it.

   TODO: Make this this work for asymmetrical polars correctly
*/
void BoatPlan::OptimizeTackingSpeed()
{
    for(unsigned int VWi = 0; VWi < wind_speeds.size(); VWi++) {
        CalculateVMG(VWi);
        for(unsigned int Wi = 0; Wi < degree_steps.size(); Wi++) {
            double at = degree_steps[Wi];
            double bt, ct;
            
            if(at > 90 && at < 270) {
                bt = wind_speeds[VWi].VMG.values[SailingVMG::STARBOARD_DOWNWIND];
                ct = wind_speeds[VWi].VMG.values[SailingVMG::PORT_DOWNWIND];
            } else {
                bt = wind_speeds[VWi].VMG.values[SailingVMG::STARBOARD_UPWIND];
                ct = wind_speeds[VWi].VMG.values[SailingVMG::PORT_UPWIND];
            }

            if(isnan(bt) || isnan(ct))
                continue;
            
            SailingWindSpeed::SailingSpeed &a = wind_speeds[VWi].speeds[Wi];
            double b = Speed(bt, wind_speeds[VWi].VW);
            double c = Speed(ct, wind_speeds[VWi].VW);
            
            /* w is the weight between b and c tacks (.5 for equal time on each
               t is the improvement factor]
               bcVB * sin(a) = w*b.VB*sin(b) + (1-w)*c.VB*sin(c)
               bcVB * cos(a) = w*b.VB*cos(b) + (1-w)*c.VB*cos(c) */
            double ar = deg2rad(at);
            double br = deg2rad(bt);
            double cr = deg2rad(ct);
            double sa = sin(ar), ca = cos(ar);
            double sb = sin(br), cb = cos(br);
            double sc = sin(cr), cc = cos(cr);
            double X = ca*sc-sa*cc, Y = sa*cb-ca*sb;
            double d = (X*c + Y*b);
            double w = X*c / d;
            
            if(w > 0 && w < 1) {
                double Z = cb*sc-sb*cc;
                double bcVB = Z*b*c / d;
                if(bcVB > a.VB) {
                    a.VB = bcVB;
                    if(at > 180)
                        a.b = bt, a.c = ct, a.w = w;
                    else
                        a.b = ct, a.c = bt, a.w = (1-w);
                }
            }           
        }
    }
}
Exemple #4
0
double Polar::SpeedAtApparentWindDirection(double A, double VW, double *pW)
{
    int iters = 0;
    double VB = 0, W = A; // initial guess
    double lp = 1;
    for(;;) {
        double cVB = Speed(W, VW);
        VB -= (VB - cVB) * lp;

        double VA = VelocityApparentWind(VB, W, VW);
        double cA = positive_degrees(DirectionApparentWind(VA, VB, W, VW));

        if(isnan(cA) || iters++ > 256) {
            if(pW) *pW = NAN;
            return NAN;
        }

        if(fabs(cA - A) < 2e-2) {
            if(pW) *pW = W;
            return cVB;
        }

        W -= (cA - A) * lp;
        lp *= .97;
    }
}
Exemple #5
0
File_Group::File_Group (void)
{
    Trip_File (NULL);
    Time_File (NULL);
    Trip_Factor (NULL);
    Script_File (NULL);

    Purpose (0);
    Mode (0);
    Method (0);
    Duration (0);
    Type (0);
    SubType (0);
    Org_Wt (0);
    Des_Wt (0);
    Dist_Wt (true);
    Speed (0);
    Time_Field (0);
    Scaling_Factor (1.0);

    period = NULL;
    time_equiv = NULL;
    program = NULL;
    header = NULL;
}
// ------------------------------------------------------------------------------------------------
Uint32 ProjectileBase :: WriteToPacket(Uint32 dataWritePos, Uint8 data[])
{
	Uint32 sendId = Id();
	ProjectileType sendType = Type();
    Vector2df sendPos = Pos();
    Uint32 sendHeadingDeg = HeadingDeg();
    float sendSpeed = Speed();
    Uint32 sendOwnerPlayerId = OwnerPlayerId();
    float sendLife = Life();
    Uint32 sendHealth = Health();
    bool sendIsMoving = IsMoving();

    memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_ID], &sendId, 4);
    memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_TYPE], &sendType, 4);
    memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_POSX], &sendPos.x, 4);
    memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_POSY], &sendPos.y, 4);
    memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_HEADING], &sendHeadingDeg, 4);
    memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_SPEED], &sendSpeed, 4);
    memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_LIFE], &sendLife, 4);
    memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_HEALTH], &sendHealth, 4);
    memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_PLAYER_ID], &sendOwnerPlayerId, 4);
	memcpy(&data[dataWritePos + PACKET_WRITE_PROJECTILE_ISMOVING], &sendIsMoving, 1);

    return PACKET_WRITE_PROJECTILE_LENGTH;
} // ----------------------------------------------------------------------------------------------
double BoatPlan::SpeedAtApparentWind(double A, double VA, double *pW)
{
    int iters = 0;
    double VW = VA, W = A, VB = 0; // initial guess
    double lp = 1;
    for(;;) {
        double cVB = Speed(W, VW);
        VB -= (VB - cVB) * lp;

        double cVA = VelocityApparentWind(VB, deg2rad(W), VW);
        double cA = rad2posdeg(DirectionApparentWind(cVA, VB, deg2rad(W), VW));

        if(isnan(cVA) || isnan(cA) || iters++ > 256) {
            if(pW) *pW = NAN;
            return NAN;
        }

        if(fabsf(cVA - VA) < 2e-2 && fabsf(cA - A) < 2e-2) {
            if(pW) *pW = W;
            return cVB;
        }

        VW -= (cVA - VA) * lp;
        W -= (cA - A) * lp;
        lp *= .97;
    }
}
SailingVMG BoatPlan::GetVMGApparentWind(double VA)
{
    SailingVMG avmg;

    for(int i=0; i<4; i++) {
        int iters = 0;
        double VW = VA, lp = 1;
        for(;;) {
            SailingVMG vmg = GetVMGTrueWind(VW);
            double W = vmg.values[i];
            if(isnan(W) || iters++ > 128) {
                avmg.values[i] = NAN;
                break;
            }

            double VB = Speed(W, VW);
            double cVA = VelocityApparentWind(VB, deg2rad(W), VW);            
            if(fabsf(cVA - VA) < 2e-1) {
                avmg.values[i] = W;
                break;
            }

            VW -= (cVA - VA) * lp;
            lp *= .97;
        }
    }

    return avmg;
}
Exemple #9
0
task autonomous() // main task basically, but this will run if we are put itno autonomous mode
{
	MVR = 77;
	MVL = 77;
	resetTimer(T2);
	while (true)
	{
		change = full;
		if (time1[T1]>200)
		{
			Speed();
			resetTimer(T1);
			SensorValue[LeftSpeed] = 0;
			SensorValue[RightSpeed] = 0;
			Pid();
		}
		change = full;
		flyWheelRun();
		if (time1[T2]>2000)
		{
			Staggershot();
		}
	}

}
Exemple #10
0
void ReachableList::setInitValues()
{
  // This info we do need from the calculator
  lastPosition = calculator->getlastPosition();
  lastAltitude = calculator->getlastAltitude().getMeters();
  _maxReach = RANGE_RADIUS; // default range radius
  Polar* polar = calculator->getPolar();
  calcMode = ReachableList::altitude;

  if ( ! polar )
    {
      calcMode = ReachableList::distance;
      // If no glider selected calculate nearest sites only.
      return;
    }

  Speed speed = polar->bestSpeed(0.0, 0.0, Speed(0));

  // qDebug("speed for best LD= %f", speed.getKph() );
  double ld = polar->bestLD( speed, speed, 0.0 );  // for coarse estimation (no wind)

  _maxReach = qMax( (lastAltitude/1000) * ld, _maxReach ); // look at least within 75km
  // Thats the maximum range we can reach
  // it in hard to get under sea level :-)
  // qDebug("maxReach: %f %f", _maxReach, (float)ld );
}
Exemple #11
0
static void InvertIntegral(SplineInfo* info, float s, int* j,
   float* v)
{
   const float tolerance = 1e-06;
   const int maxIters = 32;
   float dist=0.0;
   int iter;
   int i = *j;
   float u = *v;
      
   /* Clamp s to [0,L] so that t in [tmin,tmax]. */
   if (s <= 0.0)
   {
      i = 0;
      u = 0.0;
      *j = i;
      *v = u;
      return;
   }
   
   if (s >= info->totalLength)
   {
      i = info->numPolys-1;
      u = 1.0;
      *j = i;
      *v = u;
      return;
   }

   /* Determine which polynomial corresponds to s. */
   for (i = 0; i < info->numPolys; i++)
   {
      if ( s <= info->length[i+1] )
      {
         /* Distance along segment. */
         dist = s - info->length[i];
            
         /* initial guess for inverting the arc length integral */
         u = dist/(info->length[i+1]-info->length[i]);
         break;
      }
   }

   /* Use Newton's method to invert the arc length integral. */
   for ( iter = 0; iter < maxIters; iter++)
   {
      float diff = Length(&info->poly[i],u) - dist;
      if ( fabs(diff) <= tolerance )
      {
         break;
      }

      //assert(speed > 0);
      u -= diff/Speed(&info->poly[i],u);
   }

   *j = i;
   *v = u;   
}
Exemple #12
0
////////////////////////////////////////////////////////////////////////////////
// Инициализация вселенной
void world_setup()
{
    lists_clear();

    // Размечаем поле
    for (int y = 0; y < WORLD_DIM; y++)
        for (int x = 0; x < WORLD_DIM; x++)
            the_field(x, y).attribs.reset();
    the_field(WORLD_DIM - 1, 0).attribs.set(Cell::atrEXIT); // Позиция выхода
    the_field(0, 2).attribs.set(Cell::atrGUARDFORW); // Вешка направления движения охраны
    the_field(WORLD_DIM - 1, 2).attribs.set(Cell::atrGUARDBACKW); // Вешка направления движения охраны
    // Главный герой
    {
        the_character = reinterpret_cast<Character*>(the_alives.allocate());
        new (the_character) Character();
        the_character->position = DeskPosition(0, WORLD_DIM - 1);
        the_character->way.target = DeskPosition(0, WORLD_DIM - 1);
        the_character->set_speed();
    }
    // Стража
    {
        Guard *pgrd;
        pgrd = reinterpret_cast<Guard*>(the_alives.allocate());
        new (pgrd) Guard();
        pgrd->position = DeskPosition(0, 2);
        pgrd->size = U_SIZE * 1.5f;
        pgrd->speed = Speed(GUARD_B_SPEED, 0.0f);
    }
    // Артиллерия
    Artillery::Settings apositions(WORLD_DIM * 2 - 2);
    for (int i = 0; i < WORLD_DIM - 1; i++)
    {
        apositions[i].position = DeskPosition(i, 0);
        apositions[i].speed = Speed(0.0f, deviation_apply(ART_B_SPEED, ART_DEV));
        apositions[i].delay = deviation_apply(ART_B_DELAY, ART_DEV);
        apositions[i].timeout = 0.0f;
        apositions[WORLD_DIM - 1 + i].position = DeskPosition(0, i);
        apositions[WORLD_DIM - 1 + i].speed = Speed(deviation_apply(complexity_apply(ART_B_SPEED, LEVEL_COMPL), ART_DEV), 0.0f);
        apositions[WORLD_DIM - 1 + i].delay = deviation_apply(ART_B_DELAY, ART_DEV);
        apositions[WORLD_DIM - 1 + i].timeout = 0.0f;
    }
    std::random_shuffle(apositions.begin(), apositions.end());
    int acount = std::min(complexity_apply(ART_COUNT, LEVEL_COMPL), static_cast<int>(apositions.capacity()));
    for (int i = 0; i < acount; i++)
        the_artillery.setting.push_back(apositions[i]);
}
Exemple #13
0
/**********************************************************
 *
 * SUBROUTINE CreateExplosion()
 *
 * Used to create a new explosion
 *
 *********************************************************/
void CreateExplosion (void)
{
    int i;

    for (i = 0; i < NUM_PARTICLES; i++)
    {
        particles[i].position[0] = 0.0;
        particles[i].position[1] = 0.0;
        particles[i].position[2] = 0.0;

        particles[i].color[0] = 1.0;
        particles[i].color[1] = 1.0;
        particles[i].color[2] = 0.0;

        Speed (particles[i].speed);
    }

    for (i = 0; i < NUM_DEBRIS; i++)
    {
        debris[i].position[0] = 0.0;
        debris[i].position[1] = 0.0;
        debris[i].position[2] = 0.0;

        debris[i].orientation[0] = 0.0;
        debris[i].orientation[1] = 0.0;
        debris[i].orientation[2] = 0.0;

        debris[i].color[0] = 1.0;
        debris[i].color[1] = 1.0;
        debris[i].color[2] = 0.0;

        debris[i].scale[0] = (2.0 *
        ((GLfloat) rand ()) / ((GLfloat) RAND_MAX)) - 1.0;
        debris[i].scale[1] = (2.0 *
        ((GLfloat) rand ()) / ((GLfloat) RAND_MAX)) - 1.0;
        debris[i].scale[2] = (2.0 *
        ((GLfloat) rand ()) / ((GLfloat) RAND_MAX)) - 1.0;

        Speed (debris[i].speed);
        Speed (debris[i].orientationSpeed);
    }

    fuel = 100;
}
 virtual void update(const UpdateEventUnrecPtr e)
 {
     ForceOnCharacter.setValues(0.0,0.0,0.0);
     Real32 PushForce(10000.0);
     Real32 Speed(20.0);
     if(_IsUpKeyDown)
     {
         ForceOnCharacter += Vec3f(0.0, PushForce, 0.0);
     }
     if(_IsDownKeyDown)
     {
         ForceOnCharacter += Vec3f(0.0, -PushForce, 0.0);
     }
     if(_IsLeftKeyDown)
     {
         ForceOnCharacter += Vec3f(-PushForce, 0.0, 0.0);
     }
     if(_IsRightKeyDown)
     {
         ForceOnCharacter += Vec3f(PushForce, 0.0, 0.0);
     }
     if(ForceOnCharacter != Vec3f(0.0,0.0,0.0))
     {
         ShipBody->setEnable(true);
     }
         if(ForceOnCharacter.x() !=0.0)
         {
             ShipMotor->setFMax(osgAbs(ForceOnCharacter.x()));
             ShipMotor->setVel(osgSgn(ForceOnCharacter.x())*Speed);
         }
         else
         {
             ShipMotor->setFMax(0.0);
             ShipMotor->setVel(0.0);
         }
         if(ForceOnCharacter.y() !=0.0)
         {
             ShipMotor->setFMax2(osgAbs(ForceOnCharacter.y()));
             ShipMotor->setVel2(osgSgn(ForceOnCharacter.y())*Speed);
         }
         else
         {
             ShipMotor->setFMax2(0.0);
             ShipMotor->setVel2(0.0);
         }
         if(ForceOnCharacter.z() !=0.0)
         {
             ShipMotor->setFMax3(osgAbs(ForceOnCharacter.z()));
             ShipMotor->setVel3(osgSgn(ForceOnCharacter.z())*Speed);
         }
         else
         {
             ShipMotor->setFMax3(0.0);
             ShipMotor->setVel3(0.0);
         }
 }
Exemple #15
0
static int ReSync( void )
{
    int result;            /* result of ReSyncing */

    ++BaudCounter;              /* next slower speed */
    if( BaudCounter > MIN_BAUD ) BaudCounter = MIN_BAUD;
    while( SetSyncTime() == FAIL ) ;
    result = Speed();           /* sync */
    return( result );
}
Exemple #16
0
Traveler_Data::Traveler_Data (int traveler, int time) : 
	Class2_Index (traveler, time), Static_Scale ()
{
	Vehicle (0);
	Link_Dir (0);
	Offset (0);
	Lane (0);
	Distance (0);
	Speed (0);
}
Exemple #17
0
/*-------------------------------------------------------------------------*/
static void InvertIntegral (SplineInfo* info, double s, int* j , double* v)
{
    const double tolerance = 1e-06;
    const int maxIters = 32;
    double dist=0.0;
    int iter;
    int i = *j;
    double u = *v;
      
    /* clamp s to [0,L] so that t in [tmin,tmax] */
    if ( s <= 0.0 )
    {
        i = 0;
        u = 0.0;
	*j = i;
	*v = u;
        return;
    }
    if ( s >= info->totalLength )
    {
        i = info->numPolys-1;
        u = 1.0;
	*j = i;
	*v = u;
        return;
    }

    /* determine which polynomial corresponds to s */
    for (i = 0; i < info->numPolys; i++)
    {
        if ( s <= info->length[i+1] )
        {
	    /* distance along segment */
            dist = s - info->length[i];
            
            /* initial guess for inverting the arc length integral */
            u = dist/(info->length[i+1]-info->length[i]);
            break;
        }
    }

    /* use Newton's method to invert the arc length integral */
    for ( iter = 0; iter < maxIters; iter++)
    {
        double diff = Length(&info->poly[i],u) - dist;
        if ( fabs(diff) <= tolerance )
            break;

        /* assert: speed > 0 */
        u -= diff/Speed(&info->poly[i],u);
    }

    *j = i;
    *v = u;   
}
void SolveHarmonicOscillatorAndComputeError3D(benchmark::State& state,
                                              Length& q_error,
                                              Speed& v_error,
                                              Integrator const& integrator) {
  using ODE = SpecialSecondOrderDifferentialEquation<Position<World>>;

  state.PauseTiming();
  Displacement<World> const q_initial({1 * Metre, 0 * Metre, 0 * Metre});
  Velocity<World> const v_initial;
  Instant const t_initial;
#ifdef _DEBUG
  Instant const t_final = t_initial + 100 * Second;
#else
  Instant const t_final = t_initial + 1000 * Second;
#endif
  Time const step = 3.0e-4 * Second;

  std::vector<ODE::SystemState> solution;
  solution.reserve(static_cast<int>((t_final - t_initial) / step));
  ODE harmonic_oscillator;
  harmonic_oscillator.compute_acceleration =
      std::bind(ComputeHarmonicOscillatorAcceleration3D, _1, _2, _3);
  IntegrationProblem<ODE> problem;
  problem.equation = harmonic_oscillator;
  ODE::SystemState const initial_state = {{World::origin + q_initial},
                                          {v_initial},
                                          t_initial};
  problem.initial_state = &initial_state;
  auto append_state = [&solution](ODE::SystemState const& state) {
    solution.emplace_back(state);
  };

  auto const instance =
      integrator.NewInstance(problem, std::move(append_state), step);

  state.ResumeTiming();
  integrator.Solve(t_final, *instance);
  state.PauseTiming();

  q_error = Length();
  v_error = Speed();
  for (auto const& state : solution) {
    q_error = std::max(q_error,
                       ((state.positions[0].value - World::origin) -
                           q_initial *
                           Cos((state.time.value - t_initial) *
                               (Radian / Second))).Norm());
    v_error = std::max(v_error,
                       (state.velocities[0].value +
                           (q_initial / Second) *
                           Sin((state.time.value - t_initial) *
                               (Radian / Second))).Norm());
  }
  state.ResumeTiming();
}
Exemple #19
0
main()
{
  int gdriver=DETECT,gmode;
   initgraph(&gdriver,&gmode,"");
   speed=Speed();/*将函数返回值赋给speed*/
   cleardevice();/*清屏*/
   dwall();/*开始画墙*/
   Play();/*开始完游戏*/
   getch();
   closegraph();/*退出图形界面*/
}
Exemple #20
0
void SiX::TimeTurn(int time,int Left,int Right)
{
	while(1)
	{
		Speed(Left, Right);
		Timer(0,1);
	    unsigned long ENDt = reCorval();
		if ((ENDt/(time*1000)) == 1)
		  break;
	}
}
Exemple #21
0
//----------------------------------------------------------------------------
float PosSpline::Poly::Length (float fU)
{
    // Need to transform domain [0,u] to [-1,1].  If 0 <= x <= u
    // and -1 <= t <= 1, then x = u*(t+1)/2.
    float fResult = 0.0f;
    for (int i = 0; i < 5; i++)
        fResult += ms_afModCoeff[i]*Speed(fU*ms_afModRoot[i]);
    fResult *= fU;

    return fResult;
}
Exemple #22
0
Ephemeris<Frame>::AdaptiveStepParameters::AdaptiveStepParameters(
    AdaptiveStepSizeIntegrator<NewtonianMotionEquation> const& integrator,
    std::int64_t const max_steps,
    Length const& length_integration_tolerance,
    Speed const& speed_integration_tolerance)
    : integrator_(&integrator),
      max_steps_(max_steps),
      length_integration_tolerance_(length_integration_tolerance),
      speed_integration_tolerance_(speed_integration_tolerance) {
  CHECK_LT(0, max_steps_);
  CHECK_LT(Length(), length_integration_tolerance_);
  CHECK_LT(Speed(), speed_integration_tolerance_);
}
Exemple #23
0
bool RemoteConnect( void )
{
    int     baud_limit;     /* maximum baud that BOTH sides can achieve */
    byte    dummy;          /* hold values that we don't need here */
    byte    MaxBaud2;       /* MaxBaud at the other machine */

    SendBlkNo = ReceiveBlkNo = 0;
    LastResponse = SDATA_NAK;
    if( !SetSyncTime() )
        return( FALSE );
    /* establish baud limit */
#ifdef SERVER
    if( !WaitReceive( &dummy, 1, &MaxBaud2, SEC( 2 ) ) ) {
        return( FALSE );
    }
    if( !BlockSend( 1, (byte *)&MaxBaud, SEC( 2 ) ) ) {
        return( FALSE );
    }
#else
    if( !BlockSend( 1, (byte *)&MaxBaud, SEC( 2 ) ) ) {
        return( FALSE );
    }
    if( !WaitReceive( &dummy, 1, &MaxBaud2, SEC( 2 ) ) ) {
        return( FALSE );
    }
#endif
    /* MaxBaud2 now contains the other side's baud rate limit */
    if( MaxBaud > MaxBaud2 ) {
        baud_limit = MaxBaud;
    } else {
        baud_limit = MaxBaud2;
    }

    BaudCounter = baud_limit;
    if( !Speed() ) 
        return( FALSE );
#ifdef SERVER
    {
        char    buff[128];

        if( BaudCounter == MIN_BAUD ) {
            strcpy( buff, "pre-set" );
        } else {
            strcpy( buff, BaudTable[BaudCounter].name );
        }
        strcat( buff, " baud" );
        ServMessage( buff );
    }
#endif
    return( TRUE );
}
Exemple #24
0
status_t
NodeManager::FormatChanged(BRect videoBounds, float videoFrameRate,
	color_space preferredVideoFormat, float audioFrameRate,
	uint32 audioChannels, uint32 enabledNodes, bool useOverlays, bool force)
{
	TRACE("NodeManager::FormatChanged()\n");

	if (!force && videoBounds == VideoBounds()
		&& videoFrameRate == FramesPerSecond()) {
		TRACE("   -> reusing existing nodes\n");
		// TODO: if enabledNodes would indicate that audio or video
		// is no longer needed, or, worse yet, suddenly needed when
		// it wasn't before, then we should not return here!
		PlaybackManager::Init(videoFrameRate, false, LoopMode(),
			IsLoopingEnabled(), Speed(), MODE_PLAYING_PAUSED_FORWARD,
			CurrentFrame());
		return B_OK;
	}

	_StopNodes();
	_TearDownNodes();

	PlaybackManager::Init(videoFrameRate, true, LoopMode(), IsLoopingEnabled(),
		Speed(), MODE_PLAYING_PAUSED_FORWARD, CurrentFrame());

	SetVideoBounds(videoBounds);

	status_t ret = _SetUpNodes(preferredVideoFormat, enabledNodes,
		useOverlays, audioFrameRate, audioChannels);
	if (ret == B_OK)
		_StartNodes();
	else
		fprintf(stderr, "unable to setup nodes: %s\n", strerror(ret));

	return ret;
}
Exemple #25
0
GBNumber GBRobot::Interest() const {
	GBNumber interest = Biomass() * (GBNumber(0.001) + Speed() * 0.01)
		+ hardware.ActualShield() / 2;
	if ( hardware.blaster.Cooldown() )
		interest += hardware.blaster.Damage() * 10 / hardware.blaster.ReloadTime();
	if ( hardware.grenades.Cooldown() )
		interest += hardware.grenades.Damage() * 10 / hardware.grenades.ReloadTime();
	if ( hardware.blaster.Cooldown() )
		interest += abs(hardware.forceField.Power()) * 15 + 1;
	if ( hardware.syphon.Rate() )
		interest += abs(hardware.syphon.Rate()) + 1;
	if ( hardware.enemySyphon.Rate() )
		interest += abs(hardware.enemySyphon.Rate())* 5 + 2;
	return interest;
}
Exemple #26
0
MCWorld::MCWorld() {


	TravelingPixmap* object;

	for(int i = 0; i < 3; i++) {
		object = new TravelingPixmap("images/MCWorld/italian.png");
		italians << object;
		object = new TravelingPixmap("images/MCWorld/maiden.png");
		maidens << object;
	}

	boat = new TravelingPixmap("images/MCWorld/boat.png");

	makeObjectsList();

	shore1 = Coordinate(300, 100);
	shore2 = Coordinate(400, 400);
	boat1 = Coordinate(150, 250);
	boat2 = Coordinate(350, 450);
	setShore1(shore1, boat1);
	setShore2(shore2, boat2);

	preferedSpeed = Speed(60, 60, 0).speedModule();


	reset();
	moving = true;

	//initialise the rides to make the objects move:
	for(int i = 0; i < 3; i++) {
		Ride x;
		x.nrItalians = i + 1;
		x.nrMaidens = i + 1;
		rides << x;
		rides << x;
	}

	//seems like Qt is smart enough to know what to do with the widget:
	ui.show();
	QObject::connect(&ui, SIGNAL(back()), this, SLOT(back()));
	QObject::connect(&ui, SIGNAL(forward()), this, SLOT(forward()));
	QObject::connect(&ui, SIGNAL(fileChosen(QString)), this, SLOT(openFile(QString)));
	QObject::connect(&ui, SIGNAL(speedChanged(double)), this, SLOT(changeSpeed(double)));
	QObject::connect(&ui, SIGNAL(start()), this, SLOT(toggleStart()));
	QObject::connect(&ui, SIGNAL(random()), this, SLOT(random()));
}
AnimationTransitPtr setupAnimation(const std::vector<Pnt3f>& Path, Transform* const transCore)
{
    //Transformation Keyframe Sequence
    KeyframeTransformationSequenceRecPtr TransformationKeyframes = KeyframeTransformationSequenceMatrix4f::create();
    Matrix TempMat;
    TempMat.setScale(0.06f);
    Real32 Speed(1.0f);
    Real32 SeqTime;
    Real32 TotalPathDistance(0.0f);
    for(UInt32 i(0) ; i<Path.size()-1 ; ++i)
    {
        TotalPathDistance += Path[i].dist(Path[(i+1)]);
    }

    Real32 CumPathDistance(0.0f);
    Quaternion Rotation;
    Vec3f Direction;
    for(UInt32 i(0) ; i<Path.size() ; ++i)
    {
        SeqTime = CumPathDistance / Speed;
        Direction = Path[(i+1)%Path.size()]-Path[i];
        Direction[1] = 0.0f;
        Direction.normalize();
        Rotation = Quaternion(Vec3f(0.0f,0.0f,1.0f),Direction);
        TempMat.setTransform(Vec3f(Path[i]),Rotation,Vec3f(0.1f,0.1f,0.1f));
        TransformationKeyframes->addKeyframe(TempMat,SeqTime);

        if(i<Path.size()-1)
        {
            CumPathDistance += Path[i].dist(Path[(i+1)]);
        }
    }

    //Animator
    KeyframeAnimatorRecPtr TheAnimator = KeyframeAnimator::create();
    TheAnimator->setKeyframeSequence(TransformationKeyframes);

    //Animation
    FieldAnimationRecPtr TheAnimation = FieldAnimation::create();
    TheAnimation->setAnimator(TheAnimator);
    TheAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION);
    TheAnimation->setCycling(1);
    TheAnimation->setAnimatedField(transCore, std::string("matrix"));

    return AnimationTransitPtr(TheAnimation);
}
TEST_P(SimpleHarmonicMotionTest, Symplecticity) {
  parameters_.initial.positions.emplace_back(SIUnit<Length>());
  parameters_.initial.momenta.emplace_back(Speed());
  parameters_.initial.time = Time();
  Stiffness const k = SIUnit<Stiffness>();
  Mass const m      = SIUnit<Mass>();
  Length const q0   = parameters_.initial.positions[0].value;
  Speed const v0 = parameters_.initial.momenta[0].value;
  Energy const initial_energy = 0.5 * m * Pow<2>(v0) + 0.5 * k * Pow<2>(q0);
  parameters_.tmax = 500.0 * SIUnit<Time>();
  parameters_.Δt = 0.2 * Second;
  parameters_.sampling_period = 1;
  integrator_->SolveTrivialKineticEnergyIncrement<Length>(
      &ComputeHarmonicOscillatorAcceleration,
      parameters_,
      &solution_);
  std::size_t const length = solution_.size();
  std::vector<Energy> energy_error(length);
  std::vector<Time> time_steps(length);
  Energy max_energy_error = 0 * SIUnit<Energy>();
  for (std::size_t i = 0; i < length; ++i) {
    Length const q_i   = solution_[i].positions[0].value;
    Speed const v_i = solution_[i].momenta[0].value;
    time_steps[i] = solution_[i].time.value;
    energy_error[i] = Abs(0.5 * m * Pow<2>(v_i) + 0.5 * k * Pow<2>(q_i) -
                          initial_energy);
    max_energy_error = std::max(energy_error[i], max_energy_error);
  }
#if 0
  LOG(INFO) << "Energy error as a function of time:\n" <<
      BidimensionalDatasetMathematicaInput(time_steps, energy_error);
#endif
  double const correlation =
      PearsonProductMomentCorrelationCoefficient(time_steps, energy_error);
  LOG(INFO) << GetParam();
  LOG(INFO) << "Correlation between time and energy error : " << correlation;
  EXPECT_THAT(correlation, Lt(2E-3));
  Power const slope = Slope(time_steps, energy_error);
  LOG(INFO) << "Slope                                     : " << slope;
  EXPECT_THAT(Abs(slope), Lt(2E-6 * SIUnit<Power>()));
  LOG(INFO) << "Maximum energy error                      : " <<
      max_energy_error;
  EXPECT_EQ(GetParam().expected_energy_error, max_energy_error);
}
Exemple #29
0
int Speed()/*选择贪吃蛇运行的速度*/
{           int m;
gotoxy(20,10);
   printf("level1\n");
   gotoxy(20,12);
   printf("level2\n");
   gotoxy(20,14);
   printf("level3\n\t\tplease choose:");
   scanf("%d",&m);
   switch(m)
   {
   case 1:return 60000;
   case 2:return 40000;
   case 3:return 20000;
   default:
   cleardevice();
   Speed();
   }
}
Exemple #30
0
double BoatPlan::SpeedAtApparentWindSpeed(double W, double VA)
{
    int iters = 0;
    double VW = VA, VB = 0; // initial guess
    double lp = 1;
    for(;;) {
        double cVB = Speed(W, VW);
        VB -= (VB - cVB) * lp;

        double cVA = VelocityApparentWind(VB, deg2rad(W), VW);
        if(isnan(cVA) || iters++ > 256)
            return NAN;

        if(fabsf(cVA - VA) < 2e-2)
            return cVB;

        VW -= (cVA - VA) * lp;
        lp *= .97;
    }
}