Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Enfekted

Reflected Vectors

This topic is 5432 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''ve got a slight problem which I''ve been working on all morning with very little progress. Its with my Reflect function for reflecting 2D vectors across a Normal. If anyone can point out my mistake I would be very grateful.
HRESULT D3DXVec2Reflect( D3DXVECTOR2 *pOut, D3DXVECTOR2 *pIn, D3DXVECTOR2 *pNormal )
{
	D3DXVECTOR2 vVector;
	D3DXVec2Normalize( &vVector, pIn );
	
	*pOut = (vVector - *pNormal * 2.0f * D3DXVec2Dot( &vVector, pNormal )) * D3DXVec2Length(pIn);
return S_OK;
}
This function works fine except in certain circumstances. For example, if pIn = { 0, 7 } and pNormal = { 1, 0 } then pOut returns { 0, 7 } rather than { 0, -7 }. On the other hand, if pIn = { 1, 1 } and pNormal = { 1, 0 } then pOut correctly returns { 1, -1 }. So for the most part the function seems to be working. If anyone can help me out I would be most greatful.

Share this post


Link to post
Share on other sites
Advertisement
Nevermind, the function''s right.

If pIn = { 0, 7 } and pNormal = { 1, 0 } then pOut returns { 0, 7 }. Which is correct. pOut would return { 0, -7 } if pNormal was = { 0, 1 }.

I can''t beleive i spent all morning trying to figure out a bug that didn''t exist. I need a vacation.

Share this post


Link to post
Share on other sites

  • 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!