Vertex shader point inside triangle of a mesh
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:)
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
http://www.opengl.org/wiki/Common_Mistakes#Selection_and_Picking_and_Feedback_Mode
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)
As you see this can work for 2d vectors too.
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
Popular Topics
Advertisement