Beispiel #1
0
void PLAYER::Update()
{
  bool up = sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Z);
  bool down = sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S);
  bool left = sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Q);
  bool right = sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D);
  
  if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::C) && !Solid())
  {
    SetSolid(true);
  }
  if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::V) && Solid())
  {
    SetSolid(false);
  }
  
  if (up || down || left || right)
  {
    sprite.SetAnimation("white_run");
  }
  else
  {
    sprite.SetAnimation("white_idle");
  }
  SetSpeed( (right-left)*150, (down-up)*150 );
}
/**
 * 多面体データから distance field VolumeDataへの変換
 * @param w Width
 * @param h Height
 * @param d Depth
 * @retval true 変換成功
 * @retval false 変換失敗
 */
bool SolidDfToVolume::ToVolume(int w, int h, int d) {
    
    m_volume = BufferVolumeData::CreateInstance();
    
    int c = 1; // Store scalar density.
    m_volume->Create(w, h, d, c);
    
    //    assert(m_solid);
    //    assert(m_solid->Position());
    //    assert(m_solid->Position()->GetNum() > 0);
    
    float* voxels = m_volume->Buffer()->GetBuffer();
    
    const size_t fnum = w * h * d * c;
    for (size_t i = 0; i < fnum; i++) {
        voxels[i] = 0.0f; //-FLT_MAX; // @fixme
    }
    
    std::vector<int> countBuf(w * h * d, 0); // for compute avarage.
    
    float *position = m_solid->Position()->GetBuffer();
    
    size_t dim[3] = { w, h, d };
    float scale[3] = { (m_bmax[0] - m_bmin[0])/w, (m_bmax[1] - m_bmin[1])/h, (m_bmax[2] - m_bmin[2])/d };
    
    const int solid_n = m_solid->Position()->GetNum()/m_solid->GetType();
    const int solid_type = m_solid->GetType();
    
    std::vector<Solid> solids;
    solids.reserve(solid_n);
    
    for (int i = 0; i < solid_n; i++) {
        solids.push_back( Solid(position + solid_type * 3 * i, solid_type));
    }
    
    BVH bvh;
    bvh.generateBvhTree(solids);
    
    for (float x = m_bmin[0], y, z; x < m_bmax[0]; x += scale[0])
        for (y = m_bmin[1]; y < m_bmax[1]; y += scale[1])
            for (z = m_bmin[2]; z < m_bmax[2]; z += scale[2])
            {
                VX::Math::vec3 pt(x, y, z);
                float d = 1e16;
                bvh.searchNearestSolid(pt, d, 0);
                voxels[findLoc(x, y, z, m_bmin, m_bmax, dim)] = d;
            }
    
    printf("ToVolume: %zu, %zu, %zu\n", dim[0], dim[1], dim[2]);
    
    return true;
}
Beispiel #3
0
void Led_t::Blink(Color_t AColor, uint32_t ADelay) {
    if(ADelay == 0) {
        Solid(AColor);
        return;
    }
    Mode = lmBlink;
    Color = AColor;
    BlinkDelay = ADelay;
    IsOn = true;
    *PWM = AColor;
    Delay.Reset(&Timer);
    HasChanged = true;
}
Solid::Solid(int X, int Y, int Z, int W, int L, int H){
    Solid(X,Y,Z);
    w = W*32;
    l = L*32;
    h = H*32;
}