void Map::SetValues(unsigned int x, unsigned int y, float uOffset, float vOffset, float r, float g, float b)
{
    int index = ((y )* GRID_WIDTH) + x;
    if( index >= GRID_HEIGHT * GRID_WIDTH )
    {
        return;
    }

    if( m_vertices == NULL )
    {
        m_vBuffer->Lock( 0, 0, (void**)&m_vertices, 0 );
    }

    PosColNormalUVVertex* v = &m_vertices[ index ];

    static const float invWidth = 1.0f / ( GRID_WIDTH - 1 );
    static const float invHeight = 1.0f / ( GRID_HEIGHT - 1 );

    if( m_timed )
    {
        v->u = ((float)x * invWidth ) + (0.5f / TEX_WIDTH)  + ( ( uOffset ) * invWidth );
        v->v = ((float)y * invHeight ) + (0.5f / TEX_HEIGHT) + ( ( vOffset ) * invHeight );
        /*		unsigned char* col = (unsigned char*)&v->Diffuse;
        		col[3] = 0xff;
        		col[2] = int(MapCol(r) * 255);
        		col[1] = int(MapCol(g) * 255);
        		col[0] = int(MapCol(b) * 255);
        */
        v->FDiffuse.x = MapCol(r);
        v->FDiffuse.y = MapCol(g);
        v->FDiffuse.z = MapCol(b);
        v->FDiffuse.w = 1.0f;
    }
    else
    {
        v->u = ((float)x * invWidth ) + (0.5f / TEX_WIDTH)  + ((uOffset));
        v->v = ((float)y * invHeight ) + (0.5f / TEX_HEIGHT) + ((vOffset));
//		unsigned char* col = (unsigned char*)&v->Diffuse;
// 		col[3] = 0xff;
// 		col[2] = int(Clamp(r) * 255);
// 		col[1] = int(Clamp(g) * 255);
// 		col[0] = int(Clamp(b) * 255);
        v->FDiffuse.x = r;
        v->FDiffuse.y = g;
        v->FDiffuse.z = b;
        v->FDiffuse.w = 1;
    }
}
Esempio n. 2
0
File: Map.cpp Progetto: alexhod/xbmc
void Map::SetValues(unsigned int x, unsigned int y, float uOffset, float vOffset, float r, float g, float b)
{
    int index = ((y )* GRID_WIDTH) + x;
    if( index >= GRID_HEIGHT * GRID_WIDTH )
    {
        return;
    }

    if( m_vertices == NULL )
    {
        D3D11_MAPPED_SUBRESOURCE res;
        Renderer::GetContext()->Map(m_vBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &res);
        m_vertices = (PosColNormalUVVertex*)res.pData;
    }

    PosColNormalUVVertex* v = &m_vertices[ index ];

    static const float invWidth = 1.0f / ( GRID_WIDTH - 1 );
    static const float invHeight = 1.0f / ( GRID_HEIGHT - 1 );

    if( m_timed )
    {
        v->u = ((float)x * invWidth ) + (0.5f / TEX_WIDTH)  + ( ( uOffset ) * invWidth );
        v->v = ((float)y * invHeight ) + (0.5f / TEX_HEIGHT) + ( ( vOffset ) * invHeight );
        v->FDiffuse.x = MapCol(r);
        v->FDiffuse.y = MapCol(g);
        v->FDiffuse.z = MapCol(b);
        v->FDiffuse.w = 1.0f;
    }
    else
    {
        v->u = ((float)x * invWidth ) + (0.5f / TEX_WIDTH)  + ((uOffset));
        v->v = ((float)y * invHeight ) + (0.5f / TEX_HEIGHT) + ((vOffset));
        v->FDiffuse.x = r;
        v->FDiffuse.y = g;
        v->FDiffuse.z = b;
        v->FDiffuse.w = 1;
    }
}