Vector reflection problem
I am currently programming the phisics for my game, but i cant make a vector reflect correctly from a normal.
It seems to do just fine from certain angles, but with some others...
BOOOOM!
the poor vector gets launched to join the stars, or even sticks to the ground.
Anybody had this problem?
I think it may be some aproximation problem regarding the angle of incidence.
Anybody has a reflect function that works properly to share so i can see what i am doing wrong?
Thanks a lot!
__________________
Alejandro Martínez
__________________Alejandro Martínez
Try this (quickly written):
Given your vector v and normal n (n is unit length):
Let r = n*v.dotproduct(n) // the component of v parallel to n
Let t = v - r // the component of v perpendicular to n
Then, your new, reflected vector is:
v_reflected_about_n = r - t
You can check to see if r and t are right, since v should be equal to t+r.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Given your vector v and normal n (n is unit length):
Let r = n*v.dotproduct(n) // the component of v parallel to n
Let t = v - r // the component of v perpendicular to n
Then, your new, reflected vector is:
v_reflected_about_n = r - t
You can check to see if r and t are right, since v should be equal to t+r.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
quote:
v_reflected_about_n = r - t
Shouldn''t it be t - r ? The perpendicular component is left unchanged, and the parallel component is reversed.
A simplified version of Graham''s equation is
v_mirrored = v - 2 * (v Dot n) * n
Assuming that n is the normalized normal.
Cédric
quote:
Original post by cedricl
Shouldn't it be t - r ? The perpendicular component is left unchanged, and the parallel component is reversed.
Depends on what you want to reflect against. If you want to reflect about n , then the parallel component should be unchanged. If you want to reflect the vector to the opposite side of the surface from which n originates, then you would be correct.
(It might be important to note that I mean "perpendicular component" to mean perpendicular to the normal n, and "parallel component" to mean parallel to the normal n.)
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
[edited by - grhodes_at_work on February 20, 2003 12:44:48 PM]
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement