1

I'm writing simple 3d application, with directX. Im a newbie, but i think i understand how D3DX Rotation works. when creating a colision detection functionality i notice that ball bounce in wrong direction. the code should change the direction of axis given in "direction" vector. Instead it change the 2 others:

speed = D3DXVECTOR3(1.0f, 2.0f, 3.0f);
direction = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
D3DXMATRIX temp;

D3DXMatrixRotationAxis(&temp, &direction, 3.14f);
D3DXVec3TransformCoord(&speed, &speed, &temp);

from breakpoint i know that speed changed from 1 , 2 , 3 to:

  • _D3DVECTOR {x=0.999999762 y=-2.00477481 z=-2.99681091 } _D3DVECTOR

What am i doing wrong here? The idea is to invert the axis specified in direction vector.

Sardukar
  • 11
  • 3
  • Rotating a point around one of the primary axes never changes the component of that axis. – rpress Jun 24 '18 at 05:33
  • Yeah seems like I little misunderstood that operation. So how can I invert one axis with rotation matrix? The axis I want to invert should be indicated with direction vector. – Sardukar Jun 24 '18 at 13:54
  • Not to randomize you too much, but you should read [MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/ee663275.aspx) and [Living without D3DX](https://blogs.msdn.microsoft.com/chuckw/2013/08/20/living-without-d3dx/). You may want to consider using [SimpleMath](https://github.com/Microsoft/DirectXTK/wiki/SimpleMath) in the [DirectX Tool Kit](https://github.com/Microsoft/DirectXTK/wiki/Getting-Started). – Chuck Walbourn Jun 24 '18 at 18:22

1 Answers1

0

You have created a rotation transformation of 180 around the X axis. Operating that on (1,2,3) resulted with (1,-2,-3) which is what you specified.

"Bouncing" your "speed" S vector with a plane that has Normal N:

angle = acos(S*N);   // provided that * is an operator for D3DXVec3Dot
axis = S^N;          // provided that ^ is an operator for D3DXVec3Cross
D3DXMatrixRotationAxis(&temp, &axis , angle*2);   // angle is *2
D3DXVec3TransformCoord(&S, &S, &temp);
S=-S;                                             // negate direction