我有两个网格。其中一个是动画的,另一个没有动画。当我渲染它们时,无生命网格的动画效果与动画网格动画的方式相同 所以,让动画网格向左移动而不是返回,我的无生命网格做同样的事情! 这是无生命网格的代码类 主要课程
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();
}
答案 0 :(得分:0)
anination来自转换矩阵。 您可以将其直接传递给设备(如果使用固定功能)或着色器/效果。 在设置矩阵后绘制的所有网格都将经历相同的变换。 因此,如果您希望一个网格保持无生命,则必须在绘制网格之前更改变换。
的伪代码:
SetTransform( world* view * projection );
DrawMesh();
SetTransform( identity * view * projection );
DrawMesh();