Improved implementation of crop in AppearanceView. Not yet fully

satisfying though...
This commit is contained in:
brunoherbelin
2020-11-29 23:33:53 +01:00
parent 5200de2e3e
commit 93ad971fc0
6 changed files with 71 additions and 32 deletions

View File

@@ -186,6 +186,7 @@ Source::Source() : initialized_(false), active_(true), need_update_(true), symbo
// - crop & repeat UV can be managed here
// - additional custom shader can be associated
texturesurface_ = new Surface(renderingshader_);
crop_ = glm::vec2(1.f, 1.f);
// will be created at init
renderbuffer_ = nullptr;
@@ -444,14 +445,15 @@ void Source::update(float dt)
// Aspect Ratio correction transform : coordinates of Appearance Frame are scaled by render buffer width
glm::mat4 Ar = glm::identity<glm::mat4>();
if (renderbuffer_)
Ar = glm::scale(glm::identity<glm::mat4>(), glm::vec3(renderbuffer_->aspectRatio(), 1.f, 1.f) );
Ar = glm::scale(glm::identity<glm::mat4>(), glm::vec3(renderbuffer_->aspectRatio() * crop_.x, crop_.y, 1.f) );
// Translation : same as Appearance Frame (modified by Ar)
glm::mat4 Tra = glm::translate(glm::identity<glm::mat4>(), groups_[View::APPEARANCE]->translation_);
// Scaling : inverse scaling (larger UV when smaller Appearance Frame)
glm::mat4 Sca = glm::scale(glm::identity<glm::mat4>(), glm::vec3( 1.f / groups_[View::APPEARANCE]->scale_.x,
1.f / groups_[View::APPEARANCE]->scale_.y, 1.f));
glm::mat4 Sca = glm::scale(glm::identity<glm::mat4>(), glm::vec3( crop_.x / groups_[View::APPEARANCE]->scale_.x,
crop_.y / groups_[View::APPEARANCE]->scale_.y, 1.f));
// Rotation : same angle than Appearance Frame, inverted axis
glm::mat4 Rot = glm::rotate(glm::identity<glm::mat4>(), groups_[View::APPEARANCE]->rotation_.z, glm::vec3(0.f, 0.f, -1.f) );
// Combine transformations (non transitive) in this order:
// 1. switch to Scene coordinate system
// 2. Apply the aspect ratio correction
@@ -462,12 +464,12 @@ void Source::update(float dt)
// 7. switch back to UV coordinate system
texturesurface_->shader()->iTransform = glm::inverse(UVtoScene) * Sca * glm::inverse(Ar) * Rot * Tra * Ar * UVtoScene;
// MODIFY CROP
if (renderbuffer_) {
glm::vec2 crop = renderbuffer_->projectionArea();
groups_[View::MIXING]->scale_.x *= crop.x / crop.y;
groups_[View::LAYER]->scale_.x = crop.x / crop.y;
}
// // MODIFY CROP
// if (renderbuffer_) {
// glm::vec2 crop = renderbuffer_->projectionArea();
// groups_[View::MIXING]->scale_.x *= crop.x / crop.y;
// groups_[View::LAYER]->scale_.x = crop.x / crop.y;
// }
need_update_ = false;
}