Sign in to follow this  

Given a surface normal and a direction vector, how do I reflect?

This topic is 4204 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

How do I reflect a direction vector based on a surface normal? The way I'm doing it atm is this,

  if SurfNorm.x<>0 DirVec=-DirVec
  if SurfNorm.y<>0 dirvec=-dirvec


which works to a degree, it always reflects, it just some times reflects in the wrong direction. it only works on 90 degree surfaces for pretty obvious reasons. Less obvious (to me) is how to reflect it properly. I have a vector lib so I can almost anything required, I just need a pointer in the right direction please :) (Pun of course intended :P)

Share this post


Link to post
Share on other sites
This should do the trick for perfect elastic reflection:


dir -= norm * 2.0f * norm.dot(dir);




If you want to know why it works its because the dot product tells you how much one vector lies in the direction of the other. In other words its like projecting one vector onto the other and taking its projected length. So once you know how much the direction vector is pointing in the normal direction you take twice this length off if the normal direction to reflect around the normal. You can also model plastic reflections and any degree in between by using a number between 1.0f and 2.0f instead (where 1.0f is perfect plastic and 2.0f is perfect elastic).

Share this post


Link to post
Share on other sites

This topic is 4204 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this