示例#1
0
文件: tilemap.cpp 项目: onidev/onidev
bool TileMap::collision(const od::Shape * shape, float x, float y) const
{
    od::Rect box = shape->boundingBox();
    //od::Rect box = shape->boundingBox().translate(xoffset(), yoffset());
    
    // + ou -? => a verifier
    x -= xoffset();
    y -= yoffset();
    
    int x1 = (x + box.x1    ) / tileWidth();
    int x2 = (x + box.x2 - 1) / tileWidth();
    int y1 = (y + box.y1    ) / tileHeight();
    int y2 = (y + box.y2 - 1) / tileHeight();
    
    if(x1 < 0) x1 = 0;
    if(y1 < 0) y1 = 0;
    if(x2 > width()- 1) x2 = width()-1;
    if(y2 > height()-1) y2 = height()-1;
    
    for(int i=x1; i<=x2; ++i)
    {
        for(int j=y1; j<=y2; ++j)
        {
            const od::Shape * tile = tileCollisionMask(i, j);
            if(tile && tileSolid(i, j) && shape->collide(*tile, i * tileWidth() - x, j * tileHeight() - y))
                return true;
        }
    }
    return false;
}
示例#2
0
    virtual void renderFinished(const Camera*)
    {
      GLCHECK4()
      CHECK(texture()->dimension() == TD_TEXTURE_1D)

      glDrawBuffer(drawBuffer()); GLCHECK4()
      glBindTexture(TD_TEXTURE_1D, texture()->handle() ); GLCHECK4()
      glCopyTexSubImage1D(TD_TEXTURE_1D, level(), xoffset(), x(), y(), width()); GLCHECK4()
      glBindTexture(TD_TEXTURE_1D, 0 ); GLCHECK4()
    }
示例#3
0
    QString TileMapAdapter::query(int x, int y, int z) const
    {
        x = xoffset(x);
        y = yoffset(y);

        int a[3] = {z, x, y};
        return QString(serverPath).replace(order[2][0],2, loc.toString(a[order[2][1]]))
                .replace(order[1][0],2, loc.toString(a[order[1][1]]))
                .replace(order[0][0],2, loc.toString(a[order[0][1]]));

    }
//==============================================================================
void
face_detector::
train(ft_data &data,
      const string fname,
      const Mat &ref,
      const bool mirror,
      const bool visi,
      const float frac,
      const float scaleFactor,
      const int minNeighbours,
      const Size minSize)
{
  detector.load(fname.c_str()); detector_fname = fname; reference = ref.clone();
  vector<float> xoffset(0),yoffset(0),zoffset(0);
  for(int i = 0; i < data.n_images(); i++){
    Mat im = data.get_image(i,0); if(im.empty())continue;
    vector<Point2f> p = data.get_points(i,false); int n = p.size();
    Mat pt = Mat(p).reshape(1,2*n);
    vector<Rect> faces; Mat eqIm; equalizeHist(im,eqIm);
    detector.detectMultiScale(eqIm,faces,scaleFactor,minNeighbours,0
                  |CV_HAAR_FIND_BIGGEST_OBJECT
                  |CV_HAAR_SCALE_IMAGE,minSize);
    if(faces.size() >= 1){
      if(visi){
    Mat I; cvtColor(im,I,CV_GRAY2RGB);
    for(int i = 0; i < n; i++)circle(I,p[i],1,CV_RGB(0,255,0),2,CV_AA);
    rectangle(I,faces[0].tl(),faces[0].br(),CV_RGB(255,0,0),3);
    imshow("face detector training",I); waitKey(10); 
      }
      //check if enough points are in detected rectangle
      if(this->enough_bounded_points(pt,faces[0],frac)){
    Point2f center = this->center_of_mass(pt); float w = faces[0].width;
    xoffset.push_back((center.x - (faces[0].x+0.5*faces[0].width ))/w);
    yoffset.push_back((center.y - (faces[0].y+0.5*faces[0].height))/w);
    zoffset.push_back(this->calc_scale(pt)/w);
      }
    }
    if(mirror){
      im = data.get_image(i,1); if(im.empty())continue;
      p = data.get_points(i,true);
      pt = Mat(p).reshape(1,2*n);
      equalizeHist(im,eqIm);
      detector.detectMultiScale(eqIm,faces,scaleFactor,minNeighbours,0
                  |CV_HAAR_FIND_BIGGEST_OBJECT
                |CV_HAAR_SCALE_IMAGE,minSize);
      if(faces.size() >= 1){
    if(visi){
      Mat I; cvtColor(im,I,CV_GRAY2RGB);
      for(int i = 0; i < n; i++)circle(I,p[i],1,CV_RGB(0,255,0),2,CV_AA);
      rectangle(I,faces[0].tl(),faces[0].br(),CV_RGB(255,0,0),3);
      imshow("face detector training",I); waitKey(10);
    }
    //check if enough points are in detected rectangle
    if(this->enough_bounded_points(pt,faces[0],frac)){
      Point2f center = this->center_of_mass(pt); float w = faces[0].width;
      xoffset.push_back((center.x - (faces[0].x+0.5*faces[0].width ))/w);
      yoffset.push_back((center.y - (faces[0].y+0.5*faces[0].height))/w);
      zoffset.push_back(this->calc_scale(pt)/w);
    }
      }
    }
  }
  //choose median value
  Mat X = Mat(xoffset),Xsort,Y = Mat(yoffset),Ysort,Z = Mat(zoffset),Zsort;
  cv::sort(X,Xsort,CV_SORT_EVERY_COLUMN|CV_SORT_ASCENDING); int nx = Xsort.rows;
  cv::sort(Y,Ysort,CV_SORT_EVERY_COLUMN|CV_SORT_ASCENDING); int ny = Ysort.rows;
  cv::sort(Z,Zsort,CV_SORT_EVERY_COLUMN|CV_SORT_ASCENDING); int nz = Zsort.rows;
  detector_offset = Vec3f(Xsort.fl(nx/2),Ysort.fl(ny/2),Zsort.fl(nz/2)); return;
}