Skip to content

Commit

Permalink
#5740: Face rotations are now respecting the aspect ratio of the assi…
Browse files Browse the repository at this point in the history
…gned editor image
  • Loading branch information
codereader committed Oct 12, 2021
1 parent b1349f5 commit 8f3f0f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions radiantcore/selection/algorithm/Texturing.cpp
Expand Up @@ -94,27 +94,29 @@ void TextureFlipper::FlipFace(IFace& face, int flipAxis)

// Rotation

TextureRotator::TextureRotator(const Vector2& pivot, double angle)
TextureRotator::TextureRotator(const Vector2& pivot, double angle, double textureAspectRatio)
{
_transform = Matrix3::getTranslation(-pivot);
_transform.premultiplyBy(Matrix3::getScale({ textureAspectRatio, 1 }));
_transform.premultiplyBy(Matrix3::getRotation(angle));
_transform.premultiplyBy(Matrix3::getScale({ 1 / textureAspectRatio, 1 }));
_transform.premultiplyBy(Matrix3::getTranslation(pivot));
}

void TextureRotator::RotatePatch(IPatch& patch, double angle)
{
RotateNode(std::make_shared<textool::PatchNode>(patch), angle);
RotateNode(std::make_shared<textool::PatchNode>(patch), angle, 1.0);
}

void TextureRotator::RotateFace(IFace& face, double angle)
{
RotateNode(std::make_shared<textool::FaceNode>(face), angle);
RotateNode(std::make_shared<textool::FaceNode>(face), angle, face.getTextureAspectRatio());
}

void TextureRotator::RotateNode(const textool::INode::Ptr& node, double angle)
void TextureRotator::RotateNode(const textool::INode::Ptr& node, double angle, double textureAspectRatio)
{
const auto& bounds = node->localAABB();
TextureRotator rotator({ bounds.origin.x(), bounds.origin.y() }, angle);
TextureRotator rotator({ bounds.origin.x(), bounds.origin.y() }, angle, textureAspectRatio);

rotator.processNode(node);
}
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/selection/algorithm/Texturing.h
Expand Up @@ -79,7 +79,7 @@ class TextureRotator :
public TextureNodeManipulator
{
public:
TextureRotator(const Vector2& pivot, double angle);
TextureRotator(const Vector2& pivot, double angle, double aspect);

// Directly rotate the texture of the given patch around its UV center
static void RotatePatch(IPatch& patch, double angle);
Expand All @@ -88,7 +88,7 @@ class TextureRotator :
static void RotateFace(IFace& face, double angle);

private:
static void RotateNode(const textool::INode::Ptr& node, double angle);
static void RotateNode(const textool::INode::Ptr& node, double angle, double aspect);
};

class TextureScaler :
Expand Down
Expand Up @@ -845,7 +845,7 @@ void TextureToolSelectionSystem::rotateSelectionCmd(const cmd::ArgumentList& arg
}

Vector2 pivot{ accumulator.getBounds().origin.x(), accumulator.getBounds().origin.y() };
selection::algorithm::TextureRotator rotator(pivot, angle);
selection::algorithm::TextureRotator rotator(pivot, angle, 1.0);
foreachSelectedNode(rotator);
}

Expand Down

0 comments on commit 8f3f0f7

Please sign in to comment.