add history to guides

This commit is contained in:
2019-06-19 17:55:35 +02:00
parent 6058f05d3f
commit 9ad3c351ce
7 changed files with 395 additions and 11 deletions

View File

@@ -75,6 +75,76 @@ bool ray_intersect(glm::vec3 ray_origin, glm::vec3 ray_dir, glm::vec3 plane_orig
return true;
};
// see: http://geomalgorithms.com/a07-_distance.html
// dist3D_Line_to_Line(): get the 3D minimum distance between 2 lines
// Input: two 3D lines L1 and L2
// Return: the shortest distance between L1 and L2
float lines_distance(const glm::vec3& p0a, const glm::vec3& p0b,
const glm::vec3& p1a, const glm::vec3& p1b)
{
glm::vec3 u = p0b - p0a;
glm::vec3 v = p1b - p1a;
glm::vec3 w = p0a - p1a;
float a = glm::dot(u,u); // always >= 0
float b = glm::dot(u,v);
float c = glm::dot(v,v); // always >= 0
float d = glm::dot(u,w);
float e = glm::dot(v,w);
float D = a*c - b*b; // always >= 0
float sc, tc;
// compute the line parameters of the two closest points
if (D < 0.00001f) { // the lines are almost parallel
sc = 0.0;
tc = (b>c ? d/b : e/c); // use the largest denominator
}
else {
sc = (b*e - c*d) / D;
tc = (a*e - b*d) / D;
}
// get the difference of the two closest points
glm::vec3 dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc)
return glm::length(dP); // return the closest distance
}
bool segments_intersect_3d(const glm::vec3& p0a, const glm::vec3& p0b,
const glm::vec3& p1a, const glm::vec3& p1b, glm::vec3& out_pt, glm::vec2& out_hit_uv)
{
float denom = ((p1b.y - p1a.y)*(p0b.x - p0a.x)) -
((p1b.x - p1a.x)*(p0b.y - p0a.y));
float nume_a = ((p1b.x - p1a.x)*(p0a.y - p1a.y)) -
((p1b.y - p1a.y)*(p0b.x - p1a.x));
float nume_b = ((p0b.x - p0a.x)*(p0a.y - p1a.y)) -
((p0b.y - p0a.y)*(p0a.x - p1a.x));
if(denom == 0.0f)
{
if(nume_a == 0.0f && nume_b == 0.0f)
{
return 0;//COINCIDENT;
}
return 0;//PARALLEL;
}
float ua = nume_a / denom;
float ub = nume_b / denom;
if(ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f)
{
// Get the intersection point.
out_pt.x = p0a.x + ua*(p0b.x - p0a.x);
out_pt.y = p0a.y + ua*(p0b.y - p0a.y);
return 1;//INTERESECTING;
}
return 0;//NOT_INTERESECTING;
}
// see: https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
bool segments_intersect(const glm::vec2& p0a, const glm::vec2& p0b,
const glm::vec2& p1a, const glm::vec2& p1b, glm::vec2& out_pt, glm::vec2& out_hit_uv)