Skip to content

Commit

Permalink
#5128: Do the math to get the desired angle in radians
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 13, 2021
1 parent de4fc12 commit 1520dbb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Expand Up @@ -3,18 +3,48 @@
#include "iselectiontest.h"
#include "selection/BestPoint.h"
#include "selection/SelectionPool.h"
#include "pivot.h"

namespace selection
{

void TextureRotator::beginTransformation(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint)
{
auto device2Pivot = constructDevice2Pivot(pivot2world, view);
auto pivotPoint = device2Pivot.transformPoint(Vector3(devicePoint.x(), devicePoint.y(), 0));
_start = Vector2(pivotPoint.x(), pivotPoint.y());

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

void TextureRotator::transform(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint, unsigned int constraints)
void TextureRotator::transform(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint, unsigned int constraintFlags)
{
auto device2Pivot = constructDevice2Pivot(pivot2world, view);

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

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

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

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

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

//rMessage() << "Angle " << radians_to_degrees(angle) << std::endl;
}

void TextureRotator::resetCurAngle()
Expand Down
Expand Up @@ -12,11 +12,10 @@ class TextureRotator :
public ManipulatorComponentBase
{
private:
Vector3 _axis;
Vector3 _start;
Vector2 _start;

// The most recently calculated angle for rendering purposes
Vector3::ElementType _curAngle;
Vector2::ElementType _curAngle;
public:
TextureRotator() :
_curAngle(0)
Expand All @@ -28,7 +27,7 @@ class TextureRotator :
void transform(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint, unsigned int constraints) override;

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

class TextureToolRotateManipulator :
Expand Down

0 comments on commit 1520dbb

Please sign in to comment.