Skip to content

Commit

Permalink
parameterize line thickness
Browse files Browse the repository at this point in the history
  • Loading branch information
toloudis committed Dec 16, 2024
1 parent ce48843 commit 54d4951
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 52 deletions.
140 changes: 108 additions & 32 deletions renderlib/MoveTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ struct ManipColors
static constexpr glm::vec3 bright = { 1.0f, 1.0f, 1.0f };
};

static const float s_lineThickness = 4.0f;

void
MoveTool::action(SceneView& scene, Gesture& gesture)
{
Expand Down Expand Up @@ -205,27 +207,51 @@ MoveTool::draw(SceneView& scene, Gesture& gesture)
uint32_t code = manipulatorCode(selectionCode, m_codesOffset);

// Arrow line
gesture.graphics.addLine(Gesture::Graphics::VertsCode(axis.p + dir * (scale * 0.05f), color, opacity, code),
Gesture::Graphics::VertsCode(axis.p + dir * scale, color, opacity, code));
// gesture.graphics.addLine(Gesture::Graphics::VertsCode(axis.p + dir * (scale * 0.05f), color, opacity, code),
// Gesture::Graphics::VertsCode(axis.p + dir * scale, color, opacity, code));
gesture.graphics.addLineStrip({ Gesture::Graphics::VertsCode(axis.p + dir * (scale * 0.05f), color, opacity, code),
Gesture::Graphics::VertsCode(axis.p + dir * scale, color, opacity, code) },
4.0f,
false);

// Circle at the base of the arrow
float diskScale = scale * (fullDraw ? 0.06f : 0.03f);
gesture.drawCircle(axis.p + dir * scale, dirX * diskScale, dirY * diskScale, 12, color, 1, code);
// gesture.drawCircle(axis.p + dir * scale, dirX * diskScale, dirY * diskScale, 12, color, 1, code);
gesture.drawCircleAsStrip(
axis.p + dir * scale, dirX * diskScale, dirY * diskScale, 12, color, 1, code, s_lineThickness);
if (fullDraw) {
// Arrow
glm::vec3 ve = camFrame.vz - dir * dot(dir, camFrame.vz);
glm::vec3 vd = normalize(cross(ve, dir)) * (scale * 0.06f);
gesture.graphics.addLine(Gesture::Graphics::VertsCode(axis.p + dir * scale + vd, color, opacity, code),
Gesture::Graphics::VertsCode(axis.p + dir * (scale * 1.2f), color, opacity, code));
gesture.graphics.extLine(Gesture::Graphics::VertsCode(axis.p + dir * scale - vd, color, opacity, code));
// gesture.graphics.addLine(Gesture::Graphics::VertsCode(axis.p + dir * scale + vd, color, opacity, code),
// Gesture::Graphics::VertsCode(axis.p + dir * (scale * 1.2f), color, opacity, code));
// gesture.graphics.extLine(Gesture::Graphics::VertsCode(axis.p + dir * scale - vd, color, opacity, code));
gesture.graphics.addLineStrip({ Gesture::Graphics::VertsCode(axis.p + dir * scale + vd, color, opacity, code),
Gesture::Graphics::VertsCode(axis.p + dir * (scale * 1.2f), color, opacity, code),
Gesture::Graphics::VertsCode(axis.p + dir * scale - vd, color, opacity, code) },
4.0f,
false);
}

// Extension to arrow line at the opposite end
gesture.graphics.addLine(Gesture::Graphics::VertsCode(axis.p - dir * (scale * 0.05f), color, opacity, code),
Gesture::Graphics::VertsCode(axis.p - dir * (scale * 0.25f), color, opacity, code));

gesture.drawCircle(
axis.p - dir * scale * 0.25f, dirX * scale * 0.03f, dirY * scale * 0.03f, 12, color, opacity, code);
// gesture.graphics.addLine(Gesture::Graphics::VertsCode(axis.p - dir * (scale * 0.05f), color, opacity, code),
// Gesture::Graphics::VertsCode(axis.p - dir * (scale * 0.25f), color, opacity, code));
gesture.graphics.addLineStrip(
{ Gesture::Graphics::VertsCode(axis.p - dir * (scale * 0.05f), color, opacity, code),
Gesture::Graphics::VertsCode(axis.p - dir * (scale * 0.25f), color, opacity, code) },
4.0f,
false);

// gesture.drawCircle(
// axis.p - dir * scale * 0.25f, dirX * scale * 0.03f, dirY * scale * 0.03f, 12, color, opacity, code);
gesture.drawCircleAsStrip(axis.p - dir * scale * 0.25f,
dirX * scale * 0.03f,
dirY * scale * 0.03f,
12,
color,
opacity,
code,
s_lineThickness);
};

// Complete the axis with a transparent surface for the tip of the arrow
Expand Down Expand Up @@ -285,30 +311,76 @@ MoveTool::draw(SceneView& scene, Gesture& gesture)

// Draw a bunch of 2d arrows
float diskScale = scale * 0.17;
gesture.graphics.addLine(Gesture::Graphics::VertsCode(p + dirX * diskScale * li, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirX * diskScale * lo, arrowsColor, opacity, code));
gesture.graphics.addLine(Gesture::Graphics::VertsCode(p + dirX * diskScale - v1, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirX * diskScale, arrowsColor, opacity, code));
gesture.graphics.extLine(Gesture::Graphics::VertsCode(p + dirX * diskScale - v0, arrowsColor, opacity, code));
// gesture.graphics.addLine(Gesture::Graphics::VertsCode(p + dirX * diskScale * li, arrowsColor, opacity, code),
// Gesture::Graphics::VertsCode(p + dirX * diskScale * lo, arrowsColor, opacity, code));
gesture.graphics.addLineStrip(
{ Gesture::Graphics::VertsCode(p + dirX * diskScale * li, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirX * diskScale * lo, arrowsColor, opacity, code) },
s_lineThickness,
false);

// gesture.graphics.addLine(Gesture::Graphics::VertsCode(p + dirX * diskScale - v1, arrowsColor, opacity, code),
// Gesture::Graphics::VertsCode(p + dirX * diskScale, arrowsColor, opacity, code));
// gesture.graphics.extLine(Gesture::Graphics::VertsCode(p + dirX * diskScale - v0, arrowsColor, opacity, code));
gesture.graphics.addLineStrip(
{ Gesture::Graphics::VertsCode(p + dirX * diskScale - v1, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirX * diskScale, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirX * diskScale - v0, arrowsColor, opacity, code) },
s_lineThickness,
false);
gesture.graphics.addLine(Gesture::Graphics::VertsCode(p + dirY * diskScale * li, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirY * diskScale * lo, arrowsColor, opacity, code));
gesture.graphics.addLine(Gesture::Graphics::VertsCode(p + dirY * diskScale + v1, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirY * diskScale, arrowsColor, opacity, code));
gesture.graphics.extLine(Gesture::Graphics::VertsCode(p + dirY * diskScale - v0, arrowsColor, opacity, code));
gesture.graphics.addLine(Gesture::Graphics::VertsCode(p - dirX * diskScale * li, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirX * diskScale * lo, arrowsColor, opacity, code));
gesture.graphics.addLine(Gesture::Graphics::VertsCode(p - dirX * diskScale + v1, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirX * diskScale, arrowsColor, opacity, code));
gesture.graphics.extLine(Gesture::Graphics::VertsCode(p - dirX * diskScale + v0, arrowsColor, opacity, code));
gesture.graphics.addLine(Gesture::Graphics::VertsCode(p - dirY * diskScale * li, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirY * diskScale * lo, arrowsColor, opacity, code));
gesture.graphics.addLine(Gesture::Graphics::VertsCode(p - dirY * diskScale - v1, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirY * diskScale, arrowsColor, opacity, code));
gesture.graphics.extLine(Gesture::Graphics::VertsCode(p - dirY * diskScale + v0, arrowsColor, opacity, code));
gesture.graphics.addLineStrip(
{ Gesture::Graphics::VertsCode(p + dirY * diskScale * li, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirY * diskScale * lo, arrowsColor, opacity, code) },
s_lineThickness,
false);
// gesture.graphics.addLine(Gesture::Graphics::VertsCode(p + dirY * diskScale + v1, arrowsColor, opacity, code),
// Gesture::Graphics::VertsCode(p + dirY * diskScale, arrowsColor, opacity, code));
// gesture.graphics.extLine(Gesture::Graphics::VertsCode(p + dirY * diskScale - v0, arrowsColor, opacity, code));
gesture.graphics.addLineStrip(
{ Gesture::Graphics::VertsCode(p + dirY * diskScale + v1, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirY * diskScale, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p + dirY * diskScale - v0, arrowsColor, opacity, code) },
s_lineThickness,
false);
// gesture.graphics.addLine(Gesture::Graphics::VertsCode(p - dirX * diskScale * li, arrowsColor, opacity, code),
// Gesture::Graphics::VertsCode(p - dirX * diskScale * lo, arrowsColor, opacity, code));
gesture.graphics.addLineStrip(
{ Gesture::Graphics::VertsCode(p - dirX * diskScale * li, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirX * diskScale * lo, arrowsColor, opacity, code) },
s_lineThickness,
false);
// gesture.graphics.addLine(Gesture::Graphics::VertsCode(p - dirX * diskScale + v1, arrowsColor, opacity, code),
// Gesture::Graphics::VertsCode(p - dirX * diskScale, arrowsColor, opacity, code));
// gesture.graphics.extLine(Gesture::Graphics::VertsCode(p - dirX * diskScale + v0, arrowsColor, opacity, code));
gesture.graphics.addLineStrip(
{ Gesture::Graphics::VertsCode(p - dirX * diskScale + v1, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirX * diskScale, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirX * diskScale + v0, arrowsColor, opacity, code) },
s_lineThickness,
false);
// gesture.graphics.addLine(Gesture::Graphics::VertsCode(p - dirY * diskScale * li, arrowsColor, opacity, code),
// Gesture::Graphics::VertsCode(p - dirY * diskScale * lo, arrowsColor, opacity, code));
gesture.graphics.addLineStrip(
{ Gesture::Graphics::VertsCode(p - dirY * diskScale * li, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirY * diskScale * lo, arrowsColor, opacity, code) },
s_lineThickness,
false);
// gesture.graphics.addLine(Gesture::Graphics::VertsCode(p - dirY * diskScale - v1, arrowsColor, opacity, code),
// Gesture::Graphics::VertsCode(p - dirY * diskScale, arrowsColor, opacity, code));
// gesture.graphics.extLine(Gesture::Graphics::VertsCode(p - dirY * diskScale + v0, arrowsColor, opacity, code));
gesture.graphics.addLineStrip(
{ Gesture::Graphics::VertsCode(p - dirY * diskScale - v1, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirY * diskScale, arrowsColor, opacity, code),
Gesture::Graphics::VertsCode(p - dirY * diskScale + v0, arrowsColor, opacity, code) },
s_lineThickness,
false);
}

float diskScale = scale * 0.04 * facingScale;
gesture.drawCircle(p, dirX * diskScale, dirY * diskScale, 8, color, opacity, code);
// gesture.drawCircle(p, dirX * diskScale, dirY * diskScale, 8, color, opacity, code);
gesture.drawCircleAsStrip(p, dirX * diskScale, dirY * diskScale, 8, color, opacity, code, s_lineThickness);
};

bool forceActiveX =
Expand Down Expand Up @@ -347,8 +419,12 @@ MoveTool::draw(SceneView& scene, Gesture& gesture)
}

float diskScale = scale * 0.09;
gesture.drawCircle(axis.p, camFrame.vx * diskScale, camFrame.vy * diskScale, 24, color, 1, code);
// gesture.drawCircle(axis.p, camFrame.vx * diskScale, camFrame.vy * diskScale, 24, color, 1, code);
gesture.drawCircleAsStrip(
axis.p, camFrame.vx * diskScale, camFrame.vy * diskScale, 24, color, 1, code, s_lineThickness);
diskScale = scale * 0.02;
gesture.drawCircle(axis.p, camFrame.vx * diskScale, camFrame.vy * diskScale, 24, color, 1, code);
// gesture.drawCircle(axis.p, camFrame.vx * diskScale, camFrame.vy * diskScale, 24, color, 1, code);
gesture.drawCircleAsStrip(
axis.p, camFrame.vx * diskScale, camFrame.vy * diskScale, 24, color, 1, code, s_lineThickness);
}
}
15 changes: 10 additions & 5 deletions renderlib/RotateTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct ManipColors
};

static const float s_orthogonalThreshold = cos(glm::radians(89.0f));
static const float s_lineThickness = 4.0f;

static float
getSignedAngle(const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& vN)
Expand Down Expand Up @@ -272,7 +273,8 @@ RotateTool::draw(SceneView& scene, Gesture& gesture)
color = glm::vec3(1, 1, 0);
}
// gesture.drawCircle(axis.p, axis.l.vy * axisscale, axis.l.vz * axisscale, 48, color, 1, code, &discPlane);
gesture.drawCircleAsStrip(axis.p, axis.l.vy * axisscale, axis.l.vz * axisscale, 48, color, 1, code, &discPlane);
gesture.drawCircleAsStrip(
axis.p, axis.l.vy * axisscale, axis.l.vz * axisscale, 48, color, 1, code, s_lineThickness, &discPlane);
}
// Draw the y ring in xz plane
{
Expand All @@ -282,7 +284,8 @@ RotateTool::draw(SceneView& scene, Gesture& gesture)
color = glm::vec3(1, 1, 0);
}
// gesture.drawCircle(axis.p, axis.l.vz * axisscale, axis.l.vx * axisscale, 48, color, 1, code, &discPlane);
gesture.drawCircleAsStrip(axis.p, axis.l.vz * axisscale, axis.l.vx * axisscale, 48, color, 1, code, &discPlane);
gesture.drawCircleAsStrip(
axis.p, axis.l.vz * axisscale, axis.l.vx * axisscale, 48, color, 1, code, s_lineThickness, &discPlane);
}
// Draw the z ring in xy plane
{
Expand All @@ -292,7 +295,8 @@ RotateTool::draw(SceneView& scene, Gesture& gesture)
color = glm::vec3(1, 1, 0);
}
// gesture.drawCircle(axis.p, axis.l.vx * axisscale, axis.l.vy * axisscale, 48, color, 1, code, &discPlane);
gesture.drawCircleAsStrip(axis.p, axis.l.vx * axisscale, axis.l.vy * axisscale, 48, color, 1, code, &discPlane);
gesture.drawCircleAsStrip(
axis.p, axis.l.vx * axisscale, axis.l.vy * axisscale, 48, color, 1, code, s_lineThickness, &discPlane);
}

// Draw the camera-axis rotation manipulator as a circle always facing the view
Expand All @@ -303,7 +307,7 @@ RotateTool::draw(SceneView& scene, Gesture& gesture)
color = glm::vec3(1, 1, 0);
}
// gesture.drawCircle(axis.p, camFrame.vx * scale, camFrame.vy * scale, 48, color, 1, code);
gesture.drawCircleAsStrip(axis.p, camFrame.vx * scale, camFrame.vy * scale, 48, color, 1, code);
gesture.drawCircleAsStrip(axis.p, camFrame.vx * scale, camFrame.vy * scale, 48, color, 1, code, s_lineThickness);
}

// if we are rotating, draw a tick mark where the rotation started, and where we are now
Expand Down Expand Up @@ -369,7 +373,8 @@ RotateTool::draw(SceneView& scene, Gesture& gesture)
(int)(96.0 * abs(a) / (glm::two_pi<float>()) + 0.5),
color,
0.5,
noCode);
noCode,
s_lineThickness);
// gesture.drawArc(axis.p - v0 * (radius * 1.1f),
// a,
// axis.p,
Expand Down
10 changes: 6 additions & 4 deletions renderlib/gesture/gesture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ Gesture::drawArcAsStrip(const glm::vec3& pstart,
uint32_t numSegments,
glm::vec3 color,
float opacity,
uint32_t code)
uint32_t code,
float thickness)
{
std::vector<Gesture::Graphics::VertsCode> v;
// draw arc from pstart through angle with center of circle at center
Expand All @@ -144,7 +145,7 @@ Gesture::drawArcAsStrip(const glm::vec3& pstart,
v.push_back(Gesture::Graphics::VertsCode(p1, color, opacity, code));

if (v.size() >= 2) {
graphics.addLineStrip(v, 6.0f, false);
graphics.addLineStrip(v, thickness, false);
}
}

Expand Down Expand Up @@ -188,6 +189,7 @@ Gesture::drawCircleAsStrip(glm::vec3 center,
glm::vec3 color,
float opacity,
uint32_t code,
float thickness,
glm::vec4* clipPlane)
{
std::vector<Gesture::Graphics::VertsCode> v;
Expand All @@ -207,7 +209,7 @@ Gesture::drawCircleAsStrip(glm::vec3 center,

v.push_back(Gesture::Graphics::VertsCode(p0, color, opacity, code));
}
graphics.addLineStrip(v, 6.0f, true);
graphics.addLineStrip(v, thickness, true);
} else {
// any segment that would be entirely clipped must terminate the strip as a non-closed strip
bool isClipped = false;
Expand All @@ -228,7 +230,7 @@ Gesture::drawCircleAsStrip(glm::vec3 center,
// add a line strip and then empty the vector and start anew
if (v.size() >= 2) {
// LOG_DEBUG << "drawCircleAsStrip: " << v.size();
graphics.addLineStrip(v, 6.0f, false);
graphics.addLineStrip(v, thickness, false);
}
v.clear();
}
Expand Down
4 changes: 3 additions & 1 deletion renderlib/gesture/gesture.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ struct Gesture
uint32_t numSegments,
glm::vec3 color,
float opacity,
uint32_t code);
uint32_t code,
float thickness);

void drawCircle(glm::vec3 center,
glm::vec3 xaxis,
Expand All @@ -451,6 +452,7 @@ struct Gesture
glm::vec3 color,
float opacity,
uint32_t code,
float thickness,
glm::vec4* clipPlane = nullptr);

// does not draw a flat base
Expand Down
2 changes: 2 additions & 0 deletions renderlib/graphics/GestureGraphicsGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ GestureRendererGL::draw(SceneView& sceneView, SelectionBuffer* selection, Gestur
ScopedGlVertexBuffer vertex_buffer(graphics.verts.data(),
graphics.verts.size() * sizeof(Gesture::Graphics::VertsCode));

// buffer containing all the strip vertices
ScopedGlTextureBuffer texture_buffer(graphics.stripVerts.data(),
graphics.stripVerts.size() * sizeof(Gesture::Graphics::VertsCode));
// Prepare a lambda to draw the Gesture commands. We'll run the lambda twice, once to
Expand Down Expand Up @@ -415,6 +416,7 @@ GestureRendererGL::draw(SceneView& sceneView, SelectionBuffer* selection, Gestur
if ((int)graphics.stripProjections[i] != sequence) {
continue;
}

const glm::ivec2& range = graphics.stripRanges[i];
const float thickness = graphics.stripThicknesses[i];

Expand Down
Loading

0 comments on commit 54d4951

Please sign in to comment.