Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[SFML 2.X] Generowanie Sprajtów Budynków z dachem dwuspadowym

Ostatnio zmodyfikowano 2024-11-09 18:16
Autor Wiadomość
pekfos
» 2024-11-07 22:13:50
Myślałem o czymś takim.

Sugerowałbym jednak tekstury bo używasz ich do ściany. Jednolity kolor dachu trochę do niej wtedy nie pasuje.
P-181840
tBane
Temat założony przez niniejszego użytkownika
» 2024-11-07 22:18:39
Wiem, wiem ale  chciałbym zrobić te belki. Ewentualnie zawsze mogę dodać shader szumu jakiegoś półprzezroczystego na kafelki, żeby nie były takie jednolite.
P-181841
tBane
Temat założony przez niniejszego użytkownika
» 2024-11-07 23:36:00
Dobra. Po namyśle stwierdziłem, że spróbuję nałożyć teksturę. I tak zrobiłem oto efekt. Zdecydowanie muszę znaleźć jakąś inną teksturę ..

P-181842
tBane
Temat założony przez niniejszego użytkownika
» 2024-11-08 15:54:23
Zaprogramowałem tak dach, że teraz dachówki w co drugim rzędzie są przesunięte o połowę długości. Nie wiem tylko dlaczego są pewne nierówności. :-/

// edit //
i mam złe obliczenia dla górnych nieparzystyck kafelków po lewej stronie dachu i dla górnego oraz dolnego kafelka po prawej stronie dachu... :-/

C/C++
void loadTexture( std::ifstream & file ) {
   
   
// check the size
   
cout << size.x << " " << size.y << "\n";
   
   
short walls_height = 3;
   
   
float tiles_rows = 6;
   
float tiles_columns = 6;
   
   
float tile_width = float( size.x ) / 4.0f * 32.0f / tiles_columns;
   
float tile_height = float( size.y / 4 + 2 ) * 32.0f / tiles_rows;
   
float tile_border = 1;
   
   
sf::Color color_outside = sf::Color::Black; //sf::Color(51, 38, 21);
   
sf::Color color_inside = sf::Color( 128, 24, 24 );
   
   
// create basic image to render house
   
sf::Image house_image;
   
house_image.create( size.x * 16 + tile_width,( size.y + walls_height * 2 + 2 ) * 16, sf::Color::Transparent );
   
   
// load the wall texture
   
sf::Image wall;
   
wall.create( 32, 32, sf::Color::Transparent );
   
wall = getTexture( "walls/wooden_wall" )->texture->copyToImage();
   
   
   
// DRAWING A WALLS
   
for( short y = 1; y <= walls_height; y++ ) {
       
for( short x = 0; x < size.x / 2; x++ ) {
           
house_image.copy( wall, x * 2 * 16 + tile_width / 2.0f, house_image.getSize().y - y * 2 * 16 );
       
}
    }
   
   
// DRAWING A WALLS UNDER THE ROOF
   
short height = size.x / 4;
   
short width = size.x / 2;
   
short start_x;
   
short end_x;
   
   
for( int y = 0; y <= height; y++ ) {
       
start_x = y;
       
end_x = width - y - 1;
       
       
for( int x = 0; x < width; x++ ) {
           
if( x >= start_x && x <= end_x ) {
               
house_image.copy( wall, x * 2 * 16 + tile_width / 2.0f, house_image.getSize().y -( y + walls_height + 1 ) * 2 * 16 );
           
}
        }
    }
   
   
// DRAWING A ROOF
   
sf::Color color = sf::Color::Black;
   
   
sf::Vector2f p1( 0,( walls_height - 1.0f ) * 2.0f * 16.0f );
   
sf::Vector2f p2( tile_width / 2.0f + size.x / 2.0f * 16.0f,( walls_height - 1.0f + size.x / 4.0f ) * 2.0f * 16.0f + tile_height / 2.0f );
   
sf::Vector2f p3( tile_width + size.x * 16.0f,( walls_height - 1.0f ) * 2.0f * 16.0f );
   
sf::Vector2f p4( tile_width + size.x * 16.0f,( walls_height + size.y / 4.0f + 1.0f ) * 2.0f * 16.0f );
   
sf::Vector2f p5( tile_width / 2.0f + size.x / 2.0f * 16.0f,( walls_height + size.x / 4.0f + size.y / 4.0f + 1.0f ) * 2.0f * 16.0f + tile_height / 2.0f );
   
sf::Vector2f p6( 0,( walls_height + size.y / 4.0f + 1.0f ) * 2.0f * 16.0f );
   
   
sf::VertexArray left_quad( sf::Quads, 4 );
   
left_quad[ 0 ].position = p1;
   
left_quad[ 1 ].position = p2;
   
left_quad[ 2 ].position = p5;
   
left_quad[ 3 ].position = p6;
   
   
for( short i = 0; i < 4; i++ )
       
 left_quad[ i ].color = color;
   
   
sf::VertexArray right_quad( sf::Quads, 4 );
   
right_quad[ 0 ].position = p2;
   
right_quad[ 1 ].position = p3;
   
right_quad[ 2 ].position = p4;
   
right_quad[ 3 ].position = p5;
   
   
for( short i = 0; i < 4; i++ )
       
 right_quad[ i ].color = color;
   
   
sf::RenderTexture rtex;
   
rtex.create( house_image.getSize().x, house_image.getSize().y );
   
rtex.draw( left_quad );
   
rtex.draw( right_quad );
   
   
// CREATE A TILES
   
sf::RenderStates rstate( getTexture( "tiles/tile_5_highlands" )->texture );
   
   
// LEFT SIDE OF ROOF - EVEN TILES
   
for( float x = 0; x < tiles_columns; x += 2 ) {
       
for( float y = 0; y < tiles_rows; y += 1 ) {
           
           
sf::Vector2f quad_pos( x * tile_width,( walls_height - 1.0f ) * 32.0f + y * tile_height + x * tile_width );
           
           
sf::VertexArray tile( sf::Quads, 4 );
           
tile[ 0 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_border );
           
tile[ 1 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_width + tile_border );
           
tile[ 2 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_width + tile_height - tile_border );
           
tile[ 3 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_height - tile_border );
           
           
tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
           
tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
           
tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
           
tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
           
           
rtex.draw( tile, rstate );
       
}
    }
   
   
// LEFT SIDE OF ROOF - ODD TILES
   
for( float x = 1; x < tiles_columns; x += 2 ) {
       
       
// bottom tile
       
sf::Vector2f bottom_pos( x * tile_width,( walls_height - 1.0f ) * 32.0f + x * tile_width + tile_height / 2.0f );
       
sf::VertexArray bottom_tile( sf::Quads, 4 );
       
bottom_tile[ 0 ].position = sf::Vector2f( bottom_pos.x + tile_border, bottom_pos.y - tile_height / 2.0f + tile_border );
       
bottom_tile[ 1 ].position = sf::Vector2f( bottom_pos.x + tile_width - tile_border, bottom_pos.y + tile_width - tile_height / 2.0f + tile_border );
       
bottom_tile[ 2 ].position = sf::Vector2f( bottom_pos.x + tile_width - tile_border, bottom_pos.y + tile_width - tile_border );
       
bottom_tile[ 3 ].position = sf::Vector2f( bottom_pos.x + tile_border, bottom_pos.y - tile_border );
       
       
bottom_tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
       
bottom_tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
       
bottom_tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
       
bottom_tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
       
       
rtex.draw( bottom_tile, rstate );
       
       
// center tiles
       
for( float y = 0; y < tiles_rows - 1; y += 1 ) {
           
           
sf::Vector2f quad_pos( x * tile_width,( walls_height - 1.0f ) * 32.0f + y * tile_height + x * tile_width + tile_height / 2.0f );
           
           
sf::VertexArray tile( sf::Quads, 4 );
           
tile[ 0 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_border );
           
tile[ 1 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_width + tile_border );
           
tile[ 2 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_width + tile_height - tile_border );
           
tile[ 3 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_height - tile_border );
           
           
tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
           
tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
           
tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
           
tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
           
           
rtex.draw( tile, rstate );
       
}
       
       
// top tile
       
sf::Vector2f top_pos( x * tile_width, walls_height * 32.0f +( tiles_rows - 2.0f ) * tile_height + x * tile_width + tile_height / 2.0f );
       
sf::VertexArray top_tile( sf::Quads, 4 );
       
top_tile[ 0 ].position = sf::Vector2f( top_pos.x + tile_border, top_pos.y + tile_border );
       
top_tile[ 1 ].position = sf::Vector2f( top_pos.x + tile_width - tile_border, top_pos.y + tile_width + tile_border );
       
top_tile[ 2 ].position = sf::Vector2f( top_pos.x + tile_width - tile_border, top_pos.y + tile_width + tile_height / 2.0f - tile_border );
       
top_tile[ 3 ].position = sf::Vector2f( top_pos.x + tile_border, top_pos.y + tile_height / 2.0f - tile_border );
       
       
top_tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
       
top_tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
       
top_tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
       
top_tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
       
       
rtex.draw( top_tile, rstate );
   
}
   
   
   
// RIGHT SIDE OF ROOF - EVEN TILES
   
for( float x = 0; x < tiles_columns; x += 2 ) {
       
for( float y = 0; y < tiles_rows; y += 1 ) {
           
           
sf::Vector2f quad_pos( size.x * 16.0f - x * tile_width,( walls_height - 1.0f ) * 32.0f + y * tile_height + x * tile_width );
           
sf::VertexArray tile( sf::Quads, 4 );
           
tile[ 0 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_width + tile_border );
           
tile[ 1 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_border );
           
tile[ 2 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_height - tile_border );
           
tile[ 3 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_width + tile_height - tile_border );
           
           
tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
           
tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
           
tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
           
tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
           
           
sf::RenderStates rstate( getTexture( "tiles/tile_5_highlands" )->texture );
           
rtex.draw( tile, rstate );
       
}
    }
   
   
// RIGHT SIDE OF ROOF - ODD TILES
   
for( float x = 1; x < tiles_columns; x += 2 ) {
       
       
// bottom tile
       
sf::Vector2f bottom_pos( size.x / 2.0f * 16.0f + x * tile_width,( walls_height - 2.0f + size.x / 4.0f ) * 32.0f - x * tile_width + tile_height / 2.0f );
       
sf::VertexArray bottom_tile( sf::Quads, 4 );
       
bottom_tile[ 0 ].position = sf::Vector2f( bottom_pos.x + tile_border, bottom_pos.y + tile_width + tile_border + tile_height / 2.0f );
       
bottom_tile[ 1 ].position = sf::Vector2f( bottom_pos.x + tile_width - tile_border, bottom_pos.y + tile_border + tile_height / 2.0f );
       
bottom_tile[ 2 ].position = sf::Vector2f( bottom_pos.x + tile_width - tile_border, bottom_pos.y + tile_height - tile_border );
       
bottom_tile[ 3 ].position = sf::Vector2f( bottom_pos.x + tile_border, bottom_pos.y + tile_width + tile_height - tile_border );
       
       
bottom_tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
       
bottom_tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
       
bottom_tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
       
bottom_tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
       
       
rtex.draw( bottom_tile, rstate );
       
       
// center tiles
       
for( float y = 0; y < tiles_rows - 1; y += 1 ) {
           
           
sf::Vector2f quad_pos( size.x * 16.0f - x * tile_width,( walls_height - 1.0f ) * 32.0f + y * tile_height + x * tile_width + tile_height / 2.0f );
           
           
sf::VertexArray tile( sf::Quads, 4 );
           
tile[ 0 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_width + tile_border );
           
tile[ 1 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_border );
           
tile[ 2 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_height - tile_border );
           
tile[ 3 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_width + tile_height - tile_border );
           
           
tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
           
tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
           
tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
           
tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
           
           
rtex.draw( tile, rstate );
       
}
       
       
// top tile
       
sf::Vector2f top_pos( size.x / 2.0f * 16.0f + x * tile_width,( walls_height + size.x / 4.0f + size.y / 4.0f ) * 32.0f - x * tile_width );
       
sf::VertexArray top_tile( sf::Quads, 4 );
       
top_tile[ 0 ].position = sf::Vector2f( top_pos.x + tile_border, top_pos.y + tile_width + tile_border + tile_height / 2.0f );
       
top_tile[ 1 ].position = sf::Vector2f( top_pos.x + tile_width - tile_border, top_pos.y + tile_border + tile_height / 2.0f );
       
top_tile[ 2 ].position = sf::Vector2f( top_pos.x + tile_width - tile_border, top_pos.y + tile_height - tile_border );
       
top_tile[ 3 ].position = sf::Vector2f( top_pos.x + tile_border, top_pos.y + tile_width + tile_height - tile_border );
       
       
top_tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
       
top_tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
       
top_tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
       
top_tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
       
       
rtex.draw( top_tile, rstate );
   
}
   
   
   
sf::Image roof_image = rtex.getTexture().copyToImage();
   
   
house_image.copy( roof_image, 0, 0, sf::IntRect( 0, 0, 0, 0 ), true );
   
   
// create main tex
   
sf::Texture * tex = new sf::Texture();
   
tex->loadFromImage( house_image );
   
   
// create the sprite
   
sprite = sf::Sprite();
   
sprite.setTexture( * tex );
   
sprite.setOrigin( tex->getSize().x / 2, tex->getSize().y );
   
sprite.setPosition( position );
   
}
P-181850
tBane
Temat założony przez niniejszego użytkownika
» 2024-11-08 17:01:26
Naprawiłem tego BUG'a i teraz algorytm ładnie generuje kafelki :-) Czas zabrać się za rusztowanie, znaczy się te belki nośne budynku
C/C++
void loadTexture( std::ifstream & file ) {
   
   
// check the size
   
cout << size.x << " " << size.y << "\n";
   
   
short walls_height = 3;
   
   
float tiles_rows = 6;
   
float tiles_columns = 6;
   
   
float tile_width = float( size.x ) / 4.0f * 32.0f / tiles_columns;
   
float tile_height = float( size.y / 4 + 2 ) * 32.0f / tiles_rows;
   
float tile_border = 1;
   
   
sf::Color color_outside = sf::Color::Black; //sf::Color(51, 38, 21);
   
sf::Color color_inside = sf::Color( 128, 24, 24 );
   
   
// create basic image to render house
   
sf::Image house_image;
   
house_image.create( size.x * 16 + tile_width,( size.y + walls_height * 2 + 2 ) * 16, sf::Color::Transparent );
   
   
// load the wall texture
   
sf::Image wall;
   
wall.create( 32, 32, sf::Color::Transparent );
   
wall = getTexture( "walls/wooden_wall" )->texture->copyToImage();
   
   
   
// DRAWING A WALLS
   
for( short y = 1; y <= walls_height; y++ ) {
       
for( short x = 0; x < size.x / 2; x++ ) {
           
house_image.copy( wall, x * 2 * 16 + tile_width / 2.0f, house_image.getSize().y - y * 2 * 16 );
       
}
    }
   
   
// DRAWING A WALLS UNDER THE ROOF
   
short height = size.x / 4;
   
short width = size.x / 2;
   
short start_x;
   
short end_x;
   
   
for( int y = 0; y <= height; y++ ) {
       
start_x = y;
       
end_x = width - y - 1;
       
       
for( int x = 0; x < width; x++ ) {
           
if( x >= start_x && x <= end_x ) {
               
house_image.copy( wall, x * 2 * 16 + tile_width / 2.0f, house_image.getSize().y -( y + walls_height + 1 ) * 2 * 16 );
           
}
        }
    }
   
   
// DRAWING A ROOF
   
sf::Color color = sf::Color::Black;
   
   
sf::Vector2f p1( 0,( walls_height - 1.0f ) * 2.0f * 16.0f );
   
sf::Vector2f p2( tile_width / 2.0f + size.x / 2.0f * 16.0f,( walls_height - 1.0f + size.x / 4.0f ) * 2.0f * 16.0f + tile_height / 2.0f );
   
sf::Vector2f p3( tile_width + size.x * 16.0f,( walls_height - 1.0f ) * 2.0f * 16.0f );
   
sf::Vector2f p4( tile_width + size.x * 16.0f,( walls_height + size.y / 4.0f + 1.0f ) * 2.0f * 16.0f );
   
sf::Vector2f p5( tile_width / 2.0f + size.x / 2.0f * 16.0f,( walls_height + size.x / 4.0f + size.y / 4.0f + 1.0f ) * 2.0f * 16.0f + tile_height / 2.0f );
   
sf::Vector2f p6( 0,( walls_height + size.y / 4.0f + 1.0f ) * 2.0f * 16.0f );
   
   
sf::VertexArray left_quad( sf::Quads, 4 );
   
left_quad[ 0 ].position = p1;
   
left_quad[ 1 ].position = p2;
   
left_quad[ 2 ].position = p5;
   
left_quad[ 3 ].position = p6;
   
   
for( short i = 0; i < 4; i++ )
       
 left_quad[ i ].color = color;
   
   
sf::VertexArray right_quad( sf::Quads, 4 );
   
right_quad[ 0 ].position = p2;
   
right_quad[ 1 ].position = p3;
   
right_quad[ 2 ].position = p4;
   
right_quad[ 3 ].position = p5;
   
   
for( short i = 0; i < 4; i++ )
       
 right_quad[ i ].color = color;
   
   
sf::RenderTexture rtex;
   
rtex.create( house_image.getSize().x, house_image.getSize().y );
   
rtex.draw( left_quad );
   
rtex.draw( right_quad );
   
   
// CREATE A TILES
   
sf::RenderStates rstate( getTexture( "tiles/tile_5_highlands" )->texture );
   
   
// LEFT SIDE OF ROOF - EVEN TILES
   
for( float x = 0; x < tiles_columns; x += 2 ) {
       
for( float y = 0; y < tiles_rows; y += 1 ) {
           
           
sf::Vector2f quad_pos( x * tile_width,( walls_height - 1.0f ) * 32.0f + y * tile_height + x * tile_width );
           
           
sf::VertexArray tile( sf::Quads, 4 );
           
tile[ 0 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_border );
           
tile[ 1 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_width + tile_border );
           
tile[ 2 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_width + tile_height - tile_border );
           
tile[ 3 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_height - tile_border );
           
           
tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
           
tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
           
tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
           
tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
           
           
rtex.draw( tile, rstate );
       
}
    }
   
   
// LEFT SIDE OF ROOF - ODD TILES
   
for( float x = 1; x < tiles_columns; x += 2 ) {
       
       
// bottom tile
       
sf::Vector2f bottom_pos( x * tile_width,( walls_height - 1.0f ) * 32.0f + x * tile_width + tile_height / 2.0f );
       
sf::VertexArray bottom_tile( sf::Quads, 4 );
       
bottom_tile[ 0 ].position = sf::Vector2f( bottom_pos.x + tile_border, bottom_pos.y - tile_height / 2.0f + tile_border );
       
bottom_tile[ 1 ].position = sf::Vector2f( bottom_pos.x + tile_width - tile_border, bottom_pos.y + tile_width - tile_height / 2.0f + tile_border );
       
bottom_tile[ 2 ].position = sf::Vector2f( bottom_pos.x + tile_width - tile_border, bottom_pos.y + tile_width - tile_border );
       
bottom_tile[ 3 ].position = sf::Vector2f( bottom_pos.x + tile_border, bottom_pos.y - tile_border );
       
       
bottom_tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
       
bottom_tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
       
bottom_tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
       
bottom_tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
       
       
rtex.draw( bottom_tile, rstate );
       
       
// center tiles
       
for( float y = 0; y < tiles_rows - 1; y += 1 ) {
           
           
sf::Vector2f quad_pos( x * tile_width,( walls_height - 1.0f ) * 32.0f + y * tile_height + x * tile_width + tile_height / 2.0f );
           
           
sf::VertexArray tile( sf::Quads, 4 );
           
tile[ 0 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_border );
           
tile[ 1 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_width + tile_border );
           
tile[ 2 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_width + tile_height - tile_border );
           
tile[ 3 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_height - tile_border );
           
           
tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
           
tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
           
tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
           
tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
           
           
rtex.draw( tile, rstate );
       
}
       
       
// top tile
       
sf::Vector2f top_pos( x * tile_width,( walls_height - 1.0f ) * 32.0f +( tiles_rows ) * tile_height + x * tile_width - tile_height / 2.0f );
       
sf::VertexArray top_tile( sf::Quads, 4 );
       
top_tile[ 0 ].position = sf::Vector2f( top_pos.x + tile_border, top_pos.y + tile_border );
       
top_tile[ 1 ].position = sf::Vector2f( top_pos.x + tile_width - tile_border, top_pos.y + tile_width + tile_border );
       
top_tile[ 2 ].position = sf::Vector2f( top_pos.x + tile_width - tile_border, top_pos.y + tile_width + tile_height / 2.0f - tile_border );
       
top_tile[ 3 ].position = sf::Vector2f( top_pos.x + tile_border, top_pos.y + tile_height / 2.0f - tile_border );
       
       
top_tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
       
top_tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
       
top_tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
       
top_tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
       
       
rtex.draw( top_tile, rstate );
   
}
   
   
   
// RIGHT SIDE OF ROOF - EVEN TILES
   
for( float x = 0; x < tiles_columns; x += 2 ) {
       
for( float y = 0; y < tiles_rows; y += 1 ) {
           
           
sf::Vector2f quad_pos( size.x * 16.0f - x * tile_width,( walls_height - 1.0f ) * 32.0f + y * tile_height + x * tile_width );
           
sf::VertexArray tile( sf::Quads, 4 );
           
tile[ 0 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_width + tile_border );
           
tile[ 1 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_border );
           
tile[ 2 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_height - tile_border );
           
tile[ 3 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_width + tile_height - tile_border );
           
           
tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
           
tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
           
tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
           
tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
           
           
sf::RenderStates rstate( getTexture( "tiles/tile_5_highlands" )->texture );
           
rtex.draw( tile, rstate );
       
}
    }
   
   
// RIGHT SIDE OF ROOF - ODD TILES
   
for( float x = 1; x < tiles_columns; x += 2 ) {
       
       
// bottom tile
       
sf::Vector2f bottom_pos( size.x / 2.0f * 16.0f + x * tile_width,( walls_height - 1.0f + size.x / 4.0f ) * 32.0f - x * tile_width - tile_height / 2.0f );
       
sf::VertexArray bottom_tile( sf::Quads, 4 );
       
bottom_tile[ 0 ].position = sf::Vector2f( bottom_pos.x + tile_border, bottom_pos.y + tile_width + tile_border + tile_height / 2.0f );
       
bottom_tile[ 1 ].position = sf::Vector2f( bottom_pos.x + tile_width - tile_border, bottom_pos.y + tile_border + tile_height / 2.0f );
       
bottom_tile[ 2 ].position = sf::Vector2f( bottom_pos.x + tile_width - tile_border, bottom_pos.y + tile_height - tile_border );
       
bottom_tile[ 3 ].position = sf::Vector2f( bottom_pos.x + tile_border, bottom_pos.y + tile_width + tile_height - tile_border );
       
       
bottom_tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
       
bottom_tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
       
bottom_tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
       
bottom_tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
       
       
rtex.draw( bottom_tile, rstate );
       
       
// center tiles
       
for( float y = 0; y < tiles_rows - 1; y += 1 ) {
           
           
sf::Vector2f quad_pos( size.x * 16.0f - x * tile_width,( walls_height - 1.0f ) * 32.0f + y * tile_height + x * tile_width + tile_height / 2.0f );
           
           
sf::VertexArray tile( sf::Quads, 4 );
           
tile[ 0 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_width + tile_border );
           
tile[ 1 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_border );
           
tile[ 2 ].position = sf::Vector2f( quad_pos.x + tile_width - tile_border, quad_pos.y + tile_height - tile_border );
           
tile[ 3 ].position = sf::Vector2f( quad_pos.x + tile_border, quad_pos.y + tile_width + tile_height - tile_border );
           
           
tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
           
tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
           
tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
           
tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
           
           
rtex.draw( tile, rstate );
       
}
       
       
// top tile
       
sf::Vector2f top_pos( size.x / 2.0f * 16.0f + x * tile_width,( walls_height - 1.0f + size.x / 4.0f ) * 32.0f + tiles_rows * tile_height - x * tile_width - tile_height / 2.0f );
       
sf::VertexArray top_tile( sf::Quads, 4 );
       
top_tile[ 0 ].position = sf::Vector2f( top_pos.x + tile_border, top_pos.y + tile_width + tile_border );
       
top_tile[ 1 ].position = sf::Vector2f( top_pos.x + tile_width - tile_border, top_pos.y + tile_border );
       
top_tile[ 2 ].position = sf::Vector2f( top_pos.x + tile_width - tile_border, top_pos.y + tile_height / 2.0f - tile_border );
       
top_tile[ 3 ].position = sf::Vector2f( top_pos.x + tile_border, top_pos.y + tile_width + tile_height / 2.0f - tile_border );
       
       
top_tile[ 0 ].texCoords = sf::Vector2f( 0, 0 );
       
top_tile[ 1 ].texCoords = sf::Vector2f( tile_width, 0 );
       
top_tile[ 2 ].texCoords = sf::Vector2f( tile_width, tile_height );
       
top_tile[ 3 ].texCoords = sf::Vector2f( 0, tile_height );
       
       
rtex.draw( top_tile, rstate );
   
}
   
   
   
sf::Image roof_image = rtex.getTexture().copyToImage();
   
   
house_image.copy( roof_image, 0, 0, sf::IntRect( 0, 0, 0, 0 ), true );
   
   
// create main tex
   
sf::Texture * tex = new sf::Texture();
   
tex->loadFromImage( house_image );
   
   
// create the sprite
   
sprite = sf::Sprite();
   
sprite.setTexture( * tex );
   
sprite.setOrigin( tex->getSize().x / 2, tex->getSize().y );
   
sprite.setPosition( position );
   
}
P-181852
tBane
Temat założony przez niniejszego użytkownika
» 2024-11-08 23:21:14
Nadal występują pewne nierówności. Źle obliczam punkty dwóch głównych quadów. A na pewno, źle jest obliczane p2 oraz p5

size.x/4.0f - to odległość od ściany bocznej do dachu jakby co
walls_height - wysokość ściany
C/C++
sf::Vector2f p1( 0,( walls_height - 1.0f ) * 2.0f * 16.0f );
sf::Vector2f p2( tile_width / 2.0f + size.x / 2.0f * 16.0f,( walls_height - 1.0f + size.x / 4.0f ) * 32.0f + tile_height / 2.0f );
sf::Vector2f p3( tile_width + size.x * 16.0f,( walls_height - 1.0f ) * 32.0f );
sf::Vector2f p4( tile_width + size.x * 16.0f,( walls_height - 1.0f ) * 32.0f + tiles_rows * tile_height );
sf::Vector2f p5( tile_width / 2.0f + size.x / 2.0f * 16.0f,( walls_height - 1.0f + size.x / 4.0f ) * 32.0f + tiles_rows * tile_height + tile_height / 2.0f );
sf::Vector2f p6( 0,( walls_height - 1.0f ) * 32.0f + tiles_rows * tile_height );
P-181854
tBane
Temat założony przez niniejszego użytkownika
» 2024-11-09 14:54:18
Post usunięty przez moderatora
P-181859
tBane
Temat założony przez niniejszego użytkownika
» 2024-11-09 15:06:26
Jeszcze pozostało dodać belki. Nie wiem jakie wpisać współrzędne tekstury.

C/C++
// WOODEN BEAMS
// main wooden beam
sf::VertexArray beam( sf::Quads, 4 );
sf::Vector2f pos;
sf::Color beam_color = sf::Color( 100, 55, 30 );
sf::RenderStates rstate2;
rstate2.texture = getTexture( "tiles/tile_6" )->texture;

pos.x = size.x / 2.f * 16.0f + tile_width / 2.0f;
pos.y =( walls_height - 1.0f + size.x / 4.0f ) * 32.0f;
beam[ 0 ].position = sf::Vector2f( pos.x - tile_width / 2.0f, pos.y );
beam[ 1 ].position = sf::Vector2f( pos.x + tile_width / 2.0f, pos.y );
beam[ 2 ].position = sf::Vector2f( pos.x + tile_width / 2.0f, pos.y + tiles_rows * tile_height );
beam[ 3 ].position = sf::Vector2f( pos.x - tile_width / 2.0f, pos.y + tiles_rows * tile_height );

//beam[0].texCoords = ??? ;
//beam[1].texCoords = ??? ;
//beam[2].texCoords = ??? ;
//beam[3].texCoords = ??? ;

rtex.draw( beam, rstate2 );
P-181860
1 2 « 3 » 4
Poprzednia strona Strona 3 z 4 Następna strona