Exemplo n.º 1
0
vector<Point2i>SLIC::getContour(){
    const int dx[8] = {-1, -1, -1, 0,  0,  1, 1, 1};
    const int dy[8] = { 1,  0, -1, 1, -1, -1, 0, 1};

    vector<Point2i>contours;
    vector<vector<bool> >visit(image.rows, vector<bool>(image.cols, false));
    
    for (int y=0; y<image.rows; y++) {
        int *cluster_ptr = cluster.ptr<int>(y);
        for (int x=0; x<image.cols; x++){
            int bd = 0;
            for (int i=0; i<8; i++){
                int nx = x+dx[i];
                int ny = y+dy[i];
                if (withinRange(nx, ny)){
                    if (!visit[ny][nx] &&  cluster_ptr[x] != cluster.at<int>(ny, nx)) {
                        bd++;
                        if (bd >1) {
                            break;
                        }
                    }
                }

                if (bd >= 1) {
                    contours.push_back(Point2i(x,y));
                    visit[y][x] = true;
                }
            }
        }
    }
    return contours;
}
// Check whether a point is on the border
static bool isPointOnPathBorder(const QPolygonF& border, const QPointF& p)
{
    QPointF p1 = border.at(0);
    QPointF p2;

    for (int i = 1; i < border.size(); ++i) {
        p2 = border.at(i);
        if (areCollinear(p, p1, p2)
                // Once we know that the points are collinear we
                // only need to check one of the coordinates
                && (qAbs(p2.x() - p1.x()) > qAbs(p2.y() - p1.y()) ?
                        withinRange(p.x(), p1.x(), p2.x()) :
                        withinRange(p.y(), p1.y(), p2.y()))) {
            return true;
        }
        p1 = p2;
    }
    return false;
}
Exemplo n.º 3
0
static uint scanBucket(const Position& transmitter, const Position* receivers, int numReceivers, uint coverage)
{
    for (int receiverIndex = 0; receiverIndex < numReceivers; ++receiverIndex)
    {
        const Position& receiver = receivers[receiverIndex];

        if (withinRange(transmitter, receiver))
            ++coverage;
    }

    return coverage;
}
Exemplo n.º 4
0
void testRangeFunctions()
{
    Unit a,b;
    a.setWidth(2);
    a.setHeight(2);
    b.setWidth(2);
    b.setHeight(2);
    qDebug() << "Overlapping (t)" << withinRange(&a,0,&b);
    qDebug() << "Colliding (t)" << collide(&a,&b);
    a.setX(1);
    qDebug() << "To the left, well within(t)" << withinRange(&a,10,&b);
    qDebug() << "Colliding (t)" << collide(&a,&b);
    a.setX(10);
    qDebug() << "To the left, just within(t)" << withinRange(&a,10,&b);
    qDebug() << "Colliding (f)" << collide(&a,&b);
    a.setX(11);
    qDebug() << "To the left, just without(f)" << withinRange(&a,10,&b);
    qDebug() << "Colliding (f)" << collide(&a,&b);
    a.setX(310);
    qDebug() << "To the left, way off(f)" << withinRange(&a,10,&b);
}
Exemplo n.º 5
0
void SLIC::generateSuperPixels(){
    for (int iter = 0; iter < max_iteration; iter++){
        distance = Scalar(FLT_MAX);
        
        for (int i=0; i<center.size(); i++) {
            ColorRep tmp_center = center[i];
            for (int y=tmp_center.y-S; y<tmp_center.y+S; y++) {
                
                Vec3b *ptr = image.ptr<Vec3b>(y);
                int *cluster_ptr = cluster.ptr<int>(y);
                double *dist_ptr = distance.ptr<double>(y);
                
                for (int x = tmp_center.x -S; x<tmp_center.x+S; x++){
                    if (withinRange(x, y)) {
                        Vec3b color = ptr[x];
                        //calculate the distance
                        double dist = calcDist(tmp_center, color, x,y);
                        if (dist < dist_ptr[x]){
                            dist_ptr[x] = dist;
                            cluster_ptr[x] = i;
                        }
                    }
                }
            }
        }
        
        center.assign(center.size(), ColorRep());
        count.assign(count.size(), 0);
        
        
        for (int y=0; y<image.rows; y++) {
            int *cluster_ptr = cluster.ptr<int>(y);
            for (int x=0; x<image.cols; x++){
                int cluster_id = cluster_ptr[x];
                if (cluster_id != -1){
                    Vec3b color = image.at<Vec3b>(y,x);
                    center[cluster_id].add(color, x, y);
                    count[cluster_id]++;
                }
            }
        }
        
        for (int i=0; i<center.size(); i++){
            center[i].div(count[i]);
        }
        
    }
}
Exemplo n.º 6
0
bool BodyModel::validate()
{
    if (!withinRange()) {
        return false;
    }
    //躯干为三个头高
    int main_body_heigh = _chest_heigh + _waist_heigh;
    int main_head_heigh = _head_radius + _neck_heigh;
    if (main_body_heigh > 4 * main_head_heigh || main_body_heigh < 1.5 * main_head_heigh) {
        return false;
    }
    //手臂长为3个头高
    if (_arm_length > 4 * main_head_heigh || _arm_length < 1.5 * main_head_heigh) {
        return false;
    }
    //大腿为2个头高,小腿和足为2个头高
    if (_leg_length > 5 * main_head_heigh || _leg_length < 2 * main_head_heigh) {
        return false;
    }
    return true;
}
int main(void)
{
    pInt8U pBuffer;
    Int32U Size,TranSize;
    int i=0,j;
    int k=0;
    int cnt=0;
    int tempcnt=0;
    int concurCnt = 0;
    Flo64 curP, curQ;
    int meanCalc=1,displayIntro=1;
    AlgoPowers_t PowerLines[3];
    AlgoPowers_t prevPLines;
    AlgoPowers_t curPLines;
    int LearnNewMean = 1;
    int learning =1;
    int recognized=0;
    int plugOut = 0;
    Flo64 cInterval = 5000;
    int debug = 0;
    
    // int deviceCnt[3] = {0};
    //AlgoLine_t TestLine;
    // pAlgoLine_t pTestLine=&TestLine;
    AlgoDevice_t tmpDev;
//    AlgoDevice_t devProfiles[3]={0};
    AlgoDevice_t devProfiles[3];
    int devNum=0;
    
    
    bool addDevice = 1;
    
    Int32S devLamps[3];
    
    
    #if CDC_DEVICE_SUPPORT_LINE_CODING > 0
        CDC_LineCoding_t CDC_LineCoding;
    UartLineCoding_t UartLineCoding;
    #endif // CDC_DEVICE_SUPPORT_LINE_CODING > 0
        
    
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  GUI init  START
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // initialize touch parametres
    Int32U cursor_x = (C_GLCD_H_SIZE - CURSOR_H_SIZE)/2, cursor_y = (C_GLCD_V_SIZE - CURSOR_V_SIZE)/2;
    ToushRes_t XY_Touch;
    Boolean Touch = FALSE;
    
    
    GLCD_Ctrl (FALSE);
    
    // Init GPIO
    GpioInit();
    
    #ifndef SDRAM_DEBUG
    // MAM init
    MAMCR_bit.MODECTRL = 0;
    MAMTIM_bit.CYCLES  = 3;   // FCLK > 40 MHz
    MAMCR_bit.MODECTRL = 2;   // MAM functions fully enabled
    // Init clock
    InitClock();
    // SDRAM Init
    SDRAM_Init();
    #endif // SDRAM_DEBUG
        // Init VIC   ---interrupt
    VIC_Init();
    
    
    // GLCD init
    GLCD_Init (NULL, NULL);
    
    GLCD_Cursor_Dis(0);
    
    GLCD_Copy_Cursor ((Int32U *)Cursor, 0, sizeof(Cursor)/sizeof(Int32U));
    
    GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_32);
    
    GLCD_Move_Cursor(cursor_x, cursor_y);
    
    GLCD_Cursor_En(0);
    
    // Init touch screen
    TouchScrInit();
    
    // Touched indication LED
    USB_H_LINK_LED_SEL = 0; // GPIO
    USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK;
    USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK;
    
    // Init UART 0
    UartInit(UART_0,0,NORM);
    
    
    __enable_interrupt();
    
    GLCD_Ctrl (TRUE);
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  GUI init  END
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    
    
    /* devProfiles[0].dP= 101366.22;   //blow dryer
    devProfiles[0].dQ =51765.90;
    
    devProfiles[1].dP= 35957.14;    //light bulb
    devProfiles[1].dQ = 9045.64;
    */
    
    
    //  GLCD_print("Device char %f %f\r\n",devProfiles[devNum].dP, devProfiles[devNum].dQ );
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    // Update the baud rate
    UartLineCoding.dwDTERate = 115200;
    // Update the stop bits number
    UartLineCoding.bStopBitsFormat = UART_ONE_STOP_BIT;
    // Update the parity type
    UartLineCoding.bParityType = UART_NO_PARITY;
    // Update the word width
    UartLineCoding.bDataBits = (UartWordWidth_t)(3);
    //Description: Init UART Baud rate, Word width, Stop bits, Parity type
    UartSetLineCoding(UART_0,UartLineCoding);
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    //calculate the no load powerlines
    //calcMeanRange(&prevPLines);
    // GLCD_print("P %f %f\n\r",prevPLines.P.CiHigh, prevPLines.P.CiLow);
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    for(i=0; i<3; i++){
      devProfiles[i].dP=0;
      devProfiles[i].dQ=0;
      devLamps[i]=0;
    }
    
    // initialize gui
    //gui_monitoringScreen(devProfiles,devLamps);
    gui_mainScreen();
    
    GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff);
    GLCD_SetWindow(0,0,319,239);
    GLCD_TextSetPos(0,0);
    //calculate the no load powerlines
    calcMeanRange(&prevPLines);
    
    while(1)
    {
        
        ///////////////////////////////////////////////////////////////////////////////
        GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff);
        GLCD_SetWindow(0,0,319,239);
        GLCD_TextSetPos(0,0);
        
        /////////////////////////////////////////////////////////////////////////////////
        
        /////////////////////////////////////////////////////////////////////////////////
        //algo    START
        /////////////////////////////////////////////////////////////////////////////////
        if(dataReady){
            dataReady=0;
            GLCD_print("%s\r\n",dataArray);
            //  GLCD_print("reach reach!!!\r\n");
                        
            //convert the incoming data to floats
            dataConversion(dataArray, dataP, dataQ, dataT, cnt);           
            
            //keep track of devices
            GLCD_print("Device zero:%d   one:%d   two:%d\r",devLamps[0],
            devLamps[1],devLamps[2]);
            
            concurCnt=0;
            //detect a step change.
            if(detectStepChange(&prevPLines, dataP[cnt], dataQ[cnt] )){
                tempcnt=(int) fmod(cnt+4,45);
                while(cnt != tempcnt){
                    if(dataReady){
                        dataConversion(dataArray, dataP, dataQ, dataT, cnt);
                        if(detectStepChange(&prevPLines, dataP[cnt], dataQ[cnt] )){
                            concurCnt++;
                        }
                        cnt++;
                        dataReady=0;
                        if(cnt>=45){
                            cnt=0;
                        }
                    }
                }
                
                if(concurCnt>=3){
                    //calculate new powerlines
                    calcMeanRange(&curPLines);
                    
                    tmpDev.dP = curPLines.P.mean - prevPLines.P.mean;
                    tmpDev.dQ = curPLines.Q.mean - prevPLines.Q.mean;
                    GLCD_print("test dev dP is %f\r\n",tmpDev.dP);
                    GLCD_print("test dev dQ is %f\r\n",tmpDev.dQ);
                    
                    
                    //in learning phase
                    if(screen==1){
                        
                        // GLCD_print("we can now add DEVICES!!!\r\n");
                        
                        if(devNum==3){
                            GLCD_print("Can't learn anymore devices\r\n");
                            learning=0;
                        }
                        else{
                            if(tmpDev.dP>0 && tmpDev.dQ>0){
                                
                                GLCD_print("add device or not?\r\n");
                                
                                if(addDevice){
                                    
                                    devProfiles[devNum].dP = tmpDev.dP;
                                    devProfiles[devNum].dQ = tmpDev.dQ;
                                    GLCD_print("new profile %d p:%f q:%f\r\n",devNum,
                                    tmpDev.dP,tmpDev.dQ);
                                    devNum++;
                                }
                                
                            }
                            else{
                                GLCD_print("device is unplugged\r\n");
                                //DO THE CHECK
                                
                                //   determineDevice(devProfiles,tmpDev,&devNum,devLamps);
                                //gui_monitoringScreen(devProfiles,devLamps);
                            }
                        }
                    }
                    //in user phase
                    else if (screen==0){
                        if(devNum==0){
                            GLCD_print("No devices on file. Please enter learning mode");
                        }
                        
                        else{
                            //check aganst known devices
                            for(k=0;k<3;k++){
                                GLCD_print("devProfile %d p:%f  q:%f\r\n",k, devProfiles[k].dP,
                                devProfiles[k].dQ);
                                //if plugging out, the deltas will be negative
                                if(tmpDev.dP<0 && tmpDev.dQ<0){
                                    plugOut=1;
                                    tmpDev.dP = fabs(tmpDev.dP);
                                    tmpDev.dQ = fabs(tmpDev.dQ);
                                }
                                
                                if(withinRange(tmpDev,devProfiles[k],cInterval)){
                                    if(plugOut){
                                        GLCD_print("device %d unplugged!\r\n",k);
                                        plugOut=0;
                                        devLamps[k]=0;
                                    }
                                    else{
                                        GLCD_print("device %d plugged in!\r\n",k);
                                        devLamps[k]=1;
                                    }
                                    gui_monitoringScreen(devProfiles,devLamps);
                                    break;
                                }
                            }
                        } // end of if(devNum>0)
                    }   // end user phase
                    prevPLines = curPLines;
                    GLCD_print("prevPlines %f, %f\r",prevPLines.P,prevPLines.Q);
                }       // end of (concurCnt>=3)
            }           // end of detectStepChange()
            cnt++;
            //dataReady=0;
            if(cnt >= 45){
                cnt=0;
            }
        }               // end of dataReady
        /////////////////////////////////////////////////////////////////////////////////
        //                      End of Algo
        /////////////////////////////////////////////////////////////////////////////////
        
        
        /////////////////////////////////////////////////////////////////////////////////
        //      GUI start
        /////////////////////////////////////////////////////////////////////////////////
        
        if(TouchGet(&XY_Touch))
        {
            cursor_x = XY_Touch.X;
            cursor_y = XY_Touch.Y;
            GLCD_Move_Cursor(cursor_x, cursor_y);
            
            if (FALSE == Touch)
            {
                Touch = TRUE;
                USB_H_LINK_LED_FCLR = USB_H_LINK_LED_MASK;
            }
        }
        
        // check the need to swtich screen
        else if(Touch)
        {
            switch(screen)
            {
                
                case 0: // 0 = Monitoring screen
                
                  // Touch logic
                  if(modeButtonState)
                  {
                      if (cursor_x <= 80 && cursor_y >= 190)
                      {
                          gui_toggleMode(devProfiles,devLamps);
                          break;
                      }
                  }
                  if(settingsButtonState)
                  {
                      if (cursor_x >= 239 && cursor_y >= 190)
                      {
                          gui_settingsScreen();
                          break;
                      }
                  }
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 1: // 1 = Learning screen
                  // Touch logic
                  if(modeButtonState)
                  {
                      if (cursor_x <= 80 && cursor_y >= 190) //  mode
                      {
                          gui_toggleMode(devProfiles,devLamps);
                          break;
                      }
                  }
                  if(addDeviceButtonState)
                  {
                      // add device button placement (80,70,240,120)
                      if (cursor_x >= 80 && cursor_y >= 70 && cursor_x <= 240 && cursor_y <= 120)
                      {
                          addDevice = 1;
                          
                          //gui_addDeviceScreen();
                          break;
                      }
                  }
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 2: // 2 = Devices screen
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 3: // 3: Webserver screen
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 4: // 4: Inormation Screen
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 5: // 5: Settings Screen
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 9: // 9: Main Screen
                  // Monitor Button
                  if (cursor_x >= 59 && cursor_y >= 64 && cursor_x <= 119 && cursor_y <= 124)
                  {    
                      gui_monitoringScreen(devProfiles,devLamps);
                      break;
                  }
                  // Learn Button
                  else if (cursor_x >= 129 && cursor_y >= 64 && cursor_x <= 189 && cursor_y <= 124)
                  {
                      gui_learningScreen();
                      break;
                  }
                  // Devices Button
                  else if (cursor_x >= 199 && cursor_y >= 64 && cursor_x <= 259 && cursor_y <= 124)
                  {
                      gui_devicesScreen();
                      break;
                  }
                  // Server Button
                  else if (cursor_x >= 59 && cursor_y >= 134 && cursor_x <= 119 && cursor_y <= 194)
                  {
                      gui_serverScreen();
                      break;
                  }
                  // Info Button
                  else if (cursor_x >= 129 && cursor_y >= 134 && cursor_x <= 189 && cursor_y <= 194)
                  {
                      gui_infoScreen();
                      break;
                  }
                  // Settings Button
                  else if (cursor_x >= 199 && cursor_y >= 134 && cursor_x <= 259 && cursor_y <= 194)
                  {
                      gui_settingsScreen();
                      break;
                  }
                break;
            }
            USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK;
            Touch = FALSE;
            
        }
        /////////////////////////////////////////////////////////////////////////////////
        
        /////////////////////////////////////////////////////////////////////////////////
    }
    
}
Exemplo n.º 8
0
int main(int argc, char* argv[])
{
    int seed = init_rand();
    //int seed = init_rand(1314485160);
    std::cout << "seed:" << seed << std::endl;

    initScreen();
    displayTitleScreen();

    int world_width = worldScreenDims[WIDTH];
    int world_height = worldScreenDims[HEIGHT];
    int world_depth = 5;

    world = new World(world_width, world_height, world_depth);
    setWorld(world);//interface.h, just to keep a pointer to the world so It doesn't have to get passed with every message, prompt, etc. probably a better way to do this but i cba
    player = world->generatePlayer();
    enemies = world->generateEnemies(4,8);
    world->generateItems(25,50);

    std::stringstream intro_stream;
    intro_stream << "You are " << player->getName() << ", an Adventurer in search of the Icon of Weedaula.";
    message(intro_stream.str());
    message("Bring the Icon back to the surface to win the game!");
    message("Press '?' for help");

    while (!isGameOver())
    {
        world->incrementTimeStep();
        player->FOV(player->getMapLevel());
        displayGameScreen();
        updateScreen();

        player->startTurn();
        while (!player->isTurnFinished() && player->isTurn() && !isGameOver())
        {
            handleKeyPress();
        }
        player->endTurn();

        enemies = world->getEnemyList();
        for (unsigned int i = 0; i < enemies.size(); i++)
        {
            Enemy *en = enemies[i];
            en->FOV(en->getMapLevel());
            en->startTurn();
            if (en->isTurn() && withinRange(en->getMapLevel(), player->getMapLevel(), player->getMapLevel()))
            {
                en->takeTurn();
            }
            en->endTurn();
        }
    }

    if (isGameOver())
    {
        if (!player->isAlive())
        {
            displayGameOverScreen("You have been struck down");
        }
    }
}
Exemplo n.º 9
0
bool Actor::tooFarFromTarget() {
    if (target==NULL) return false;
    
    return !withinRange();
}
Exemplo n.º 10
0
void ServerMix(std::string iaddress, std::string target, double total, bool multipath) {

  int iSecret;
  int iLow;
  int iHigh;
  //std::cerr << "INSIDE THE MIXING LOGIC" << std::endl;
/* initialize random seed: */
  srand (time(NULL));
  iLow = 1;
  iHigh = 4;
  /* generate secret number between 1 and 10: */
  iSecret = 1 + (rand() % 5);



  // ensure smtx.amount coins was transferred to smtx.iaddress
  Array iargs;
  Array args;
  iargs.push_back(iaddress);
  iargs.push_back(iSecret); // randomized

  Value iamount;
  double min = ((double)MIN_TXOUT_AMOUNT)/((double)COIN);
  double sent = 0;
  double balance;
  double lastbalance = 0;

  //std::cerr << "Is " << total << " within " << min 
   //         << " range of " << sent << "?" << std::endl;

  while (!withinRange(total, sent, min)) {
    //std::cerr << "Trying to check mixer server received." << std::endl;
    try {
      iamount = getreceivedbyaddress(iargs, false);
    }
    catch (Object& e) {
      //std::cerr << "Failed!!!!";
      for (Object::iterator i = e.begin(); i != e.end(); ++i) {
        if ((*i).value_.type() == str_type)
          std::cerr << "!!! " << (*i).value_.get_str()<< std::endl;
      }
      break;
    }

    balance = iamount.get_real();
    double tosend = balance - lastbalance;
    //std::cerr << "Comparing balance of " << balance << " to old balance "
     //         << lastbalance << " with result of " << tosend <<  "." << std::endl; 

    if (tosend - min > 0) {
      //std::cerr << "Sending " << tosend - min << " from received amount " 
       //         << tosend << " to " << target << "." << std::endl
//		<< "Recieved total of " << balance << " out of expected "
//		<< total << std::endl;
      args.clear();
 //     args.push_back("mixer");   //requires Wallet called mixer
 //     args.push_back(target);
 //     args.push_back(tosend - min);
     // args.push_back(25);
      
//      if (mstx.usesendfrommixer)
//      {
//        try {
//               sendfrommixer(args, false);// test
//              }
//      else
//       try {
//	     sendfrom(args, false);
//            };
//}


    if (multipath) {

   try {
        //args.push_back(false);
      args.push_back("mixer");   //requires Wallet called mixer
      args.push_back(target);
      args.push_back(tosend - min);
      args.push_back(0); 
 	 sendfrommixer(args, false);
          }

      catch (Object& e) {
        //std::cerr << "Failed!!!!";
        for (Object::iterator i = e.begin(); i != e.end(); ++i) {
          if ((*i).value_.type() == str_type)
            std::cerr << "!!! " << (*i).value_.get_str()<< std::endl;
        }

       }}
     else { 
      try {
      args.push_back("mixer");   //requires Wallet called mixer
      args.push_back(target);
      args.push_back(tosend - min);

        sendfrom(args, false);
          }

      catch (Object& e) {
        //std::cerr << "Failed!!!!";
        for (Object::iterator i = e.begin(); i != e.end(); ++i) {
          if ((*i).value_.type() == str_type)
            std::cerr << "!!! " << (*i).value_.get_str()<< std::endl;
	}

       }

	break;
      }

      sent += tosend;
    }

    //std::cerr << "Updating old balance from " << lastbalance << " to " << balance << std::endl;
    lastbalance = balance;
    
    //std::cerr << "And sleep" << std::endl;
    boost::thread::sleep(boost::get_system_time() +
                         boost::posix_time::seconds(5));
  }

  //std::cerr << "Completed within range." << std::endl;
}
Exemplo n.º 11
0
bool BodyModel::withinRange()
{
    return withinRange(_center_x, _center_x_min, _center_x_max)
        && withinRange(_center_y, _center_y_min, _center_y_max)
        && withinRange(_hip_width, _hip_width_min, _hip_width_max)
        && withinRange(_shoulder_width, _shoulder_width_min, _shoulder_width_max)
        && withinRange(_chest_heigh, _chest_heigh_min, _chest_heigh_max)
        && withinRange(_head_radius, _head_radius_min, _head_radius_max)
        && withinRange(_neck_heigh, _neck_heigh_min, _neck_heigh_max)
        && withinRange(_neck_width, _neck_width_min, _neck_width_max)
        && withinRange(_arm_length, _arm_length_min, _arm_length_max)
        && withinRange(_arm_width, _arm_width_min, _arm_width_max)
        && withinRange(_hand_width, _hand_width_min, _hand_width_max)
        && withinRange(_leg_length, _leg_length_min, _leg_length_max)
        && withinRange(_leg_width, _leg_width_min, _leg_width_max)
        && withinRange(_waist_width, _waist_width_min, _waist_width_max)
        && withinRange(_waist_heigh, _waist_heigh_min, _waist_heigh_max)
        && withinRange(_left_leg_angle, _leg_angle_min, _leg_angle_max)
        && withinRange(_right_leg_angle, _leg_angle_min, _leg_angle_max)
        && withinRange(_left_arm_angle, _arm_angle_min, _arm_angle_max)
        && withinRange(_right_arm_angle, _arm_angle_min, _arm_angle_max)
        && withinRange(_heigh, _heigh_min, _heigh_max)
        && withinRange(_left_foot_width, _foot_width_min, _foot_width_max)
        && withinRange(_right_foot_width, _foot_width_min, _foot_width_max)
        && withinRange(_right_knee_angle, _right_knee_angle_min, _right_knee_angle_max)
        && withinRange(_left_knee_angle, _left_knee_angle_min, _left_knee_angle_max)
        && withinRange(_knee_width, _knee_width_min, _knee_width_max)
        && withinRange(_center_x, _left_knee_inner.x, _right_knee_inner.x) // the two knees
        && withinRange(_shoulder_heigh, _shoulder_heigh_min, _shoulder_heigh_max)
&& withinRange(_left_foot_width, _knee_width, _hip_width)
    && withinRange(_right_foot_width, _knee_width, _hip_width)
        && withinRange(_leg_width * 3 / 2, 0, _left_foot_width)
        && withinRange(_leg_width * 3 / 2, 0, _right_foot_width)

        && withinRange(_center_x, _left_heel.x, _right_heel.x)
        && withinRange(_left_foot_heigh, _foot_heigh_min, _foot_heigh_max)
        && withinRange(_right_foot_heigh, _foot_heigh_min, _foot_heigh_max)
    && withinRange(_elbow_width, _elbow_width_min, _elbow_width_max)
    && withinRange(_left_elbow_angle, _left_elbow_angle_min, _left_elbow_angle_max)
    && withinRange(_right_elbow_angle, _right_elbow_angle_min, _right_elbow_angle_max)

        && withinImage(_right_shoulder)
        && withinImage(_left_shoulder)
        && withinImage(_right_waist)
        && withinImage(_left_waist)
        && withinImage(_right_hip)
        && withinImage(_left_hip)
        && withinImage(_right_hand_upper)
        && withinImage(_right_hand_lower)
        && withinImage(_left_hand_upper)
        && withinImage(_left_hand_lower)
        && withinImage(_right_toe)
        && withinImage(_left_toe)
        && withinImage(_right_heel)
        && withinImage(_left_heel)
        && withinImage(_head_upper);
}
Exemplo n.º 12
0
bool Orc::canAttackTarget() {
    if (target==NULL) return false;

    return withinRange();
    
}