Skip to content

Commit

Permalink
#5740: Face::rotateTexDef method is using the same rotator class as P…
Browse files Browse the repository at this point in the history
…atches
  • Loading branch information
codereader committed Oct 1, 2021
1 parent e12b053 commit cec9770
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
40 changes: 1 addition & 39 deletions radiantcore/brush/Face.cpp
Expand Up @@ -589,45 +589,7 @@ void Face::scaleTexdef(float sFactor, float tFactor) {

void Face::rotateTexdef(float angle)
{
if (m_winding.size() < 3) return;

undoSave();

// Calculate the pivot of rotation (which will be the UV centroid)
Vector2 centroid = m_winding[0].texcoord;

for (std::size_t i = 1; i < m_winding.size(); ++i)
{
centroid += m_winding[i].texcoord;
}

centroid /= static_cast<Vector2::ElementType>(m_winding.size());

auto angleInRadians = degrees_to_radians(angle);

// Translate to origin, then rotate, then translate back
auto pivotedRotation = Matrix3::getTranslation(-centroid)
.getPremultipliedBy(Matrix3::getRotation(angleInRadians))
.getPremultipliedBy(Matrix3::getTranslation(centroid));

// Calculate the desired set of UV coordinates
Vector2 uvs[] =
{
pivotedRotation * m_winding[0].texcoord,
pivotedRotation * m_winding[1].texcoord,
pivotedRotation * m_winding[2].texcoord,
};

// Prepare the winding vertex XYZ coordinates
Vector3 points[] =
{
m_winding[0].vertex,
m_winding[1].vertex,
m_winding[2].vertex,
};

setTexDefFromPoints(points, uvs);
_texdef = m_texdefTransformed;
selection::algorithm::TextureRotator::RotateFace(*this, degrees_to_radians(angle));
}

void Face::fitTexture(float s_repeat, float t_repeat) {
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/selection/algorithm/Texturing.cpp
Expand Up @@ -97,6 +97,11 @@ void TextureRotator::RotatePatch(IPatch& patch, double angle)
RotateNode(std::make_shared<textool::PatchNode>(patch), angle);
}

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

void TextureRotator::RotateNode(const textool::INode::Ptr& node, double angle)
{
const auto& bounds = node->localAABB();
Expand Down
3 changes: 3 additions & 0 deletions radiantcore/selection/algorithm/Texturing.h
Expand Up @@ -78,6 +78,9 @@ class TextureRotator :
// Directly rotate the texture of the given patch around its UV center
static void RotatePatch(IPatch& patch, double angle);

// Directly rotate the texture of the given face around its UV center
static void RotateFace(IFace& face, double angle);

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

0 comments on commit cec9770

Please sign in to comment.