Commit 4bd6cd0a authored by Sabrina Templeton's avatar Sabrina Templeton
Browse files

intersection calculation but something is off overall

parent 9dccffe2
......@@ -46,12 +46,12 @@ layout (triangle_strip, max_vertices = 16) out;
uniform samplerBuffer seeds;
// render full square
void render_square(vec3 pt) {
void render_square(vec3 pt, float size) {
//define all four points of the square
vec3 bl = pt + vec3(-.01, -.01, 0);
vec3 br = pt + vec3(.01, -.01, 0);
vec3 tl = pt + vec3(-.01, .01, 0);
vec3 tr = pt + vec3(.01, .01, 0);
vec3 bl = pt + vec3(-size, -size, 0);
vec3 br = pt + vec3(size, -size, 0);
vec3 tl = pt + vec3(-size, size, 0);
vec3 tr = pt + vec3(size, size, 0);
//top triangle
......@@ -92,8 +92,44 @@ float dist(vec3 a, vec3 b){
float comp2 = pow(b.y - a.y, 2);
return comp1 + comp2;
}
vec3 calc_intersect(vec3 zi,vec3 zj, vec3 b0, vec3 b1){ // b0 and b1 are border pts
return vec3(.15, .15, 0);
vec3 calc_intersect(vec3 p1, vec3 p2, vec3 q1, vec3 q2){ // p1 and p2 are seeds, q1 and q2 are borders
//initialize variables
float d = 0;
float l1 = 0;
float l2 = 0;
float n = 0;
//deal with the x
n = p1.x - p2.x;
d -= n* (p2.x + p1.x);
l1 += q2.x * n;
l2 += q1.x * n;
//deal with the y
n = p1.y - p2.y;
d -= n* (p2.y + p1.y);
l1 += q2.y * n;
l2 += q1.y * n;
//
d = .5 * d;
l1 = abs(l1 + d);
l2 = abs(l2 + d);
float l12 = l1 + l2;
if (l12 > 1e-30) {
l1 /= l12;
l2 /= l12;
}
else{
l1 = .5;
l2 = .5;
}
float x0 = l1 * q1.x + l2 * q2.x;
float y0 = l1 * q1.y + l2 * q2.y;
return vec3(x0, y0, 0);
}
void calc_poly(vec3 zi, vec3 zj){
......@@ -120,7 +156,7 @@ void calc_poly(vec3 zi, vec3 zj){
//test if the intersect point works
render_square(intersect);
render_square(intersect, .02);
}
......@@ -141,7 +177,7 @@ main() {
calc_poly(p0, nn0);
render_square(p0);
render_square(p0, .01);
//dist(vec3(0, 0, 0), vec3(5, 3, 0));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment