Esempio n. 1
0
void DisplayTileConfig::parseConfig(const Setting& sTile, DisplayConfig& cfg)
{
    settingData = &sTile;

    DisplayTileConfig* tc = this;

    tc->name = sTile.getName();

    String sm = Config::getStringValue("stereoMode", sTile, "default");
    StringUtils::toLowerCase(sm);
    if(sm == "default") tc->stereoMode = DisplayTileConfig::Default;
    else if(sm == "mono") tc->stereoMode = DisplayTileConfig::Mono;
        // 'interleaved' defaults to row interleaved
    else if(sm == "interleaved") tc->stereoMode = DisplayTileConfig::LineInterleaved;
    else if(sm == "rowinterleaved") tc->stereoMode = DisplayTileConfig::LineInterleaved;
    else if(sm == "columninterleaved") tc->stereoMode = DisplayTileConfig::ColumnInterleaved;
    else if(sm == "sidebyside") tc->stereoMode = DisplayTileConfig::SideBySide;
                
    tc->invertStereo = Config::getBoolValue("invertStereo", sTile);
    tc->enabled = Config::getBoolValue("enabled", sTile);
                
    //tc.index = index;
    //tc.interleaved = Config::getBoolValue("interleaved", sTile);
    tc->device = Config::getIntValue("device", sTile);

    tc->center = Config::getVector3fValue("center", sTile, Vector3f::Zero());
    tc->yaw = Config::getFloatValue("yaw", sTile, 0);
    tc->pitch = Config::getFloatValue("pitch", sTile, 0);

    tc->position = Config::getVector2iValue("position", sTile);
    tc->disableScene = Config::getBoolValue("disableScene", sTile);

    tc->offscreen = Config::getBoolValue("offscreen", sTile, false);
    tc->borderless = Config::getBoolValue("borderless", sTile, cfg.borderless);

    tc->disableMouse = Config::getBoolValue("disableMouse", sTile, false);

    tc->isHMD = Config::getBoolValue("isHMD", sTile, false);

    //tc->viewport = Config::getVector4fValue("viewport", sTile, tc->viewport);

    // If the tile config contains a size entry use it, oterwise use the default tile and bezel size data
    if(sTile.exists("size"))
    {
        tc->size = Config::getVector2fValue("size", sTile);
    }
    else
    {
        tc->size = cfg.tileSize - cfg.bezelSize;
    }

    if(sTile.exists("resolution"))
    {
        tc->pixelSize = Config::getVector2iValue("resolution", sTile);
    }
    else
    {
        tc->pixelSize = cfg.tileResolution;
    }

    if(sTile.exists("offset"))
    {
        tc->offset = Config::getVector2iValue("offset", sTile);
    }
    else
    {
        std::vector<std::string> args = StringUtils::split(String(sTile.getName()), "xt");
        Vector2i index = Vector2i(atoi(args[0].c_str()), atoi(args[1].c_str()));
        tc->offset = index.cwiseProduct(tc->pixelSize);
        cfg.tileGrid[index[0]][index[1]] = tc;
    }

    // Parse custom grid options
    tc->isInGrid = Config::getBoolValue("isInGrid", sTile, false);
    if(tc->isInGrid)
    {
        tc->gridX = Config::getIntValue("gridX", sTile, 0);
        tc->gridY = Config::getIntValue("gridY", sTile, 0);
        cfg.tileGrid[tc->gridX][tc->gridY] = tc;
    }

    // Custom camera
    tc->cameraName = Config::getStringValue("cameraName", sTile, "");

    // Compute default values for this tile corners. These values may be overwritted by display config generators applied later on.
    computeTileCorners();
}
bool CylindricalDisplayConfig::buildConfig(DisplayConfig& cfg, Setting& scfg)
{
    Vector2i numTiles = Config::getVector2iValue("numTiles", scfg);
    cfg.tileGridSize = numTiles;

    cfg.canvasPixelSize = numTiles.cwiseProduct(cfg.tileResolution);
    ofmsg("canvas pixel size: %1%", %cfg.canvasPixelSize);

    int numSides = numTiles.x();
    
    // Angle increment for each side (column)
    float sideAngleIncrement = Config::getFloatValue("sideAngleIncrement", scfg, 90);

    // Angle of side containing 0-index tiles.
    float sideAngleStart = Config::getFloatValue("sideAngleStart", scfg, -90);

    // Display system cylinder radius
    myRadius = Config::getFloatValue("radius", scfg, 5);

    // Number of vertical tiles in each side
    int numSideTiles = numTiles.y();

    // Offset of center of bottom tile.
    float yOffset = cfg.referenceOffset.y();

    // Save offset of low end of bottom tile (subtract center)
    myYOffset = yOffset - cfg.tileSize.y() / 2;

    // Save cylinder height
    myHeight = numSideTiles * cfg.tileSize.y();

    float tileViewportWidth = 1.0f / numTiles[0];
    float tileViewportHeight = 1.0f / numTiles[1];
    float tileViewportX = 0.0f;
    float tileViewportY = 0.0f;

    // Fill up the tile position / orientation data.
    // Compute the edge coordinates for all sides
    float curAngle = sideAngleStart;
    for(int x = 0; x < numSides; x ++)
    {
        float yPos = yOffset;
        for(int y = 0; y < numSideTiles; y ++)
        {
            // Use the indices to create a tile name in the form t<X>x<Y> (i.e. t1x0).
            // This is kind of hacking, because it forces tile names to be in that form for cylindrical configurations, 
            // but it works well enough.
            String tileName = ostr("t%1%x%2%", %x %y);
            if(cfg.tiles.find(tileName) == cfg.tiles.end())
            {
                ofwarn("CylindricalDisplayConfig::buildConfig: could not find tile '%1%'", %tileName);
            }
            else
            {
                DisplayTileConfig* tc = cfg.tiles[tileName];
                cfg.tileGrid[x][y] = tc;
                
                tc->enabled = true;
                tc->isInGrid = true;
                tc->gridX = x;
                tc->gridY = y;
                
                tc->yaw = curAngle;
                tc->pitch = 0;
                tc->center = Vector3f(
                    sin(curAngle * Math::DegToRad) * myRadius,
                    yPos,
                    -1 * cos(curAngle * Math::DegToRad) * myRadius);

                // Save the tile viewport
                //tc->viewport = Vector4f(tileViewportX, tileViewportY, tileViewportWidth, tileViewportHeight);
                
                // Compute this tile pixel offset.
                // Note that the tile row index is inverted wrt. pixel coordinates 
                // (tile row 0 is at the bottom of the cylinder, while pixel 
                // row 0 is at the top). We take this into account to compute
                // correct pixel offsets for each tile.
                tc->offset[0] = tc->pixelSize[0] * x;
                tc->offset[1] = tc->pixelSize[1] * (numSideTiles - y - 1);

                tc->computeTileCorners();
            }
            yPos += cfg.tileSize.y();
            tileViewportY += tileViewportHeight;
        }