gpt4 book ai didi

C++ 网格在不应该的时候变得动画化

转载 作者:太空宇宙 更新时间:2023-11-04 14:25:24 24 4
gpt4 key购买 nike

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

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

最佳答案

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

伪代码:

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

关于C++ 网格在不应该的时候变得动画化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4362186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com