Jump to content
  • Advertisement
Sign in to follow this  
frankypoo

quick ques. about rotation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to turn my character around with the left/right keys and move him forward with up/down keys. What's happening is that my character is rotating around 0,0,0 as a pivot point, so when I move him away from the origin, instead of rotating in place, he sweeps a rotation around the origin. Here's my code:
member variables:
    D3DXMATRIX	_WorldMatrix;
    D3DXMATRIX  _RotationMatrix;					            
    D3DXMATRIX	_ScaleMatrix;
    D3DXMATRIX	_MoveMatrix;

inline void Move(float amount)
{
    D3DXMatrixTranslation(&_MoveMatrix,
	_WorldMatrix._31*amount,
        _WorldMatrix._32*amount,
        _WorldMatrix._33*amount);
}
inline void Turn(float amount)
{
    D3DXMATRIX tempMatrix;
    D3DXMatrixIdentity(&tempMatrix);
    D3DXMatrixRotationY(&tempMatrix, amount);
    D3DXMatrixMultiply(&_RotationMatrix, &_RotationMatrix, &tempMatrix);
}

void Draw()
{
    D3DXMatrixMultiply(&_WorldMatrix, &_WorldMatrix, &_RotationMatrix);
    D3DXMatrixMultiply(&_WorldMatrix, &_WorldMatrix, &_ScaleMatrix);
    D3DXMatrixMultiply(&_WorldMatrix, &_WorldMatrix, &_MoveMatrix);
		
    _pd3dDevice->SetTransform( D3DTS_WORLD, &_WorldMatrix );

    ...Render stuff here

    //Reset the matrices
    D3DXMatrixIdentity(&_RotationMatrix); 
    D3DXMatrixIdentity(&_ScaleMatrix);
    D3DXMatrixIdentity(&_MoveMatrix);
}
any suggestions? (ok, i'm way newbie...)

Share this post


Link to post
Share on other sites
Advertisement
When calling Move and Turn, you should just save the ammount to a variable like keeping a position vector as to find out where the character is and some rotation variables ( like -0.01f for turning a little left and 0.02 for turning a little bit more right). Then do the actual movement of matrices before rendering. First apply the rotation to the matrix when the char is still at 0,0,0. Then apply the translation.. Should work, if not.. It's early in the morning and I have to sleep more!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!