Jump to content
  • Advertisement
Sign in to follow this  
Hannesnisula

How to get a face's normal

This topic is 3612 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'm using D3DXIntersect for my collision detection and I want to find out the normal of the face that the ray hits, so I can calculate vectors when running into hills etc. I get the index of the face but how do I access the mesh's face's normal? BTW: Is using face normals to calculate which direction the character will move, when it hits a plane which isn't horizontal, the way to do that kind of collision detection? Are there faster ways to do it?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Hannesnisula
I'm using D3DXIntersect for my collision detection and I want to find out the normal of the face that the ray hits, so I can calculate vectors when running into hills etc. I get the index of the face but how do I access the mesh's face's normal?

BTW: Is using face normals to calculate which direction the character will move, when it hits a plane which isn't horizontal, the way to do that kind of collision detection? Are there faster ways to do it?


I did this before, what you have to do is get 2 normals pointing from one of the vectors to the other 2 then get the cross product.

Though I'd advice that you don't use the D3DXIntersect command and just use a physics library like PhysX.

Share this post


Link to post
Share on other sites
Quote:
Original post by CodaKiller
I did this before, what you have to do is get 2 normals pointing from one of the vectors to the other 2 then get the cross product.

Though I'd advice that you don't use the D3DXIntersect command and just use a physics library like PhysX.


Do you know how to get the face normal?

Why is it better to use a physics library instead of creating it yourself? Is it faster?

BTW: Can you see the sourcecode of the physics libraries?

Share this post


Link to post
Share on other sites
Quote:
Original post by Hannesnisula
Do you know how to get the face normal?
You need the 3 corner vertices of the triangle, subtract 2 of them from the third, and take the cross-product of the resulting vectors. There are many tutorials around the internet, or take a look at a geometry textbook.

Quote:
Why is it better to use a physics library instead of creating it yourself? Is it faster?
It is certainly faster in terms of development time, than building your own from scratch. In addition, realistic physics simulation is surprisingly complicated, and unless you have a very strong math and physics background, it will take you a very long time to get it right.

Quote:
BTW: Can you see the sourcecode of the physics libraries?
You can if they are open source, take a look at Bullet and ODE.

Share this post


Link to post
Share on other sites
Calculating that cross product will return the normal vector for that face; the principle should appear in any good maths book on vectors. Just remember to normalise the resultant vector though, otherwise your reflected light beam will have a different intensity.

It is probably better to use a physics library because of things like assembly language optimisations that are not obvious or straightforward (i.e. SSE) with high-level code... you can also rest assured that it has been bug-tested and scrutinised for some time and will likely give correct results all of the time.

(EDIT: Beaten to the punch by "swiftcoder"!)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!