Sign in to follow this  
Thr3ad

Textured Mesh Rotation Problems

Recommended Posts

I have managed to load a mess and its texture which i created in 3dStudio Max and got it to display on screen. So I have now gone onto trying to get it to rotate around its 'Y' axis. I have managed to do this a bit but it rotates around the center of the right hand side, and when it gets so far round it shrinks and then disapears to come back a bit further into the rotation. This is what i am using and the code is crude but i am only learning right now.
D3DXMATRIX matView;
    D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( 0.0f, 3.0f,-100.0f ),
					//	&D3DXVECTOR3( 0.0f, -3.0f, 100.0f ),
						&D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
						&D3DXVECTOR3( 0.0f, 3.0f, 0.0f ) );
    pD3DDevice->SetTransform( D3DTS_VIEW, &matView );

    D3DXMATRIX matProj;
  //  D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/2, 1.0f, 1.0f, 100.0f );
	
	D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 55.0f ), 800.0f / 600.0f,
		                        1.0f, 100.0f );

    pD3DDevice->SetTransform( D3DTS_PROJECTION, &matProj );

    D3DXMATRIX matWorld;
    D3DXMatrixRotationY( &matWorld, GetTickCount()/1000.0f );
    pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld );

    for( DWORD i=0; i<m_dwNumMaterials; i++ )
    {
        // Set the material and texture for this subset
        pD3DDevice->SetMaterial( &pMeshMaterials[i] );
        pD3DDevice->SetTexture( 0, pMeshTextures[i] );

        // Draw the mesh subset
        pSysMemMesh->DrawSubset(i);
    }
is there a better and cleaner way to do this? Thanks for looking.

Share this post


Link to post
Share on other sites
Quote:

I have managed to do this a bit but it rotates around the center of the right hand side


Most probably your model wasn't situated at position 0,0,0 in 3DS Max when you exported it. Make sure it's in the center of the 'square grid' whet you export it.

Quote:

and when it gets so far round it shrinks and then disapears to come back a bit further into the rotation.


I guess it disappears because it gets out of your FOV.
try transforming this line:

D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/2, 1.0f, 1.0f, 100.0f );

into this

D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/2, 1.0f, 1.0f, 1000.0f );

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