I'm trying to position and rotate triangles with D3DXVec3TransformCoordArray and a world matrix but when I draw the triangles transformed they are distorted horribly. What am I doing wrong? (Btw. I need to do this on CPU, it's not for drawing purposes...)
D3DXVECTOR3 tri[3];
tri[0] = mbuffer.vertices[mbuffer.indices[x]].position;
tri[1] = mbuffer.vertices[mbuffer.indices[x + 1]].position;
tri[2] = mbuffer.vertices[mbuffer.indices[x + 2]].position;
D3DXMatrixRotationQuaternion(&rotM, &obj->getRotation());
D3DXMatrixTranslation(&posM, obj->getPosition().x, obj->getPosition().y, obj->getPosition().z);
transM = rotM * posM;
D3DXVec3TransformCoordArray(tri, 1, tri, 1, &transM, 3);
When I comment out the last line D3DXVec3TransformCoordArray(tri, 1, tri, 1, &transM, 3);
then the object renders fine but, of course, not transformed...
EDIT:
Also, obj->getPosition()
and obj->getRotation()
return correct values.
EDIT2: Allright, it seems like
D3DXVec3TransformCoord(&tri[0], &tri[0], &transM);
D3DXVec3TransformCoord(&tri[1], &tri[1], &transM);
D3DXVec3TransformCoord(&tri[2], &tri[2], &transM);
instead of
D3DXVec3TransformCoordArray(tri, 1, tri, 1, &transM, 3);
solves the problem.
Can anyone tell me how to use D3DXVec3TransformCoordArray
properly? (MSDN wasn't very helpful)
EDIT: D3DXVec3TransformCoordArray in this case stride parameters should be size of D3DXVECTOR3. Try to pass in D3DXVec3TransformCoordArray transM matrix instead posM if you want rotate and translate.