Skip to content

Commit

Permalink
#5768: Adjust Face::setShiftScaleRotation to handle the values emitte…
Browse files Browse the repository at this point in the history
…d by the Surface Inspector input fields
  • Loading branch information
codereader committed Oct 2, 2021
1 parent d894757 commit e14eabd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
22 changes: 19 additions & 3 deletions radiantcore/brush/Face.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/brush/Face.h
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion radiantcore/brush/TexDef.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -133,7 +139,7 @@ Matrix4 TexDef::getTransform(double width, double height) const
return transform;
}

ShiftScaleRotation TexDef::getShiftScaleRotation() const
ShiftScaleRotation TexDef::toShiftScaleRotation() const
{
ShiftScaleRotation result;

Expand Down
3 changes: 2 additions & 1 deletion radiantcore/brush/TexDef.h
Expand Up @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit e14eabd

Please sign in to comment.