# its rotating the wrong way ?

This topic is 2991 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

trying to rotate an object in conjution with a main object so , in stays local to it. via maths float x = -2; float y = 5; float matrix[16]; player->GetMatrix( matrix ); float matrixSinMinus = matrix[2]; float matrixSin = matrix[8]; float matrixCos = matrix[10]; // rotate local corners to there real world position float tx,tz; tx = (matrixCos * x) + (matrixSinMinus * z); // dim3d is all correct tz = (matrixSin * x) + (matrixCos * z); Model->SetX(tx+player->GetX()); Model->SetZ(tz+player->GetZ()); if i rotate the player , the player rotates, but the Model that i want to keep local to it rotates in the oposite direction . can you tell me what i got wrong

##### Share on other sites
Why doing things so complicated? If you want to apply parenting to an object, then multiply its (local) transformation matrix with the world matrix of the parent and you're done. E.g. so:
float matrix1[16];float matrix2[16];float matrix3[16];player->GetWorldMatrix( matrix1 );model->GetLocalMatrix( matrix2 );matrix3 = matrix2 * matrix1;model->SetWorldMatrix( matrix3 );
(where matrix3 is calculated assuming you use row vectors; re-order the multiplicants if you use column vectors).

##### Share on other sites
I'm not sure how D3D does stuff, but I think a normal rotation-around-Y-matrix would have

matrixSin = matrix[2];
matrixSinMinus = matrix[8];

Good Luck,

• 10
• 17
• 9
• 13
• 41