Skip to content

Commit

Permalink
allow circles to be clipped against a plane
Browse files Browse the repository at this point in the history
  • Loading branch information
toloudis committed Mar 18, 2024
1 parent 23592c4 commit 17ee71d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 5 additions & 3 deletions renderlib/RotateTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ RotateTool::draw(SceneView& scene, Gesture& gesture)

gesture.graphics.addCommand(GL_LINES);

glm::vec4 discPlane(camFrame.vz, -glm::dot(camFrame.vz, axis.p));

float axisscale = scale * 0.85f;
// Draw the x ring in yz plane
{
Expand All @@ -269,7 +271,7 @@ RotateTool::draw(SceneView& scene, Gesture& gesture)
if (m_activeCode == RotateTool::kRotateX) {
color = glm::vec3(1, 1, 0);
}
gesture.drawCircle(axis.p, axis.l.vy * axisscale, axis.l.vz * axisscale, 48, color, 1, code);
gesture.drawCircle(axis.p, axis.l.vy * axisscale, axis.l.vz * axisscale, 48, color, 1, code, &discPlane);
}
// Draw the y ring in xz plane
{
Expand All @@ -278,7 +280,7 @@ RotateTool::draw(SceneView& scene, Gesture& gesture)
if (m_activeCode == RotateTool::kRotateY) {
color = glm::vec3(1, 1, 0);
}
gesture.drawCircle(axis.p, axis.l.vz * axisscale, axis.l.vx * axisscale, 48, color, 1, code);
gesture.drawCircle(axis.p, axis.l.vz * axisscale, axis.l.vx * axisscale, 48, color, 1, code, &discPlane);
}
// Draw the z ring in xy plane
{
Expand All @@ -287,7 +289,7 @@ RotateTool::draw(SceneView& scene, Gesture& gesture)
if (m_activeCode == RotateTool::kRotateZ) {
color = glm::vec3(1, 1, 0);
}
gesture.drawCircle(axis.p, axis.l.vx * axisscale, axis.l.vy * axisscale, 48, color, 1, code);
gesture.drawCircle(axis.p, axis.l.vx * axisscale, axis.l.vy * axisscale, 48, color, 1, code, &discPlane);
}

// Draw the camera-axis rotation manipulator as a circle always facing the view
Expand Down
14 changes: 11 additions & 3 deletions renderlib/gesture/gesture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ Gesture::drawCircle(glm::vec3 center,
uint32_t numSegments,
glm::vec3 color,
float opacity,
uint32_t code)
uint32_t code,
glm::vec4* clipPlane)
{
for (int i = 0; i < numSegments; ++i) {
float t0 = float(i) / float(numSegments);
Expand All @@ -628,8 +629,15 @@ Gesture::drawCircle(glm::vec3 center,
glm::vec3 p0 = center + xaxis * cosf(theta0) + yaxis * sinf(theta0);
glm::vec3 p1 = center + xaxis * cosf(theta1) + yaxis * sinf(theta1);

graphics.addLine(Gesture::Graphics::VertsCode(p0, color, opacity, code),
Gesture::Graphics::VertsCode(p1, color, opacity, code));
if (clipPlane) {
if (glm::dot(*clipPlane, glm::vec4(p0, 1.0)) > 0 && glm::dot(*clipPlane, glm::vec4(p1, 1.0)) > 0) {
graphics.addLine(Gesture::Graphics::VertsCode(p0, color, opacity, code),
Gesture::Graphics::VertsCode(p1, color, opacity, code));
}
} else {
graphics.addLine(Gesture::Graphics::VertsCode(p0, color, opacity, code),
Gesture::Graphics::VertsCode(p1, color, opacity, code));
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion renderlib/gesture/gesture.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ struct Gesture
uint32_t numSegments,
glm::vec3 color,
float opacity,
uint32_t code);
uint32_t code,
glm::vec4* clipPlane = nullptr);

// does not draw a flat base
void drawCone(glm::vec3 base,
Expand Down

0 comments on commit 17ee71d

Please sign in to comment.