# DirectX help

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

## Recommended Posts

First things first, Hello I'm new to posting here but have found several threads that have helped my in the past. Yes this is homework related, no I'm not looking for someone to do it, just help me where I'm stuck at. I have searched for answer but have not found it yet, if this has been covered then please tell me where to find it.

Ok now what I need for the homework:
I need an sphere rotating at the world orgin like a sun, which I have working.
I need a sphere rotating around that sphere like a planet, which I have working as well.
I need a sphere rotating around that sphere like a moon, is kicking my butt.

This is the code that I have, it doesn't state that the planet or moon need to rotate themselves I just added it for fun and experience. This is what I have between the BeginScene and EndScene.

 pd3dDevice->BeginScene(); // sun transformations D3DXMatrixRotationX(&meshRotate, D3DXToRadian(90)); // align sphere axis with world D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); D3DXMatrixRotationY(&meshRotate, D3DXToRadian(3 * angle1++)); // make sphere rotate D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); pd3dDevice->SetTransform(D3DTS_WORLD, &meshMat); // apply transformation Sun->DrawSubset(0); // draw sun sphere // remove all transformations D3DXMatrixIdentity(&meshMat); // planet transformations D3DXMatrixRotationX(&meshRotate, D3DXToRadian(angle2--)); // rotate sphere 1 axis D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); D3DXMatrixRotationY(&meshRotate, D3DXToRadian(2 * angle3++)); // rotate sphere 2 axis D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); D3DXMatrixTranslation(&meshTranslate, 135, 0, 0); // move sphere D3DXMatrixMultiply(&meshMat, &meshMat, &meshTranslate); D3DXMatrixRotationY(&meshRotate, D3DXToRadian(angle4--)); // around sun sphere D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); pd3dDevice->SetTransform(D3DTS_WORLD, &meshMat); // apply transformations pPlanet->DrawSubset(0); // draw planet sphere // remove all transformations D3DXMatrixIdentity(&meshMat); // moon transformations D3DXMatrixRotationX(&meshRotate, D3DXToRadian(angle2)); // rotate sphere 1 axis D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); D3DXMatrixRotationY(&meshRotate, D3DXToRadian(angle1)); // rotate sphere 2 axis D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); D3DXMatrixRotationZ(&meshRotate, D3DXToRadian(angle3)); // rotate sphere 3 axis D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); D3DXMatrixMultiply(&meshMat, &meshMat, &meshTranslate); // return to last location of planet D3DXMatrixTranslation(&meshTranslate, -50, 0, 0); // move sphere D3DXMatrixMultiply(&meshMat, &meshMat, &meshTranslate); D3DXMatrixRotationY(&meshRotate, D3DXToRadian(angle1)); // rotate sphere around 1 axis of planet D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); // D3DXMatrixRotationZ(&meshRotate, D3DXToRadian(angle1)); // rotate sphere around 2 axis of planet // D3DXMatrixMultiply(&meshMat, &meshMat, &meshRotate); pd3dDevice->SetTransform(D3DTS_WORLD, &meshMat); pMoon->DrawSubset(0); pd3dDevice->EndScene(); 

What seems to be happening is that the moon is still orbiting around the center of the world and not the center of the planet. I'm beggining to think that I need to use a vertex list, but I'm not sure how to do that with a sphere. Can someone point me in the direction of getting the moon to orbit the planet? Also if anyone has suggestions to cleaner code I would love to hear them as well.

##### Share on other sites
Save the position of the earth after you have calculated its transform (meshMat._41 = x, meshMat._42 = y, meshMat.43 = z) and transform the moon by that after making all of the other transforms you have made.

L. Spiro

##### Share on other sites
It never occured to me to translate to the last position of the planet AFTER all of my other transormations. Thank you very much, it is working great.

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 10
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013149
×