Sign in to follow this  

Mesh Roll With Pivot at Top

Recommended Posts

I was trying to rotate a mesh about its z-axis with the pivot of rotation being the top most part of the mesh. In other words, I want the mesh to move about a circle with the center at origin(0,0,z) and radius being the bounding radius of the mesh. I translated the mesh to the (y-offseted by the bounding radius) world origin. Apllied rotation about Z axis and then translated it back to its previous position. Instead of moving about a circle, the mesh kept rolling in a wierd manner. I hope the code below gives a better picture as to what I tried to do. Any help will be deeply appreciated.
void OffsetedRollObject_PivotTop(const FLOAT fUnits)
	D3DXMATRIX		matWorld, matTrans ;
	D3DXVECTOR3		vec3Pos ;

	m_TheWorld.GetWorldMatrix(&matWorld) ;
	vec3Pos.x = matWorld._41 ;	vec3Pos.y = matWorld._42 + m_fRadius ;	vec3Pos.z = matWorld._43 ;

	D3DXMatrixTranslation(&matTrans, -vec3Pos.x, -vec3Pos.y, -vec3Pos.z) ;
	D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans) ;
	D3DXMatrixRotationZ(&matTrans, fUnits) ;
	D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans) ;

	D3DXMatrixTranslation(&matTrans, vec3Pos.x, vec3Pos.y, vec3Pos.z) ;
	D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans) ;
	m_TheWorld.SetWorld(&matWorld) ;

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