Skip to content

Commit

Permalink
Fix 180 degree problem
Browse files Browse the repository at this point in the history
  • Loading branch information
jowin202 committed Mar 11, 2024
1 parent f62f69f commit e20a45b
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions rotations/rotationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RotationDialog::RotationDialog(options *opt, QWidget *parent) :
this->opt = opt;

this->base_sprite = opt->data.value("sprites").toArray().at(opt->current_sprite).toObject();

connect(this->ui->spin_angle, SIGNAL(valueChanged(int)), this, SLOT(update_rotation()));
connect(this->ui->spin_steps, SIGNAL(valueChanged(int)), this, SLOT(update_rotation()));

Expand Down Expand Up @@ -64,17 +65,38 @@ QJsonObject RotationDialog::rotate_by(QJsonObject sprite, int angle)
for (int j = 0; j < 144; j++)
temp1[i][j] = temp2[i][j] = temp3[i][j] = rotated[i][j] = 0;

for (int i = 0; i < 24; i++)
{
for (int j = 0; j < 21; j++)

//
if (angle <= 90 || angle >= 270)
{
for (int i = 0; i < 24; i++)
{
int px_val = sprite.value("sprite_data").toArray().at(j).toArray().at(i).toInt();
rotated[BORDER_SIZE + 2*i+0][BORDER_SIZE + 2*j+0+3] = px_val;
rotated[BORDER_SIZE + 2*i+1][BORDER_SIZE + 2*j+0+3] = px_val;
rotated[BORDER_SIZE + 2*i+0][BORDER_SIZE + 2*j+1+3] = px_val;
rotated[BORDER_SIZE + 2*i+1][BORDER_SIZE + 2*j+1+3] = px_val;
for (int j = 0; j < 21; j++)
{
int px_val = sprite.value("sprite_data").toArray().at(j).toArray().at(i).toInt();
rotated[BORDER_SIZE + 2*i+0][BORDER_SIZE + 2*j+0+3] = px_val;
rotated[BORDER_SIZE + 2*i+1][BORDER_SIZE + 2*j+0+3] = px_val;
rotated[BORDER_SIZE + 2*i+0][BORDER_SIZE + 2*j+1+3] = px_val;
rotated[BORDER_SIZE + 2*i+1][BORDER_SIZE + 2*j+1+3] = px_val;
}
}
}
}
else //angle near 180
{
angle -= 180;
for (int i = 0; i < 24; i++)
{
for (int j = 0; j < 21; j++)
{
int px_val = sprite.value("sprite_data").toArray().at(20-j).toArray().at(23-i).toInt();
rotated[BORDER_SIZE + 2*i+0][BORDER_SIZE + 2*j+0+3] = px_val;
rotated[BORDER_SIZE + 2*i+1][BORDER_SIZE + 2*j+0+3] = px_val;
rotated[BORDER_SIZE + 2*i+0][BORDER_SIZE + 2*j+1+3] = px_val;
rotated[BORDER_SIZE + 2*i+1][BORDER_SIZE + 2*j+1+3] = px_val;
}
}
}


qreal shear_factor_x = -qTan(angle/180.0 * 3.14159265358979323846 * 0.5);
qreal shear_factor_y = qSin(angle/180.0 * 3.14159265358979323846);
Expand Down

0 comments on commit e20a45b

Please sign in to comment.