world rotation question...

Started by
5 comments, last by nananya 13 years, 3 months ago
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:
game1.jpg

After Rotation:
game2.jpg
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?
Advertisement
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?

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.

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?
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.

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.

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?

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.
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?

This topic is closed to new replies.

Advertisement