Beispiel #1
0
void RasterNode::calcTexCoords()
{
    glm::vec2 textureSize = glm::vec2(m_pSurface->getTextureSize());
    glm::vec2 imageSize = glm::vec2(m_pSurface->getSize());
    glm::vec2 texCoordExtents = glm::vec2(imageSize.x/textureSize.x,
            imageSize.y/textureSize.y);

    glm::vec2 texSizePerTile;
    if (m_TileSize.x == -1) {
        texSizePerTile = texCoordExtents;
    } else {
        texSizePerTile = glm::vec2(float(m_TileSize.x)/imageSize.x*texCoordExtents.x,
                float(m_TileSize.y)/imageSize.y*texCoordExtents.y);
    }

    IntPoint numTiles = getNumTiles();
    vector<glm::vec2> texCoordLine(numTiles.x+1);
    m_TexCoords = std::vector<std::vector<glm::vec2> > 
            (numTiles.y+1, texCoordLine);
    for (unsigned y = 0; y < m_TexCoords.size(); y++) {
        for (unsigned x = 0; x < m_TexCoords[y].size(); x++) {
            if (y == m_TexCoords.size()-1) {
                m_TexCoords[y][x].y = texCoordExtents.y;
            } else {
                m_TexCoords[y][x].y = texSizePerTile.y*y;
            }
            if (x == m_TexCoords[y].size()-1) {
                m_TexCoords[y][x].x = texCoordExtents.x;
            } else {
                m_TexCoords[y][x].x = texSizePerTile.x*x;
            }
        }
    }
}
Beispiel #2
0
Tile* WorldSegment::getTile(uint32_t index)
{
    if(index < 0 || index>=getNumTiles() ) {
        return NULL;
    }
    return tiles[index].IsValid() ? &(tiles[index]) : NULL;
}
Beispiel #3
0
  LocalFrameBuffer::LocalFrameBuffer(const vec2i &size,
                                     ColorBufferFormat colorBufferFormat,
                                     const uint32 channels,
                                     void *colorBufferToUse)
    : FrameBuffer(size, colorBufferFormat, channels)
      , tileErrorRegion(hasVarianceBuffer ? getNumTiles() : vec2i(0))
  {
    Assert(size.x > 0);
    Assert(size.y > 0);
    if (colorBufferToUse)
      colorBuffer = colorBufferToUse;
    else {
      switch (colorBufferFormat) {
      case OSP_FB_NONE:
        colorBuffer = nullptr;
        break;
      case OSP_FB_RGBA8:
      case OSP_FB_SRGBA:
        colorBuffer = (uint32*)alignedMalloc(sizeof(uint32)*size.x*size.y);
        break;
      case OSP_FB_RGBA32F:
        colorBuffer = (vec4f*)alignedMalloc(sizeof(vec4f)*size.x*size.y);
        break;
      }
    }

    depthBuffer = hasDepthBuffer ? alignedMalloc<float>(size.x*size.y) :
      nullptr;

    accumBuffer = hasAccumBuffer ? alignedMalloc<vec4f>(size.x*size.y) :
      nullptr;

    const size_t bytes = sizeof(int32)*getTotalTiles();
    tileAccumID = (int32*)alignedMalloc(bytes);
    memset(tileAccumID, 0, bytes);

    varianceBuffer = hasVarianceBuffer ? alignedMalloc<vec4f>(size.x*size.y) :
      nullptr;

    normalBuffer = hasNormalBuffer ? alignedMalloc<vec3f>(size.x*size.y) :
      nullptr;

    albedoBuffer = hasAlbedoBuffer ? alignedMalloc<vec3f>(size.x*size.y) :
      nullptr;


    ispcEquivalent = ispc::LocalFrameBuffer_create(this,size.x,size.y,
                                                   colorBufferFormat,
                                                   colorBuffer,
                                                   depthBuffer,
                                                   accumBuffer,
                                                   varianceBuffer,
                                                   normalBuffer,
                                                   albedoBuffer,
                                                   tileAccumID);
  }
Beispiel #4
0
void RasterNode::calcVertexGrid(VertexGrid& grid)
{
    IntPoint numTiles = getNumTiles();
    std::vector<glm::vec2> TileVerticesLine(numTiles.x+1);
    grid = std::vector<std::vector<glm::vec2> > (numTiles.y+1, TileVerticesLine);
    for (unsigned y = 0; y < grid.size(); y++) {
        for (unsigned x = 0; x < grid[y].size(); x++) {
            calcTileVertex(x, y, grid[y][x]);
        }
    }
}
Beispiel #5
0
void RasterNode::calcTileVertex(int x, int y, glm::vec2& Vertex) 
{
    IntPoint numTiles = getNumTiles();
    if (x < numTiles.x) {
        Vertex.x = float(m_TileSize.x*x) / m_pSurface->getSize().x;
    } else {
        Vertex.x = 1;
    }
    if (y < numTiles.y) {
        Vertex.y = float(m_TileSize.y*y) / m_pSurface->getSize().y;
    } else {
        Vertex.y = 1;
    }
}
void CvArea::changeNumTiles(int iChange)
{
	bool bOldLake;

	if (iChange != 0)
	{
		bOldLake = isLake();

		m_iNumTiles += iChange;
		FAssert(getNumTiles() >= 0);

		if (bOldLake != isLake())
		{
			GC.getMapINLINE().updateYield();
		}
	}
}
Beispiel #7
0
void RasterNode::setWarpedVertexCoords(const VertexGrid& grid)
{
    checkDisplayAvailable("setWarpedVertexCoords");
    bool bGridOK = true;
    IntPoint numTiles = getNumTiles();
    if (grid.size() != (unsigned)(numTiles.y+1)) {
        bGridOK = false;
    }
    for (unsigned i = 0; i < grid.size(); ++i) {
        if (grid[i].size() != (unsigned)(numTiles.x+1)) {
            bGridOK = false;
        }
    }
    if (!bGridOK) {
        throw Exception(AVG_ERR_OUT_OF_RANGE,
                "setWarpedVertexCoords() called with incorrect grid size.");
    }
    if (m_bHasStdVertices) {
        m_bHasStdVertices = false;
        m_pSubVA = new SubVertexArray();
    }
    m_TileVertices = grid;
}
Beispiel #8
0
bool osgParticle::Particle::update(double dt, bool onlyTimeStamp)
{
    // this method should return false when the particle dies;
    // so, if we were instructed to die, do it now and return.
    if (_mustdie) {
        _alive = -1.0;
        return false;
    }

    double x = 0;

    // if we don't live forever, compute our normalized age.
    if (_lifeTime > 0) {
        x = _t0 / _lifeTime;
    }

    _t0 += dt;

    // if our age is over the lifetime limit, then die and return.
    if (x > 1) {
        _alive = -1.0;
        return false;
    }

    // compute the current values for size, alpha and color.
    if (_lifeTime <= 0) {
       if (dt == _t0) {
          _current_size = _sr.get_random();
          _current_alpha = _ar.get_random();
          _current_color = _cr.get_random();
       }
    } else {
       _current_size = _si.get()->interpolate(x, _sr);
       _current_alpha = _ai.get()->interpolate(x, _ar);
       _current_color = _ci.get()->interpolate(x, _cr);
    }

    // update position
    _prev_pos = _position;
    _position += _velocity * dt;

    // return now if we indicate that only time stamp should be updated
    // the shader will handle remain properties in this case
    if (onlyTimeStamp) return true;

    //Compute the current texture tile based on our normalized age
    int currentTile = _start_tile + static_cast<int>(x * getNumTiles());

    //If the current texture tile is different from previous, then compute new texture coords
    if(currentTile != _cur_tile)
    {

        _cur_tile = currentTile;
        _s_coord = _s_tile * fmod(_cur_tile , 1.0 / _s_tile);
        _t_coord = 1.0 - _t_tile * (static_cast<int>(_cur_tile * _t_tile) + 1);

        // OSG_NOTICE<<this<<" setting tex coords "<<_s_coord<<" "<<_t_coord<<std::endl;
    }

    // update angle
    _prev_angle = _angle;
    _angle += _angul_arvel * dt;

    if (_angle.x() > osg::PI*2) _angle.x() -= osg::PI*2;
    if (_angle.x() < -osg::PI*2) _angle.x() += osg::PI*2;
    if (_angle.y() > osg::PI*2) _angle.y() -= osg::PI*2;
    if (_angle.y() < -osg::PI*2) _angle.y() += osg::PI*2;
    if (_angle.z() > osg::PI*2) _angle.z() -= osg::PI*2;
    if (_angle.z() < -osg::PI*2) _angle.z() += osg::PI*2;

    return true;
}
int CvArea::getNumUnrevealedTiles(TeamTypes eIndex) const
{
	return (getNumTiles() - getNumRevealedTiles(eIndex));
}
int CvArea::getNumUnownedTiles() const
{
	return (getNumTiles() - getNumOwnedTiles());
}
bool CvArea::isLake() const
{
	return (isWater() && (getNumTiles() <= GC.getLAKE_MAX_AREA_SIZE()));
}