My X Mesh won't rotate c++ directx

Started by
1 comment, last by ramilolz 13 years ago
I have two objects. The problem is that i can't scale and rotate objects, i can only do one of them. if i put scaling code after rotating it will scale. if i rotating code is after scaling it will rotate. I don't really know why this is happening.
here is my code


void AnimatedMesh::UpdateFrameMatrices(const D3DXFRAME *frameBase, D3DXMATRIX *parentMatrix, Transformation trans)
{
D3DXFRAME_EXTENDED *currentFrame = (D3DXFRAME_EXTENDED*)frameBase;

// If parent matrix exists multiply our frame matrix by it
if (parentMatrix != NULL)
{
D3DXMatrixMultiply(&currentFrame->exCombinedTransformationMatrix, &currentFrame->TransformationMatrix, parentMatrix);
D3DXMatrixRotationYawPitchRoll(&currentFrame->exCombinedTransformationMatrix, trans.Rx, trans.Ry, trans.Rz);
D3DXMatrixScaling(&currentFrame->exCombinedTransformationMatrix, trans.Sx, trans.Sy, trans.Sz);
}
else
currentFrame->exCombinedTransformationMatrix = currentFrame->TransformationMatrix;

// If we have a sibling recurse
if (currentFrame->pFrameSibling != NULL)
UpdateFrameMatrices(currentFrame->pFrameSibling, parentMatrix, trans);

// If we have a child recurse
if (currentFrame->pFrameFirstChild != NULL)
UpdateFrameMatrices(currentFrame->pFrameFirstChild, &currentFrame->exCombinedTransformationMatrix, trans);
}


I Know the problem won't be there but i don't know where it would be
Advertisement
You need to create a separate matrix each for scaling and rotation. Then multiply all of the matrices together - combined, rotation and scaling.

The way you have it, you're overwriting the combined.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

it didn't work. I still have same result.
here is my new code


D3DXMATRIX w;
D3DXMATRIX s;
D3DXMatrixRotationYawPitchRoll(&w, trans.Rx, trans.Ry, trans.Rz);
D3DXMatrixScaling(&s, trans.Sx, trans.Sy, trans.Sz);
D3DXMatrixMultiply(&currentFrame->exCombinedTransformationMatrix, &w, &s);


This topic is closed to new replies.

Advertisement