From e14eabd4b74da5be3f302b3da0234b0706fd7bbd Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 2 Oct 2021 10:29:10 +0200 Subject: [PATCH] #5768: Adjust Face::setShiftScaleRotation to handle the values emitted by the Surface Inspector input fields --- radiantcore/brush/Face.cpp | 22 +++++++++++++++++++--- radiantcore/brush/Face.h | 2 +- radiantcore/brush/TexDef.cpp | 8 +++++++- radiantcore/brush/TexDef.h | 3 ++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/radiantcore/brush/Face.cpp b/radiantcore/brush/Face.cpp index 4b4d5f26c4..07130fbf47 100644 --- a/radiantcore/brush/Face.cpp +++ b/radiantcore/brush/Face.cpp @@ -454,7 +454,7 @@ void Face::setTexdef(const TexDef& texDef) ShiftScaleRotation Face::getShiftScaleRotation() const { auto texdef = _texdef.matrix.getFakeTexCoords(); - auto ssr = texdef.getShiftScaleRotation(); + auto ssr = texdef.toShiftScaleRotation(); // These values are going to show up in the Surface Inspector, so // we need to make some adjustments: @@ -504,9 +504,25 @@ ShiftScaleRotation Face::getShiftScaleRotation() const #endif } -void Face::setShiftScaleRotation(const ShiftScaleRotation& scr) +void Face::setShiftScaleRotation(const ShiftScaleRotation& ssr) { - setTexdef(TexDef::CreateFromShiftScaleRotation(scr)); + // We need to do the opposite adjustments as in Face::getShiftScaleRotation() + // The incoming values are scaled up and down, respectively. + auto texdef = TexDef::CreateFromShiftScaleRotation(ssr); + + // Scale the pixel value in SSR to relative UV coords + texdef.setShift({ texdef.getShift().x() / _shader.getWidth(), + texdef.getShift().y() / _shader.getHeight() }); + + // Add the texture dimensions to the scale. + texdef.setScale({ texdef.getScale().x() * _shader.getWidth(), + texdef.getScale().y() * _shader.getHeight() }); + + // Construct the BPTexDef out of this TexDef + TextureProjection projection; + projection.matrix = TextureMatrix(texdef); + + SetTexdef(projection); } void Face::applyShaderFromFace(const Face& other) diff --git a/radiantcore/brush/Face.h b/radiantcore/brush/Face.h index 5083735621..984fcaca28 100644 --- a/radiantcore/brush/Face.h +++ b/radiantcore/brush/Face.h @@ -149,7 +149,7 @@ class Face : void setTexDefFromPoints(const Vector3 points[3], const Vector2 uvs[3]); ShiftScaleRotation getShiftScaleRotation() const override; - void setShiftScaleRotation(const ShiftScaleRotation& scr) override; + void setShiftScaleRotation(const ShiftScaleRotation& ssr) override; /** * greebo: Copies the shader (texdef) from the other face, diff --git a/radiantcore/brush/TexDef.cpp b/radiantcore/brush/TexDef.cpp index 204d8cdbfb..ec957fc85c 100644 --- a/radiantcore/brush/TexDef.cpp +++ b/radiantcore/brush/TexDef.cpp @@ -60,6 +60,12 @@ Vector2 TexDef::getShift() const return Vector2(_shift); } +void TexDef::setShift(const Vector2& shift) +{ + _shift[0] = shift.x(); + _shift[1] = shift.y(); +} + Vector2 TexDef::getScale() const { return Vector2(_scale); @@ -133,7 +139,7 @@ Matrix4 TexDef::getTransform(double width, double height) const return transform; } -ShiftScaleRotation TexDef::getShiftScaleRotation() const +ShiftScaleRotation TexDef::toShiftScaleRotation() const { ShiftScaleRotation result; diff --git a/radiantcore/brush/TexDef.h b/radiantcore/brush/TexDef.h index 169e92d843..e99d01e29e 100644 --- a/radiantcore/brush/TexDef.h +++ b/radiantcore/brush/TexDef.h @@ -23,6 +23,7 @@ class TexDef virtual ~TexDef() {} Vector2 getShift() const; + void setShift(const Vector2& shift); Vector2 getScale() const; void setScale(const Vector2& scale); double getRotation() const; @@ -48,7 +49,7 @@ class TexDef // Converts this instance's values to a ShiftScaleRotation structure // Since TexDef is using the same format to store its values internally // this is equivalent to a few simple assignment or copy operations. - ShiftScaleRotation getShiftScaleRotation() const; + ShiftScaleRotation toShiftScaleRotation() const; static TexDef CreateFromShiftScaleRotation(const ShiftScaleRotation& scr);