Sign in to follow this  
frankypoo

quick ques. about rotation

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this