Vertex shader point inside triangle of a mesh

Started by
1 comment, last by Tasaq 12 years, 3 months ago
I would like to find 3 points that creates a poly in which my given point is currently located, and that triangle is a part of a mesh. I only need x and z, don't need the y axis, so you can say the problem is 2 dimensional only :) I can't do much now because i have problems with my shader compiler, and i only work on ideas. Mainly my problem is that my algorithm might chose vertices that are not creating poly... And I have no idea how to make sure that 3 points i find creates a real poly. Is there any way to do that in glsl? Any ideas someone?:) I will be really grateful:)
Advertisement
Sounds like you want to select a triangle based on a mouse click. Selection (of vertex or line or triangle or whatever) is not done through shaders. It is done by raycasting or color selection.
http://www.opengl.org/wiki/Common_Mistakes#Selection_and_Picking_and_Feedback_Mode
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Sounds like you want to select a triangle based on a mouse click. Selection (of vertex or line or triangle or whatever) is not done through shaders. It is done by raycasting or color selection.
http://www.opengl.or...d_Feedback_Mode


It's not my aim :) I want to send vec2 to my shader and find a poly, no mouse clicking etc.
Here is function which determines "is point inside triangle" (implementation taken from Code Sampler's:Basic Collision)



const bool isInsideTriangle(const vec3 &point, const vec3 triangle[3])

{

float totalAngle = 0;

vec3 v1 = normalize(point - triangle[0]);

vec3 v2 = normalize(point - triangle[1]);

vec3 v3 = normalize(point - triangle[2]);

totalAngle += acos(dot(v1,v2));

totalAngle += acos(dot(v2,v3));

totalAngle += acos(dot(v3,v1));

return abs(totalAngle - (6.28 /* 2 * Pi */ )) < 0.001;

}






As you see this can work for 2d vectors too.

This topic is closed to new replies.

Advertisement