Witam.
Potrzebuję tak przerobić funkcję, by generowała elipsę w zadanym przedziale.
Elipsa powinna być generowana tak jak podane rozmiary pędzla, albo przynajmniej tak, by elipsa wyglądała jak elipsa a nie "przycięty fragment elipsy", bo tak wychodzi z wzoru
float centerX =( start_x + end_x ) / 2.0f;
float centerY =( start_y + end_y ) / 2.0f;
float a = width / 2.0f;
float b = height / 2.0f;
for( int y = start_y; y < end_y; y++ ) {
for( int x = start_x; x < end_x; x++ ) {
float dx =( x - centerX ) / a;
float dy =( y - centerY ) / b;
if( dx * dx + dy * dy <= 1 ) {
int xx = x * int( tileSide );
int yy = y * int( tileSide );
Tu kod funkcji dla prostokąta, która muszę przerobić: if( tool == toolType::Rectangle ) {
if( selection_state == true ) {
int start_x = std::min( ceil( startWorldMousePosition.x / tileSide ), ceil( worldMousePosition.x / tileSide ) );
int start_y = std::min( ceil( startWorldMousePosition.y / tileSide ), ceil( worldMousePosition.y / tileSide ) );
int end_x = std::max( ceil( startWorldMousePosition.x / tileSide ), ceil( worldMousePosition.x / tileSide ) );
int end_y = std::max( ceil( startWorldMousePosition.y / tileSide ), ceil( worldMousePosition.y / tileSide ) );
cout << "start: " << start_x << ", " << start_y << "\n";
cout << "end: " << end_x << ", " << end_y << "\n";
cout << "\n\n";
for( int y = start_y; y < end_y; y++ )
for( int x = start_x; x < end_x; x++ ) {
int xx = x * int( tileSide );
int yy = y * int( tileSide );
if( prefabToPaint->type == gameObjectType::Terrain ) {
TerrainPrefab * ter = new TerrainPrefab( prefabToPaint->name, dynamic_cast < TerrainPrefab * >( prefabToPaint )->ttype );
ter->position = sf::Vector2f( xx + 8, yy + 8 );
ter->collider->shape->setFillColor( sf::Color( 129, 48, 48, 128 ) );
ter->collider->shape->setPosition( sf::Vector2f( xx, yy ) );
prefabsToPaint.push_back( ter );
}
if( prefabToPaint->type == gameObjectType::Floor ) {
FloorPrefab * flo = new FloorPrefab( prefabToPaint->name, dynamic_cast < FloorPrefab * >( prefabToPaint )->ftype );
flo->position = sf::Vector2f( xx + 8, yy + 8 );
flo->collider->shape->setFillColor( sf::Color( 128, 48, 48, 128 ) );
flo->collider->shape->setPosition( sf::Vector2f( xx, yy ) );
prefabsToPaint.push_back( flo );
}
}
}
}
std::vector<std::vector<std::vector<bool>>> brushes = {
// 0 - 1x1
{
{1}
},
// 1 - 3x3
{
{0, 1, 0},
{1, 1, 1},
{0, 1, 0}
},
// 2 - 5x5
{
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 1, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0}
},
// 3 - 7x7
{
{0, 0, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 0, 0}
},
// 4 - 9x9
{
{0, 0, 0, 1, 1, 1, 0, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0, 0}
},
// 5 - 11x11
{
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
}
};