Exemplo n.º 1
0
void MainBottomWidget::initAnimation()
{
    QRect mainRect(0, 240, 900, 360);
    QRect origRect(0, 440, 900, 160);
    m_examineAnimation = new QPropertyAnimation(this, "geometry");
    m_examineAnimation->setDuration(200);
    m_examineAnimation->setStartValue(origRect);
    m_examineAnimation->setEndValue(mainRect);


    m_returnAnimation = new QPropertyAnimation(this, "geometry");
    m_returnAnimation->setDuration(200);
    m_returnAnimation->setStartValue(mainRect);
    m_returnAnimation->setEndValue(origRect);

}
Exemplo n.º 2
0
void Player::Update(sf::Time elapsed, MB::EventList* events)
{
    MB::GameComponent::Update(elapsed, events);

    int dirX = 0;
    int dirY = 0;
    bool moved = false;

    sf::Vector2f origPos(this->playerSprite.getPosition());
    float origRot = this->playerSprite.getRotation();

    Game* g = (Game*)this->game;


    /*if(g->HasFocus()){*/
    if ( (this->actions->Exists("Player Move Up") && this->actions->Get("Player Move Up")->IsActive() ) ||
            ( this->actions->Exists("Player Move Up Alt") && this->actions->Get("Player Move Up Alt")->IsActive())) {
        dirY = -1;
        moved = true;
    }

    if ( (this->actions->Exists("Player Move Down") && this->actions->Get("Player Move Down")->IsActive() ) ||
            ( this->actions->Exists("Player Move Down Alt") && this->actions->Get("Player Move Down Alt")->IsActive())) {
        dirY = 1;
        moved = true;
    }

    if ( (this->actions->Exists("Player Move Left") && this->actions->Get("Player Move Left")->IsActive() ) ||
            ( this->actions->Exists("Player Move Left Alt") && this->actions->Get("Player Move Left Alt")->IsActive())) {
        dirX = -1;
        moved = true;
    }

    if ( (this->actions->Exists("Player Move Right") && this->actions->Get("Player Move Right")->IsActive() ) ||
            ( this->actions->Exists("Player Move Right Alt") && this->actions->Get("Player Move Right Alt")->IsActive())) {
        dirX = 1;
        moved = true;
    }

    //}


    sf::Vector2f direction(dirX,dirY);


    // Change position (based on elapsed time)
    // Limit elapsed time first
    float limitedElapsed = (float)elapsed.asMilliseconds();
    if(limitedElapsed > 31.0f) {
        limitedElapsed = 31.0f;
    }

    sf::Vector2f velocity(dirX * 1.f * limitedElapsed, dirY * 1.f * limitedElapsed);

    // Now check collision

    sf::IntRect origRect(this->playerSprite.getGlobalBounds());
    origRect.top = origPos.y;
    origRect.left = origPos.x;
    origRect.width = origRect.height = 32;

    // Slight offset correction (from origin)
    origRect.top -= 16;
    origRect.left -= 16;

    sf::Vector2f correctedVector = gameMap->collisionDetect(origRect, velocity, direction ) ;

    correctedVector.x += origPos.x;
    correctedVector.y += origPos.y;

    this->playerSprite.setPosition(correctedVector);

    // Set sprite orientation based on dir
    float rotation = 0.0f;

    // Diagonals

    if(dirY == -1 && dirX == -1) {
        rotation = 315.0f;
    } else if(dirY == -1 && dirX == 1) {
        rotation = 45.0f;
    } else if(dirY == 1 && dirX == -1) {
        rotation = 225.0f;
    } else if(dirY == 1 && dirX == 1) {
        rotation = 135.0f;
    }

    if(rotation == 0.0f) {
        if(dirY == 1) {
            rotation = 180.0f;
        } else if(dirX == -1) {
            rotation = 270.0f;
        } else if(dirX == 1) {
            rotation = 90.0f;
        }
    }

    this->playerSprite.setRotation(rotation);


    if(moved) {
        // Update the local copy of weapon hitbox only if moved
        UpdateWeaponHitBox();
        this->directionVector = sf::Vector2i(dirX,dirY);
        // Send Packet
        Packets packets;
        WorkQueues::packetsToSend().push(packets.CreateSendThisPlayerPos(playerSprite.getPosition(),playerSprite.getRotation()));

    } else {
        this->playerSprite.setRotation(origRot);
    }


    if (
        (this->actions->Exists("UseItem") && this->actions->Get("UseItem")->IsActive()) ||
        (this->actions->Exists("UseItem Alt") && this->actions->Get("UseItem Alt")->IsActive())
    )
    {
        this->UseItem();
    }
    this->attacking = false;
    if (this->game->GetActions()->Exists("Attack") && this->game->GetActions()->Get("Attack")->IsActive())
    {
        this->attacking = true;
        this->Attack();

    }
}
Exemplo n.º 3
0
ImageBlending::ImageBlending(std::vector<cv::Mat>&& images, std::vector<float>&& focal, std::vector<cv::Matx<float,3,3>>&& transforms)
: m_Images(std::forward<std::vector<cv::Mat>>(images)),
  m_FocalLengths(std::forward<std::vector<float>>(focal)),
  m_Transforms(std::forward<std::vector<cv::Matx<float,3,3>>>(transforms))
{
  std::vector<cv::Matx<float,3,3>> invTransforms;
  invTransforms.reserve(m_Transforms.size());
  
  for (cv::Matx<float,3,3>& mat : m_Transforms) {
    invTransforms.emplace_back();
    cv::invert(mat, invTransforms.back(), cv::DECOMP_SVD);
  }
  
  m_Bounds.reserve(m_Images.size());
  for (auto img = m_Images.begin(); img != m_Images.end(); ++img) {
    int index = img - m_Images.begin();
    cv::Matx<float,3,3>& mat = invTransforms[index];
    cv::Rect origRect(cv::Point(0,0), img->size());
    
    cv::Mat vertices(4, 1, CV_32FC2), verticesProj;
    vertices.at<cv::Point2f>(0, 0) = cv::Point2f(0, 0);
    vertices.at<cv::Point2f>(1, 0) = cv::Point2f(0, img->rows);
    vertices.at<cv::Point2f>(2, 0) = cv::Point2f(img->cols, img->rows);
    vertices.at<cv::Point2f>(3, 0) = cv::Point2f(img->cols, 0);
    cv::perspectiveTransform(vertices, verticesProj, mat);
    
    cv::Point topLeft, bottomRight;
    topLeft = bottomRight = verticesProj.at<cv::Point2f>(0,0);
    for (int i = 0; i < 4; ++i) {
      cv::Point2f pt = verticesProj.at<cv::Point2f>(i,0);
      topLeft.x = std::min(topLeft.x, (int)std::floor(pt.x));
      topLeft.y = std::min(topLeft.y, (int)std::floor(pt.y));
      bottomRight.x = std::max(bottomRight.x, (int)std::ceil(pt.x));
      bottomRight.y = std::max(bottomRight.y, (int)std::ceil(pt.y));
    }
    
    TransformedRect rect;
    rect.bound = cv::Rect(topLeft, bottomRight);
    for (int i = 0; i < 4; ++i)
      rect.vertex[i] = verticesProj.at<cv::Point2f>(i,0);
    m_Bounds.push_back(rect);
  }
  
  cv::Rect canvasBound = m_Bounds[0].bound;
  for (auto& rt : m_Bounds) {
    canvasBound = canvasBound | rt.bound;
  }
  printf("canvas: %d %d %d %d\n", canvasBound.x, canvasBound.y, canvasBound.width, canvasBound.height);
  
  for (auto rt = m_Bounds.begin(); rt != m_Bounds.end(); ++rt) {
    rt->bound.x -= canvasBound.x;
    rt->bound.y -= canvasBound.y;
    for (int i = 0; i < 4; ++i)
      rt->vertex[i] = rt->vertex[i] - cv::Point2f(canvasBound.tl());
    
    cv::Matx<float,3,3>& transform = m_Transforms[rt-m_Bounds.begin()];
    cv::Matx<float,3,3> trans;
    cv::setIdentity(trans);
    trans(0,2) += canvasBound.x;
    trans(1,2) += canvasBound.y;
    transform = transform * trans;
    
    //cv::Matx<float,3,3>& h = trans;
    //for (int i = 0; i < 3; ++i) {
    //  printf("    [ ");
    //  for (int j = 0; j < 3; ++j)
    //    printf("%f ", h(i,j));
    //  printf("]\n");
    //}
  }
  canvasBound.x = 0;
  canvasBound.y = 0;
  framebuffer.create(canvasBound.size(), CV_8UC3);
  stencilbuffer.create(canvasBound.size(), CV_8UC1);
  
}