载入Device1的时候没问题,但载入Device2的时候无法显示。请问该如何解决啊!最好给一段代码,分别载入两个不同的.x物体,同时显示!!让两个小物体分别自己旋转,并且同时可以让整个世界的视角也可以调整,请问改如何解决!谢谢!!

解决方案 »

  1.   


    VOID SetupMatrices()
    {
        // Set up world matrix
      /*  D3DXMATRIXA16 matWorld;
        D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f );
        g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );*/ D3DXMATRIXA16 matWorld;
    D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f );
     D3DXMATRIX   mat2;  
      D3DXMATRIX   curMatrix;
    D3DXMatrixTranslation(&mat2,0.1,0,0);
    D3DXMatrixMultiply(&curMatrix,&matWorld,&mat2);   
    g_pd3dDevice->SetTransform( D3DTS_WORLD, &curMatrix );    // Set up our view matrix. A view matrix can be defined given an eye point,
        // a point to lookat, and a direction for which way is up. Here, we set the
        // eye five units back along the z-axis and up three units, look at the 
        // origin, and define "up" to be in the y-direction.
        D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );
        D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
        D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
        D3DXMATRIXA16 matView;
        D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
        g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );    // For the projection matrix, we set up a perspective transform (which
        // transforms geometry from 3D view space to 2D viewport space, with
        // a perspective divide making objects smaller in the distance). To build
        // a perpsective transform, we need the field of view (1/4 pi is common),
        // the aspect ratio, and the near and far clipping planes (which define at
        // what distances geometry should be no longer be rendered).
        D3DXMATRIXA16 matProj;
        D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
        g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
    }VOID SetupMatrices1()
    {
        // Set up world matrix
      /*  D3DXMATRIXA16 matWorld;
        D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f );
        g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );*/ D3DXMATRIXA16 matWorld;
    D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f );
     D3DXMATRIX   mat2;  
      D3DXMATRIX   curMatrix;
    D3DXMatrixTranslation(&mat2,1.5,0,0);
    D3DXMatrixMultiply(&curMatrix,&matWorld,&mat2);   
    g_pd3dDevice->SetTransform( D3DTS_WORLD, &curMatrix );    // Set up our view matrix. A view matrix can be defined given an eye point,
        // a point to lookat, and a direction for which way is up. Here, we set the
        // eye five units back along the z-axis and up three units, look at the 
        // origin, and define "up" to be in the y-direction.
        D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );
        D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
        D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
        D3DXMATRIXA16 matView;
        D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
        g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );    // For the projection matrix, we set up a perspective transform (which
        // transforms geometry from 3D view space to 2D viewport space, with
        // a perspective divide making objects smaller in the distance). To build
        // a perpsective transform, we need the field of view (1/4 pi is common),
        // the aspect ratio, and the near and far clipping planes (which define at
        // what distances geometry should be no longer be rendered).
        D3DXMATRIXA16 matProj;
        D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
        g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
    }
    //-----------------------------------------------------------------------------
    // Name: Render()
    // Desc: Draws the scene
    //-----------------------------------------------------------------------------
    VOID Render()
    {
    //::MessageBox(NULL,"jfkldsf","jkldfsj",1);
        // Clear the backbuffer and the zbuffer
        g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
                             D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
        
    g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
    g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1,D3DTA_TEXTURE);
    g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTA_TEXTURE);
    g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); g_pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
    g_pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR , false);
    //g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, 0xff0000ff);     // Begin the scene
        if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
        {
            // Setup the world, view, and projection matrices
            SetupMatrices();        // Meshes are divided into subsets, one for each material. Render them in
            // a loop
            for( DWORD i=0; i<g_dwNumMaterials; i++ )
            {
                // Set the material and texture for this subset
                g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
                g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
            
                // Draw the mesh subset
                g_pMesh->DrawSubset( i );
            } SetupMatrices1();
     for( DWORD i=0; i<g_dwNumMaterials; i++ )
            {
                // Set the material and texture for this subset
                g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
                g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
            
                // Draw the mesh subset
                g_pMesh->DrawSubset( i );
            }        // End the scene
            g_pd3dDevice->EndScene();
        }
      
        g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
    }我是根据directx下面的例子改的,现在两只并排着的老虎都在转,只要是用了D3DXMatrixTranslation来实现平移
    其实你没必要像我这样,你只要设两个不同的curMatrix就好了 
      

  2.   

    如果你要显示不同的物体,只要改下g_pMeshMaterials,g_pMeshTextures就好了