2010-12-06 47 views
1

我有兩個網格。其中一個是動畫,另一個不是動畫。當我渲染它們時,無生命的網格以與動畫網格動畫相同的方式獲得動畫。
所以,讓動畫網格走到左邊比回來,我無生命的網格做同樣的事情!
這是我的無生命網格的代碼類。
主類C++網格變得動畫時,他們不是也假設

class StaticMesh 
{ 
public: 
    StaticMesh(LPDIRECT3DDEVICE9* device); 
    ~StaticMesh(void); 
    void Render(void); 
    void Load(LPCWSTR fileName); 
    void CleanUp(void); 
private: 
    LPDIRECT3DDEVICE9* d3ddev;      // the pointer to the device class 
    LPD3DXMESH mesh; // define the mesh pointer 
    D3DMATERIAL9* material; // define the material object 
    DWORD numMaterials; // stores the number of materials in the mesh 
    LPDIRECT3DTEXTURE9* texture; // a pointer to a texture 
    LPD3DXBUFFER bufMeshMaterial; 
}; 

#include "StdAfx.h" 
#include "StaticMesh.h" 


StaticMesh::StaticMesh(LPDIRECT3DDEVICE9* device) 
{ 
    d3ddev=device; 
} 


StaticMesh::~StaticMesh(void) 
{ 
} 

void StaticMesh::Render(void) 
{ 
    LPDIRECT3DDEVICE9 device=*d3ddev; 
    for(DWORD i = 0; i < numMaterials; i++) // loop through each subset 
    { 
     device->SetMaterial(&material[i]); // set the material for the subset 
     device->SetTexture(0, texture[i]); // ...then set the texture 

     mesh->DrawSubset(i); // draw the subset 
    } 
} 

void StaticMesh::Load(LPCWSTR fileName) 
{ 
    LPDIRECT3DDEVICE9 device=*d3ddev; 

    D3DXLoadMeshFromX(fileName, // load this file 
         D3DXMESH_SYSTEMMEM, // load the mesh into system memory 
         device, // the Direct3D Device 
         NULL, // we aren't using adjacency 
         &bufMeshMaterial, // put the materials here 
         NULL, // we aren't using effect instances 
         &numMaterials, // the number of materials in this model 
         &mesh); // put the mesh here 

    // retrieve the pointer to the buffer containing the material information 
    D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMeshMaterial->GetBufferPointer(); 

    // create a new material buffer and texture for each material in the mesh 
    material = new D3DMATERIAL9[numMaterials]; 
    texture = new LPDIRECT3DTEXTURE9[numMaterials]; 

    for(DWORD i = 0; i < numMaterials; i++) // for each material... 
    { 
     // Copy the material 
     material[i] = tempMaterials[i].MatD3D; 

     // Set the ambient color for the material (D3DX does not do this) 
     material[i].Ambient = material[i].Diffuse; 

     // Create the texture if it exists - it may not 
     texture[i] = NULL; 
     if (tempMaterials[i].pTextureFilename) 
     { 
      D3DXCreateTextureFromFileA(device, tempMaterials[i].pTextureFilename,&texture[i]); 
     } 
    } 
} 

void StaticMesh::CleanUp(void) 
{ 
    mesh->Release(); 
} 
+1

我有一種感覺你的問題存在您提供的類之外。您可以包含您在StaticMesh對象上執行哪些操作的示例嗎? – MrGomez 2010-12-06 00:34:37

回答

0

的anination來自一個轉換矩陣。 您將其直接傳遞給設備(如果使用固定功能)或着色器/效果。 在矩陣設置後繪製的所有網格都將經歷相同的變換。 所以,如果你想讓一個網格保持無生命,你必須在繪製網格之前改變變換。

僞代碼:

SetTransform(world* view * projection); 
DrawMesh(); 
SetTransform(identity * view * projection); 
DrawMesh(); 
相關問題