j'ai 2 type d'Image Entity :
- une normale, public de sf::drawable, qui prend en compte qu'un rectangle de vertex, _vertex[4]
- une IE_Light, qui prend en compte 36 vertex, _vertex[36]. Elle est contenue dans un vector , lui même contenue dans une IE normal.
Quand/si l'IE normale contiend une IE_Light, au moment de s'afficher lui même, il affiche également toutes ses IE_Light, après leur avoir demandé de se recalculer leurs position :
allé, pour le style, je met le code complet de la fonction
là mon IE normale :
void IE::draw ( sf::RenderWindow &window )
{
window.draw ( *this ) ;
for ( std::vector < IE_Light > :: iterator it = _IE_Light.begin() ; it != _IE_Light.end() ; )
{
if( ! it -> setLightPosition ( _vertex[0] ) )
{
it = _IE_Light.erase( it ) ;
}
else
{
window.draw ( *it ) ;
it ++ ;
}
}
}
et là une des IE_Light contenue dans l'IE normale :
bool IE_Light::setLightPosition ( sf::Vertex &vertex )
{
sf::Vector2f position = vertex.position ;
float x = _light -> getPosition().x ;
float y = _light -> getPosition().y ;
int sizeLight = _light -> getSize () ;
sf::Color color = _light -> getColor () ;
bool condition = true ;
if ( x + sizeLight/2 < position.x
|| x - sizeLight/2 > position.x + _texture -> getSize().x
|| y + sizeLight/2 < position.y
|| y - sizeLight/2 > position.y + _texture -> getSize().y )
{
condition = false ;
}
if( condition )
{
_vertex[0] = sf::Vector2f( x , y );
_vertex[1] = sf::Vector2f( x , y - sizeLight );
_vertex[2] = sf::Vector2f( x + sizeLight/2 , y - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[3] = sf::Vector2f( x , y );
_vertex[4] = sf::Vector2f( x + sizeLight/2 , y - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[5] = sf::Vector2f( x + sqrt ( -( (sizeLight/2) * (sizeLight/2)) + (sizeLight * sizeLight) ) , y - sizeLight/2 );
_vertex[6] = sf::Vector2f( x , y );
_vertex[7] = sf::Vector2f( x + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y - sizeLight/2 );
_vertex[8] = sf::Vector2f( x + sizeLight , y );
_vertex[9] = sf::Vector2f( x , y );
_vertex[10] = sf::Vector2f( x + sizeLight , y );
_vertex[11] = sf::Vector2f( x + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y + sizeLight/2 );
_vertex[12] = sf::Vector2f( x , y );
_vertex[13] = sf::Vector2f( x + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y + sizeLight/2 );
_vertex[14] = sf::Vector2f( x + sizeLight/2 , y + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[15] = sf::Vector2f( x , y );
_vertex[16] = sf::Vector2f( x + sizeLight/2 , y + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[17] = sf::Vector2f( x , y + sizeLight );
_vertex[18] = sf::Vector2f( x , y );
_vertex[19] = sf::Vector2f( x , y + sizeLight );
_vertex[20] = sf::Vector2f( x - sizeLight/2 , y + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[21] = sf::Vector2f( x , y );
_vertex[22] = sf::Vector2f( x - sizeLight/2 , y + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[23] = sf::Vector2f( x - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y + sizeLight/2 );
_vertex[24] = sf::Vector2f( x , y );
_vertex[25] = sf::Vector2f( x - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y + sizeLight/2 );
_vertex[26] = sf::Vector2f( x - sizeLight , y );
_vertex[27] = sf::Vector2f( x , y );
_vertex[28] = sf::Vector2f( x - sizeLight , y );
_vertex[29] = sf::Vector2f( x - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y - sizeLight/2 );
_vertex[30] = sf::Vector2f( x , y );
_vertex[31] = sf::Vector2f( x - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y - sizeLight/2 );
_vertex[32] = sf::Vector2f( x - sizeLight/2 , y - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[33] = sf::Vector2f( x , y );
_vertex[34] = sf::Vector2f( x - sizeLight/2 , y - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[35] = sf::Vector2f( x , y - sizeLight );
x = _light -> getPosition().x - position.x + vertex.texCoords.x ;
y = _light -> getPosition().y - position.y + vertex.texCoords.y ;
_vertex[0].texCoords = sf::Vector2f( x , y );
_vertex[1].texCoords = sf::Vector2f( x , y - sizeLight );
_vertex[2].texCoords = sf::Vector2f( x + sizeLight/2 , y - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[3].texCoords = sf::Vector2f( x , y );
_vertex[4].texCoords = sf::Vector2f( x + sizeLight/2 , y - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[5].texCoords = sf::Vector2f( x + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y - sizeLight/2 );
_vertex[6].texCoords = sf::Vector2f( x , y );
_vertex[7].texCoords = sf::Vector2f( x + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y - sizeLight/2 );
_vertex[8].texCoords = sf::Vector2f( x + sizeLight , y );
_vertex[9].texCoords = sf::Vector2f( x , y );
_vertex[10].texCoords = sf::Vector2f( x + sizeLight , y );
_vertex[11].texCoords = sf::Vector2f( x + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y + sizeLight/2 );
_vertex[12].texCoords = sf::Vector2f( x , y );
_vertex[13].texCoords = sf::Vector2f( x + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y + sizeLight/2 );
_vertex[14].texCoords = sf::Vector2f( x + sizeLight/2 , y + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[15].texCoords = sf::Vector2f( x , y );
_vertex[16].texCoords = sf::Vector2f( x + sizeLight/2 , y + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[17].texCoords = sf::Vector2f( x , y + sizeLight );
_vertex[18].texCoords = sf::Vector2f( x , y );
_vertex[19].texCoords = sf::Vector2f( x , y + sizeLight );
_vertex[20].texCoords = sf::Vector2f( x - sizeLight/2 , y + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[21].texCoords = sf::Vector2f( x , y );
_vertex[22].texCoords = sf::Vector2f( x - sizeLight/2 , y + sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[23].texCoords = sf::Vector2f( x - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y + sizeLight/2 );
_vertex[24].texCoords = sf::Vector2f( x , y );
_vertex[25].texCoords = sf::Vector2f( x - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y + sizeLight/2 );
_vertex[26].texCoords = sf::Vector2f( x - sizeLight , y );
_vertex[27].texCoords = sf::Vector2f( x , y );
_vertex[28].texCoords = sf::Vector2f( x - sizeLight , y );
_vertex[29].texCoords = sf::Vector2f( x - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y - sizeLight/2 );
_vertex[30].texCoords = sf::Vector2f( x , y );
_vertex[31].texCoords = sf::Vector2f( x - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) , y - sizeLight/2 );
_vertex[32].texCoords = sf::Vector2f( x - sizeLight/2 , y - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[33].texCoords = sf::Vector2f( x , y );
_vertex[34].texCoords = sf::Vector2f( x - sizeLight/2 , y - sqrt ( -( (sizeLight/2) * (sizeLight/2) ) + (sizeLight * sizeLight) ) );
_vertex[35].texCoords = sf::Vector2f( x , y - sizeLight );
_vertex[0].color = sf::Color( color );
_vertex[1].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[2].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[3].color = sf::Color( color );
_vertex[4].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[5].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[6].color = sf::Color( color );
_vertex[7].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[8].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[9].color = sf::Color( color );
_vertex[10].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[11].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[12].color = sf::Color( color );
_vertex[13].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[14].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[15].color = sf::Color( color );
_vertex[16].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[17].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[18].color = sf::Color( color );
_vertex[19].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[20].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[21].color = sf::Color( color );
_vertex[22].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[23].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[24].color = sf::Color( color );
_vertex[25].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[26].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[27].color = sf::Color( color );
_vertex[28].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[29].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[30].color = sf::Color( color );
_vertex[31].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[32].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[33].color = sf::Color( color );
_vertex[34].color = sf::Color( 0 , 0 , 0 , 0 );
_vertex[35].color = sf::Color( 0 , 0 , 0 , 0 );
}
return condition ;
}
un exemple en plus grand d'une scène comprenant plusieurs types de Lights :