Archived

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

Enfekted

Reflected Vectors

Recommended Posts

Enfekted    122
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
Enfekted    122
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