Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra brackets for old gcc #95

Merged
merged 2 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/polyscope/transformation_gizmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class TransformationGizmo : public Widget {
glm::vec3 dragPrevVec{1., 0.,
0.}; // the normal vector from the previous frame of the drag OR previous translation center

std::array<glm::vec3, 3> niceRGB = {glm::vec3{211 / 255., 45 / 255., 62 / 255.},
glm::vec3{65 / 255., 121 / 255., 225 / 255.},
glm::vec3{95 / 255., 175 / 255., 35 / 255.}};
std::array<glm::vec3, 3> niceRGB = {{glm::vec3{211 / 255., 45 / 255., 62 / 255.},
glm::vec3{65 / 255., 121 / 255., 225 / 255.},
glm::vec3{95 / 255., 175 / 255., 35 / 255.}}};

void markUpdated();

Expand Down
28 changes: 18 additions & 10 deletions src/transformation_gizmo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,16 @@ bool TransformationGizmo::interact() {
std::tuple<float, float, glm::vec3> TransformationGizmo::circleTest(glm::vec3 raySource, glm::vec3 rayDir,
glm::vec3 center, glm::vec3 normal, float radius) {

// used for explicit constructors below to make old compilers (gcc-5) happy
typedef std::tuple<float, float, glm::vec3> ret_t;

// Intersect the ray with the plane defined by the normal
float div = glm::dot(normal, rayDir);
if (std::fabs(div) < 1e-6) return {-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}}; // parallel
if (std::fabs(div) < 1e-6)
return ret_t{-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}}; // parallel

float tRay = glm::dot((center - raySource), normal) / div;
if (tRay < 0) return {-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}}; // behind the ray
if (tRay < 0) return ret_t{-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}}; // behind the ray

glm::vec3 hitPoint = raySource + tRay * rayDir;

Expand All @@ -378,16 +381,18 @@ std::tuple<float, float, glm::vec3> TransformationGizmo::circleTest(glm::vec3 ra
float ringDist = std::fabs(hitRad - radius);
glm::vec3 nearestPoint = center + (hitPoint - center) / hitRad * radius;

return {tRay, ringDist, nearestPoint};
return ret_t{tRay, ringDist, nearestPoint};
}

std::tuple<float, float, glm::vec3> TransformationGizmo::lineTest(glm::vec3 raySource, glm::vec3 rayDir,
glm::vec3 center, glm::vec3 tangent, float length) {

// used for explicit constructors below to make old compilers (gcc-5) happy
typedef std::tuple<float, float, glm::vec3> ret_t;

glm::vec3 nBetween = glm::cross(rayDir, tangent);
if (glm::length(nBetween) < 1e-6)
return {-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}}; // parallel
return ret_t{-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}}; // parallel

glm::vec3 nTan = glm::cross(tangent, nBetween);
glm::vec3 nRay = glm::cross(rayDir, nBetween);
Expand All @@ -396,18 +401,21 @@ std::tuple<float, float, glm::vec3> TransformationGizmo::lineTest(glm::vec3 rayS
float tLine = glm::dot(raySource - center, nRay) / glm::dot(tangent, nRay);

if (tLine < -length || tLine > length || tRay < 0)
return {-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}}; // out of bounds or beind
return ret_t{-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}}; // out of bounds or beind

glm::vec3 pRay = raySource + tRay * rayDir;
glm::vec3 pLine = center + tLine * tangent;

return {tRay, glm::length(pRay - pLine), pLine};
return ret_t{tRay, glm::length(pRay - pLine), pLine};
}

std::tuple<float, float, glm::vec3> TransformationGizmo::sphereTest(glm::vec3 raySource, glm::vec3 rayDir,
glm::vec3 center, float radius,
bool allowHitSurface) {

// used for explicit constructors below to make old compilers (gcc-5) happy
typedef std::tuple<float, float, glm::vec3> ret_t;

glm::vec3 oc = raySource - center;
float b = 2. * dot(oc, rayDir);
float c = glm::dot(oc, oc) - radius * radius;
Expand All @@ -417,18 +425,18 @@ std::tuple<float, float, glm::vec3> TransformationGizmo::sphereTest(glm::vec3 ra
float tHit = glm::dot(rayDir, center - raySource);
if (tHit < 0.) {
// hit behind
return {-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}};
return ret_t{-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}};
}
glm::vec3 hitPoint = raySource + tHit * rayDir;
return {tHit, glm::length(hitPoint - center) - radius, hitPoint};
return ret_t{tHit, glm::length(hitPoint - center) - radius, hitPoint};
} else {
// actual hit
float tHit = (-b - std::sqrt(disc)) / 2.;
if (tHit < 0.) {
// hit behind
return {-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}};
return ret_t{-1, std::numeric_limits<float>::infinity(), glm::vec3{0., 0., 0.}};
}
return {tHit, 0, raySource + tHit * rayDir};
return ret_t{tHit, 0, raySource + tHit * rayDir};
}
}

Expand Down