• 10
• 9
• 13
• 10
• 18

# world rotation question...

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

## Recommended Posts

D3DXMatrixRotationY( &matTrans2, rotX ); D3DXMatrixMultiply(&matWorld2,&matWorld2,&matTrans2 ); D3DXMatrixTranslation(&matTrans2,transX,transY,transZ ); D3DXMatrixMultiply(&matWorld2,&matWorld2,&matTrans2 ); pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld2); //player x file

Before rotation:

After Rotation:

just as the above picture show...i wan to keep direction Z is same as the direction my character facing to...
but using the code above i only can rotate my character,cannot rotate the world coordinate...so i wan to ask is there anyone can help me to solve this question?

##### Share on other sites
It's not clear exactly what you want to do, I'm afraid. You can't "rotate" the world. You must rotate objects (such as the camera, your player, etc.) within the world.

Can you explain a little more about what you want to do?

##### Share on other sites
actually u get what i want to do...i want to rotate the world coordinate system...making direction X and Z to change every time i rotate my character.
I want to make a game use up arrow key to move in front...
and when my character rotate, i wish to make it walk in front to the direction where it facing to.
That mean the character can only walk in front to where it is facing...
If cannot rotate the world coordinate system is there any other choice to make it?

##### Share on other sites
You need variables for the character's position and direction. When you press the up arrow key, the character's new position will be:
 // speed is a float for how far you want the character to move when you press the arrow key character_position += speed * character_direction; 
When you rotate your character, change the character_direction and normalize it. You need to normalize it ( like D3DXVec3Normalize(&character_direction,&character_direction) ) so the equation above will move the character consistently.

##### Share on other sites
Thank you for reply...but i still got 1 question to ask...
how to set the character_direction?i didnt learn it before...is it any tutorial?

##### Share on other sites

Thank you for reply...but i still got 1 question to ask...
how to set the character_direction?i didnt learn it before...is it any tutorial?

Generally speaking, if you have a transform matrix for an object, you have the direction vectors as well (they will be the first three rows of the matrix, assuming row-vector convention).

There can be situations where you need a direction vector other than those encoded in the transform matrix, such as for typical FPS-style movement; in those cases, the required direction vector can computed using simple trigonometry.

##### Share on other sites
hmm...tat means the Direction Matrix is transX,transY and transZ in the code i given above?
or is the &matWorld2 will be the Direction Matrix?