# Vertex shader point inside triangle of a mesh

This topic is 2544 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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:)

##### Share on other sites
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

##### Share on other sites

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.

##### Share on other sites
Hidden
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.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633664
• Total Posts
3013238
×