<div dir="ltr">Hi,<br><br>Some more remarks:<br><br>+#include "d3d9.h" is unneeded: already set in d3dx9.h.<br><br>why not use the more common syntax: pointer->field instead of (*pointer).field?<br><br> +#define module(vx,vy,vz) sqrt((vx)*(vx)+(vy)*(vy)+(vz)*<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
(vz)) can be avoided by calling d3dxVector3Length.<br></blockquote><br> /*Let's calculate rotation now*/<br>+ /*If some of the scale factors is zero, it is impossible to obtain the rotation*/<br>+ if (((*poutscale).x==0)||((*poutscale).y==0)||((*poutscale).z==0))<br>
+ {<br>+ return D3DERR_INVALIDCALL;<br>+ }<br>+ /*We calculate the different products with simple sums of the members of the 3x3 submatrix<br>+ Quaternion (x,y,z,w) to Matrix:<br>+ | 1-2y2-2z2 2xy-2wz 2xz+2wy | <br>
+ | 2xy+2wz 1-2x2-2z2 2yz-wx | <br>+ | 2xz-2wy 2yz+2wx 1-2x2-2y2 |*/<br>+ wx=-((*pM).m[2][1]/(*poutscale).z-(*pM).m[1][2]/(*poutscale).y)/4;<br>+ wy=-((*pM).m[0][2]/(*poutscale).x-(*pM).m[2][0]/(*poutscale).z)/4;<br>
+ wz=-((*pM).m[1][0]/(*poutscale).y-(*pM).m[0][1]/(*poutscale).x)/4;<br>+ xy=((*pM).m[0][1]/(*poutscale).x+(*pM).m[1][0]/(*poutscale).y)/4;<br>+ xz=((*pM).m[0][2]/(*poutscale).x+(*pM).m[2][0]/(*poutscale).z)/4;<br>
+ yz=((*pM).m[1][2]/(*poutscale).y+(*pM).m[2][1]/(*poutscale).z)/4;<br>+ xx=(1+(*pM).m[0][0]/(*poutscale).x-(*pM).m[1][1]/(*poutscale).y-(*pM).m[2][2]/(*poutscale).z)/4;<br>+ yy=(1-(*pM).m[0][0]/(*poutscale).x+(*pM).m[1][1]/(*poutscale).y-(*pM).m[2][2]/(*poutscale).z)/4;<br>
+ zz=(1-(*pM).m[0][0]/(*poutscale).x-(*pM).m[1][1]/(*poutscale).y+(*pM).m[2][2]/(*poutscale).z)/4;<br>+ /*Then we go for the biggest component in order to minimise division error as commonly explained in the literacy.<br>
+ We just calculate one component from the diagonal to avoid sign loss of the square root. The first sign is not important<br>+ because the rotations (x,y,z,w) and (-x,-y,-z,-w) are equivalent. But if we calc ulated the other two components we would have<br>
+ to choose and could be wrong.*/<br>+ if ((xx>yy) && (xx>zz))<br>+ {<br>+ (*poutrotation).x=sqrt(xx);<br>+ (*poutrotation).y=xy/(*poutrotation).x;<br>+ (*poutrotation).z=xz/(*poutrotation).x;<br>
+ (*poutrotation).w=wx/(*poutrotation).x; <br>+ return S_OK;<br>+ }<br>+ if (yy>zz)<br>+ {<br>+ (*poutrotation).y=sqrt(yy);<br>+ (*poutrotation).x=xy/(*poutrotation).y;<br>+ (*poutrotation).z=yz/(*poutrotation).y;<br>
+ (*poutrotation).w=wy/(*poutrotation).y; <br>+ return S_OK;<br>+ }<br>+ (*poutrotation).z=sqrt(zz);<br>+ (*poutrotation).x=xz/(*poutrotation).z;<br>+ (*poutrotation).y=yz/(*poutrotation).z;<br>+ (*poutrotation).w=wz/(*poutrotation).z; <br>
+ return S_OK;<br>+}<br>+<br>can be avoided by calling D3DXQuaternionRotationMatrix<br><br><br>You could avoid useless explicit allocation of memory by writing<br>D3DXMATRIX pM; instead of D3DXMATRIX *pM;......<br>and then D3DXMatrixDecompose(&poutscale, &poutrotation, &pouttranslation, &pM); instead of D3DXMatrixDecompose(poutscale, poutrotation, pouttranslation, pM);<br>
<br>David<br><br><br><br><div class="gmail_quote">2008/8/4 H. Verbeet <span dir="ltr"><<a href="mailto:hverbeet@gmail.com">hverbeet@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2008/8/4 Luis Busquets <<a href="mailto:luis.busquets@ilidium.com">luis.busquets@ilidium.com</a>>:<br>
> +#include "d3d9.h"<br>
...<br>
> +#define module(vx,vy,vz) sqrt((vx)*(vx)+(vy)*(vy)+(vz)*(vz))<br>
...<br>
> +#include "stdio.h"<br>
<br>
You don't really need those.</blockquote><br></div><br></div>