【问题标题】:C++ Meshes getting animated when they are not suppose tooC++ 网格在不应该的情况下获得动画
【发布时间】:2010-12-06 00:17:21
【问题描述】:

我有两个网格。其中一个是动画的,另一个不是动画的。当我渲染它们时,无生命的网格会以与动画网格相同的方式进行动画处理。
所以,让动画网格向左走而不是回来,我的无生命网格做同样的事情!
这是我的无生命网格的代码类。
主类

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();
}

【问题讨论】:

  • 我感觉您的问题存在于您提供的课程之外。您能否提供一个示例,说明您对 StaticMesh 对象执行的操作?

标签: c++ winapi visual-c++ directx


【解决方案1】:

anination 来自转换矩阵。 您可以将其直接传递给设备(如果使用固定功能)或传递给着色器/效果。 设置矩阵后绘制的所有网格都将经历相同的变换。 所以,如果你想让一个网格保持静止,你必须在绘制网格之前更改变换。

伪代码:

SetTransform( world* view * projection );
DrawMesh();
SetTransform( identity * view * projection );
DrawMesh();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 2019-01-31
    • 2012-10-06
    • 2018-08-24
    • 2022-01-16
    • 2019-01-22
    • 2022-01-05
    相关资源
    最近更新 更多