Finding nearest polygon normal

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Barbalute
Posts: 7
Joined: Sun May 28, 2006 9:40 pm

Finding nearest polygon normal

Post by Barbalute »

Hi,
how would I find the normal of the nearest polygon? Some example code would be appreciated but any help would be great.
Thanks
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Nearest polygon to what?
Barbalute
Posts: 7
Joined: Sun May 28, 2006 9:40 pm

Post by Barbalute »

To the camera, sorry I should have specified.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I guess it doesn't really matter. You need to get access to its vertex/index buffers.

Use those to find the triangle [set of 3 vertices] that is nearest the point in question. Then you take the normals of those vertices and average them.

Doing this with a brute force search will be slow. You will probably want to use something similar to the octtree triangle selector. Whatever it is, you will need to be able to access the vertex data so you can find the normals.

Travis
Barbalute
Posts: 7
Joined: Sun May 28, 2006 9:40 pm

Post by Barbalute »

Ok, thanks for all your help. I'd better get started with it then. This could take a little while though :P
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post by dhenton9000 »

newtondynamics can be used in collision mode, not physics mode, which might give you a non brute-force method of finding those vertices. I think that collision type packages (coldet) might work as well. RAPID and SOLID might be a bit too much.

BTW, is that Barbalute as in Brown Barbalute? :D
Barbalute
Posts: 7
Joined: Sun May 28, 2006 9:40 pm

Post by Barbalute »

hm ok I'll look into newtondynamics as well. Thanks for the advice - and yes, it is :D
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

i'm curious.. what do you need the normal of the closest triangle for? perhaps there's a different way around your problem
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Post Reply