Skip to content

Commit

Permalink
#5128: Display the angle of rotation (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 16, 2021
1 parent b8b2092 commit 4712eb5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 13 deletions.
2 changes: 2 additions & 0 deletions radiant/selection/ManipulateMouseTool.cpp
Expand Up @@ -211,6 +211,8 @@ void ManipulateMouseTool::endMove()

// Finish the undo move
GlobalUndoSystem().finish(command.str());

activeManipulator->setSelected(false);
}
}

Expand Down
6 changes: 0 additions & 6 deletions radiantcore/selection/RadiantSelectionSystem.cpp
Expand Up @@ -31,12 +31,6 @@
namespace selection
{

namespace
{
const std::string RKEY_MANIPULATOR_FONTSTYLE = "user/ui/manipulatorFontStyle";
const std::string RKEY_MANIPULATOR_FONTSIZE = "user/ui/manipulatorFontSize";
}

// --------- RadiantSelectionSystem Implementation ------------------------------------------

RadiantSelectionSystem::RadiantSelectionSystem() :
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/selection/manipulators/ManipulatorComponents.h
Expand Up @@ -17,6 +17,12 @@
namespace selection
{

namespace
{
constexpr const char* const RKEY_MANIPULATOR_FONTSTYLE = "user/ui/manipulatorFontStyle";
constexpr const char* const RKEY_MANIPULATOR_FONTSIZE = "user/ui/manipulatorFontSize";
}

class ManipulatorComponentBase :
public IManipulator::Component
{
Expand Down
Expand Up @@ -28,22 +28,22 @@ void TextureRotator::transform(const Matrix4& pivot2world, const VolumeTest& vie
auto device2Pivot = constructDevice2Pivot(pivot2world, view);

auto current3D = device2Pivot.transformPoint(Vector3(devicePoint.x(), devicePoint.y(), 0));
auto current = Vector2(current3D.x(), current3D.y());
_current = Vector2(current3D.x(), current3D.y());

auto length = current.getLength();
auto length = _current.getLength();
if (length > 0)
{
current /= length;
_current /= length;
}

_curAngle = acos(_start.dot(current));
_curAngle = acos(_start.dot(_current));

if (constraintFlags & Constraint::Type1)
{
_curAngle = float_snapped(_curAngle, 5 * c_DEG2RADMULT);
}

auto sign = _start.crossProduct(current) < 0 ? +1 : -1;
auto sign = _start.crossProduct(_current) < 0 ? +1 : -1;
_curAngle *= sign;

_rotateFunctor(Vector2(pivot2world.tx(), pivot2world.ty()), _curAngle);
Expand All @@ -59,11 +59,22 @@ Vector3::ElementType TextureRotator::getCurAngle() const
return _curAngle;
}

const Vector2& TextureRotator::getStartDirection() const
{
return _start;
}

const Vector2& TextureRotator::getCurrentDirection() const
{
return _current;
}

TextureToolRotateManipulator::TextureToolRotateManipulator() :
_rotator(std::bind(&TextureToolRotateManipulator::rotateSelected, this, std::placeholders::_1, std::placeholders::_2)),
_renderableCircle(8 << 3)
_renderableCircle(8 << 3),
_circleRadius(1.0f)
{
draw_circle(8, 1.0f, &_renderableCircle.front(), RemapXYZ());
draw_circle(8, _circleRadius, &_renderableCircle.front(), RemapXYZ());
_renderableCircle.setColour(Colour4b(200, 200, 200, 200));
}

Expand Down Expand Up @@ -122,6 +133,12 @@ void TextureToolRotateManipulator::renderComponents(const Matrix4& pivot2World)
if (!_shader)
{
_shader = GlobalRenderSystem().capture("$WIRE_OVERLAY");

auto manipulatorFontStyle = registry::getValue<std::string>(RKEY_MANIPULATOR_FONTSTYLE) == "Sans" ?
IGLFont::Style::Sans : IGLFont::Style::Mono;
auto manipulatorFontSize = registry::getValue<int>(RKEY_MANIPULATOR_FONTSIZE);

_glFont = GlobalOpenGL().getFont(manipulatorFontStyle, manipulatorFontSize);
}

if (_renderableCircle.empty()) return;
Expand All @@ -135,6 +152,31 @@ void TextureToolRotateManipulator::renderComponents(const Matrix4& pivot2World)
glPushMatrix();
glTranslated(translation.x(), translation.y(), 0);

auto angle = _rotator.getCurAngle();

if (_selectableZ.isSelected())
{
glEnable(GL_BLEND);
glBlendColor(0, 0, 0, 0.3f);
glBlendFunc(GL_CONSTANT_ALPHA_EXT, GL_ONE_MINUS_CONSTANT_ALPHA_EXT);

glColor3f(0.6f, 0.6f, 0.6f);

glBegin(GL_TRIANGLE_FAN);

glVertex3d(0, 0, 0);

auto startingPointOnCircle = _rotator.getStartDirection() * _circleRadius;
auto currentPointOnCircle = _rotator.getCurrentDirection() * _circleRadius;

glVertex3d(startingPointOnCircle.x(), startingPointOnCircle.y(), 0);
glVertex3d(currentPointOnCircle.x(), currentPointOnCircle.y(), 0);

glEnd();

glDisable(GL_BLEND);
}

// Enable point colours if required
glEnableClientState(GL_COLOR_ARRAY);

Expand All @@ -143,6 +185,14 @@ void TextureToolRotateManipulator::renderComponents(const Matrix4& pivot2World)

glDisableClientState(GL_COLOR_ARRAY);

if (_selectableZ.isSelected())
{
glColor3f(0.75f, 0.75f, 0.75f);
glRasterPos3dv(Vector3(0, 0, 0));

_glFont->drawString(fmt::format("Rotate: {0:3.2f} degrees", static_cast<float>(c_RAD2DEGMULT * angle)));
}

glPopMatrix();
}

Expand Down
10 changes: 10 additions & 0 deletions radiantcore/selection/manipulators/TextureToolRotateManipulator.h
Expand Up @@ -13,6 +13,7 @@ class TextureRotator :
{
private:
Vector2 _start;
Vector2 _current;

// The most recently calculated angle for rendering purposes
Vector2::ElementType _curAngle;
Expand All @@ -32,6 +33,12 @@ class TextureRotator :

void resetCurAngle();
Vector2::ElementType getCurAngle() const;

// The vector from the pivot to the starting point of the manipulation (normalised)
const Vector2& getStartDirection() const;

// The vector from the pivot to the current point of manipulation (normalised)
const Vector2& getCurrentDirection() const;
};

class TextureToolRotateManipulator :
Expand All @@ -45,6 +52,9 @@ class TextureToolRotateManipulator :
RenderableCircle _renderableCircle;

ShaderPtr _shader;
IGLFont::Ptr _glFont;

float _circleRadius;

public:
TextureToolRotateManipulator();
Expand Down

0 comments on commit 4712eb5

Please sign in to comment.