Skip to main content
gamedev.net
🔒 Locked

reflect() function for normal and light vector?

Started by karx11erx 4 replies 1.4k views
Original Post
karx11erx
karx11erx
I have to admit my knowledge of vector math is very limited indeed. :) How do I compute the reflection vector if I have an 'incoming' vector v and a surface normal n of the reflecting surface please? is it "2 * n * (n dot v) - v"?
_________karx11erxVisit my Descent site or see my case mod.
minamur
minamur
edit:
-2.0f * n * (n*normalize(v)) + v

where n is the surface normal and v is the direction vector you want to reflect

since you aren't normalizeing v i think you're over estimateing the projection of v onto n which would fuck up your results.
Darkstrike
Darkstrike
v-2*n*(n.v) is correct as long as n is normalized. If it isn't, v - 2*n*(n.v)/(n.n) is the way to go. v doesn't need to be normalized in either case.
minamur
minamur
Quote:
Original post by Darkstrike
v-2*n*(n.v) is correct as long as n is normalized. If it isn't, v - 2*n*(n.v)/(n.n) is the way to go. v doesn't need to be normalized in either case.


quoted for truth.

sorry, i didn't think before posting.
karx11erx
karx11erx
Thx. I am normalizing all vectors, just did not explicitly note that here.
_________karx11erxVisit my Descent site or see my case mod.
Bob Janova
Bob Janova
Quote:
I am normalizing all vectors, just did not explicitly note that here.


Not the velocity I hope ...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.