Applying distance to perspective projection

This commit is contained in:
Andrew Golovashevich 2025-03-20 18:00:27 +03:00
parent 280abd4a38
commit ff43f035b1
2 changed files with 13 additions and 11 deletions

View File

@ -22,7 +22,7 @@ namespace BGTU::ComputerGraphicsLabWork::Impl {
#if 1
QApplication qApplication{argc, argv};
SpriteData::Provider sprites_data_custom{0.1, 0.1, 10};
SpriteData::Provider sprites_data_custom{0.1, 0.1, 0.5};
QMainWindow w{};
@ -37,8 +37,8 @@ namespace BGTU::ComputerGraphicsLabWork::Impl {
QObject::connect(&kbd, &QtUtilities::KeyboardCatcherWidget::key_pressed_D, &sprites_data_custom, &SpriteData::Provider::inc_y_angle);
QObject::connect(&kbd, &QtUtilities::KeyboardCatcherWidget::key_pressed_S, &sprites_data_custom, &SpriteData::Provider::dec_x_angle);
QObject::connect(&kbd, &QtUtilities::KeyboardCatcherWidget::key_pressed_W, &sprites_data_custom, &SpriteData::Provider::inc_x_angle);
QObject::connect(&kbd, &QtUtilities::KeyboardCatcherWidget::key_pressed_PageDown, &sprites_data_custom, &SpriteData::Provider::dec_scale);
QObject::connect(&kbd, &QtUtilities::KeyboardCatcherWidget::key_pressed_PageUp, &sprites_data_custom, &SpriteData::Provider::inc_scale);
QObject::connect(&kbd, &QtUtilities::KeyboardCatcherWidget::key_pressed_PageDown, &sprites_data_custom, &SpriteData::Provider::dec_distance);
QObject::connect(&kbd, &QtUtilities::KeyboardCatcherWidget::key_pressed_PageUp, &sprites_data_custom, &SpriteData::Provider::inc_distance);
QObject::connect(&kbd, &QtUtilities::KeyboardCatcherWidget::key_pressed_P, &sprites_data_custom, &SpriteData::Provider::switch_projection);
SortSprite sprites_sort{sprites, sprites_count};

View File

@ -36,11 +36,11 @@ namespace BGTU::ComputerGraphicsLabWork::Impl {
QMutex sync;
double x_angle;
double y_angle;
double scale;
double distance;
double x_angle_step;
double y_angle_step;
double scale_step;
double distance_step;
bool is_projection_enabled;
RendererApi::VirtualVoxelPainter::visible_pixel_coordinate_fast_t w, h;
@ -50,14 +50,14 @@ namespace BGTU::ComputerGraphicsLabWork::Impl {
double x_angle_step,
double y_angle_step,
double scale_step
) : x_angle{0}, y_angle{0}, scale{1}, x_angle_step{x_angle_step}, y_angle_step{y_angle_step}, scale_step{scale_step},
) : x_angle{0}, y_angle{0}, distance{0}, x_angle_step{x_angle_step}, y_angle_step{y_angle_step}, distance_step{scale_step},
w{0}, h{0}, is_projection_enabled{false} {}
SpriteData get_sprite_data() override {
this->sync.lock();
double radius = (((this->w < this->h) ? this->w : this->h) * 7 / 16.0);
auto projection = this->is_projection_enabled
? Utilities::Matrix4d::projection_central(-2, 2, -2, 2, 1, 9) * Utilities::Matrix4d::scale(1, 1, -1) * Utilities::Matrix4d::shift(0, 0, 7)
? Utilities::Matrix4d::projection_central(-1.5, 1.5, -1.5, 1.5, 1, 9) * Utilities::Matrix4d::scale(5, 5, -1) * Utilities::Matrix4d::shift(0, 0, 7 + this->distance)
: Utilities::Matrix4d::projection_orto(-2, 2, -2, 2, -6, 2);
SpriteData cached{
Utilities::Matrix4d::shift(this->w / 2, this->h / 2, 0) * Utilities::Matrix4d::scale(radius) * projection * Utilities::Matrix4d::rotate_x(this->x_angle) * Utilities::Matrix4d::rotate_y(this->y_angle),
@ -99,15 +99,17 @@ namespace BGTU::ComputerGraphicsLabWork::Impl {
this->sync.unlock();
}
void inc_scale() {
void inc_distance() {
this->sync.lock();
this->scale += this->scale_step;
this->distance += this->distance_step;
this->sync.unlock();
}
void dec_scale() {
void dec_distance() {
this->sync.lock();
this->scale -= this->scale_step;
this->distance -= this->distance_step;
if (this->distance < 0)
this->distance = 0;
this->sync.unlock();
}