Skip to content

Commit

Permalink
fix a few bugs when drawing Beziers
Browse files Browse the repository at this point in the history
- points were not smoothed
- firs CP was missing tangent handles
- CP being moved, drawn in cyan, was not reverted to its original color if no mouse motion
- Issue #653 is still to be fixed (see comment "continue editing the tangent")
  • Loading branch information
devernay committed Jul 20, 2021
1 parent b7d8a02 commit 50c808c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
10 changes: 9 additions & 1 deletion Engine/RotoPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,9 @@ RotoPaint::drawOverlay(double time,
colorChanged = true;
}

glEnable(GL_POINT_SMOOTH);
glPointSize(cpWidth * screenPixelRatio);
// code below draws GL_POINTS
for (SelectedCPs::const_iterator cpIt = _imp->ui->selectedCps.begin();
cpIt != _imp->ui->selectedCps.end();
++cpIt) {
Expand All @@ -1907,7 +1910,6 @@ RotoPaint::drawOverlay(double time,
}
} // for(cpIt)

glPointSize(cpWidth * screenPixelRatio);
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
Expand Down Expand Up @@ -1938,6 +1940,7 @@ RotoPaint::drawOverlay(double time,
}

if (drawFeather) {
glEnable(GL_POINT_SMOOTH);
glPointSize(cpWidth * screenPixelRatio);
glBegin(GL_POINTS);
glVertex2f(xF, yF);
Expand Down Expand Up @@ -2557,6 +2560,11 @@ RotoPaint::onOverlayPenDown(double time,

_imp->ui->selectedCps.clear();
_imp->ui->setCurrentTool( _imp->ui->selectAllAction.lock() );

// continue editing the tangent

//->ui->tangentBeingDragged = *it;
//_imp->ui->state = eEventStateDraggingRightTangent;
} else {
BezierCPPtr fp = _imp->ui->builtBezier->getFeatherPointAtIndex(i);
assert(fp);
Expand Down
3 changes: 1 addition & 2 deletions Engine/RotoPaintInteract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ RotoPaintInteract::drawSelectedCp(double time,

bool drawLeftHandle = leftDeriv.x != x || leftDeriv.y != y;
bool drawRightHandle = rightDeriv.y != x || rightDeriv.y != y;
glEnable(GL_POINT_SMOOTH);
glBegin(GL_POINTS);
if (drawLeftHandle) {
if (colorLeftTangent) {
Expand Down Expand Up @@ -238,7 +237,6 @@ RotoPaintInteract::drawSelectedCp(double time,
glVertex2d(rightDeriv.x, rightDeriv.y);
}
glEnd();
glDisable(GL_POINT_SMOOTH);
} // drawSelectedCp

void
Expand Down Expand Up @@ -919,6 +917,7 @@ RotoPaintInteract::handleControlPointSelection(const std::pair<BezierCPPtr,

cpBeingDragged = p;
state = eEventStateDraggingControlPoint;
evaluateOnPenUp = true; // so that color is restored to normal on pen up, even if there's no motion
}

void
Expand Down
27 changes: 20 additions & 7 deletions Engine/RotoUndoCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,8 @@ dragTangent(double time,
const Transform::Matrix3x3& transform,
double dx,
double dy,
bool left,
bool both, //< should both tangents be moved symmetrically?
bool left, //< which one is being controlled
bool autoKeying,
bool breakTangents,
bool draggedPointIsFeather)
Expand All @@ -846,10 +847,18 @@ dragTangent(double time,
getDeltaForPoint(fp, time, transform, dx, dy, left, breakTangents, &otherFpDiffX, &otherFpDiffY, &isOnKeyframe);

if (autoKeying || isOnKeyframe) {
if (left) {
cp.getBezier()->movePointLeftAndRightIndex(cp, fp, time, dx, dy, otherDiffX, otherDiffY, dx, dy, otherFpDiffX, otherFpDiffY, breakTangents, draggedPointIsFeather);
if (both) {
if (!left) {
dx = -dx;
dy = -dy;
}
cp.getBezier()->movePointLeftAndRightIndex(cp, fp, time, dx, dy, -dx, -dy, dx, dy, -dx, -dy, breakTangents, draggedPointIsFeather);
} else {
cp.getBezier()->movePointLeftAndRightIndex(cp, fp, time, otherDiffX, otherDiffY, dx, dy, otherFpDiffX, otherFpDiffY, dx, dy, breakTangents, draggedPointIsFeather);
if (left) {
cp.getBezier()->movePointLeftAndRightIndex(cp, fp, time, dx, dy, otherDiffX, otherDiffY, dx, dy, otherFpDiffX, otherFpDiffY, breakTangents, draggedPointIsFeather);
} else {
cp.getBezier()->movePointLeftAndRightIndex(cp, fp, time, otherDiffX, otherDiffY, dx, dy, otherFpDiffX, otherFpDiffY, dx, dy, breakTangents, draggedPointIsFeather);
}
}
}
}
Expand Down Expand Up @@ -922,7 +931,7 @@ MoveTangentUndoCommand::redo()
bool autoKeying = roto->getContext()->isAutoKeyingEnabled();


dragTangent( _time, *cp, *fp, transform, _dx, _dy, _left, autoKeying, _breakTangents, _tangentBeingDragged->isFeatherPoint() );
dragTangent( _time, *cp, *fp, transform, _dx, _dy, false, _left, autoKeying, _breakTangents, _tangentBeingDragged->isFeatherPoint() );


if (_firstRedoCalled) {
Expand Down Expand Up @@ -1459,8 +1468,12 @@ MakeBezierUndoCommand::redo()
int lastIndex = _newCurve->getControlPointsCount() - 1;
assert(lastIndex >= 0);
_lastPointAdded = lastIndex;
_newCurve->moveLeftBezierPoint(lastIndex, _time, -_dx, -_dy);
_newCurve->moveRightBezierPoint(lastIndex, _time, _dx, _dy);
Transform::Matrix3x3 transform;
_newCurve->getTransformAtTime(_time, &transform);
BezierCPPtr cp = _newCurve->getControlPointAtIndex(lastIndex);
BezierCPPtr fp = _newCurve->getFeatherPointAtIndex(lastIndex);

dragTangent(_time, *cp, *fp, transform, _dx, _dy, true, false, false, false, false);
}

RotoItemPtr parentItem;
Expand Down

0 comments on commit 50c808c

Please sign in to comment.