Archived

This topic is now archived and is closed to further replies.

EasyGino

Rotation Question

Recommended Posts

Okay guys and girls, Quick question, what would be the best way to have two cubes on the screen and rotate them in opposite directions (I want an approach opinion). Whe I rotate around my pyramid, its the world moving and not actually the code (correct?).

Share this post


Link to post
Share on other sites
Not sure I understand you question are the two cubes being rotated around a pyramid with a fixed camera. If this is the case you can translate each of the cubes to the correct location, then rotate then rotate the first cube by x Radians, and then rotate the second cube by –x + 3.14159f Radians. Finally, increment x each frame between x = 0 to 2 * 3.14159f.

This should cause the two cubes to spin around the center in opposite directions. If this is not what you want can you clarify further?

Thanks


Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
Ok just two cubes on the screen, rotating in opposite directions, one rotates clockwise the other counter-clockwise.

Right now i''m using a pyramid and with the Matrices i''m using the timer with a formula to rotate around in circles.

Thanks.

Share this post


Link to post
Share on other sites
Based on your explanation it sounds like you want to rotate the cubes from a stationary position? In order to make the cubes rotate from a stationary position you need to build two matrices and render as per the following:


//Cube 1

D3DXMATRIX matMatrix;
D3DXMATRIX matRotation;
D3DXMATRIX matTranslate;

D3DXMatrixIdentity(&matMatrix);
D3DXMatrixRotationX(&matRotation, time); // Positive Time rotated by the x Axis

D3DXMatrixMultiply(&matMatrix, &matMatrix , &matRotation,);
D3DXMatrixTranslation(&matTranslate, x, y, z);
D3DXMatrixMultiply(&matMatrix, &matMatrix , &matTranslate,);
device->SetTransform(D3DTS_WORLD, &matMatrix);
// Render the 1st Cube


Cube 2
D3DXMatrixIdentity(&matMatrix);
D3DXMatrixRotationX(&matRotation, -time); // Negative Time Rotated by the x Axis

D3DXMatrixMultiply(&matMatrix, &matMatrix , &matRotation,);
D3DXMatrixTranslation(&matTranslate, x, y, z);
D3DXMatrixMultiply(&matMatrix, &matMatrix , &matTranslate,);
device->SetTransform(D3DTS_WORLD, &matMatrix);
// Render the 2nd Cube



This should get you closer to a solution.

Understanding is a three edged sword...

Share this post


Link to post
Share on other sites