0

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)

theCNG27
  • 405
  • 8
  • 27

1 Answers1

0

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.

Vivee
  • 23
  • 1
  • 5
  • Oh, yes it should be transM instead of posM but I wanted to know if it at least works with position only and forgot to change it back. I'll edit that. Sure about parameters 2 and 4? MSDN says different. I have tryed to change them to 3 but it didn't help. Looks even worse^^ – theCNG27 Jan 26 '14 at 20:04