Jump to content
  • Advertisement
Sign in to follow this  
Tasaq

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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

Share this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!