我正在尝试在DirectX 10中创建一只飞虎。我已装入虎和翼网,但我想让翅膀翻动。在这一点上,我只是想让翅膀移动,而不是老虎本身。我是DirectX的新手,我正在学习它作为一种爱好,所以我不确定从哪里开始。
这是我的代码:
void CALLBACK OnD3D10FrameRender(ID3D10Device* pd3dDevice, double fTime,
float fElapsedTime, void* pUserContext)
{
//
// Clear the back buffer
//
float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; // red, green, blue,
alpha
ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
pd3dDevice->ClearRenderTargetView(pRTV, ClearColor);
//
// Clear the depth stencil
//
ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
pd3dDevice->ClearDepthStencilView(pDSV, D3D10_CLEAR_DEPTH, 1.0, 0);
//
// Update variables that change once per frame
//
g_pWorldVariable->SetMatrix((float*)&g_World);
//
// Set the Vertex Layout
//
pd3dDevice->IASetInputLayout(g_pVertexLayout);
//
// Render the mesh
//
UINT Strides[1];
UINT Offsets[1];
ID3D10Buffer* pVB[1];
pVB[0] = g_Mesh.GetVB10(0, 0);
Strides[0] = (UINT)g_Mesh.GetVertexStride(0, 0);
Offsets[0] = 0;
pd3dDevice->IASetVertexBuffers(0, 1, pVB, Strides, Offsets);
pd3dDevice->IASetIndexBuffer(g_Mesh.GetIB10(0), g_Mesh.GetIBFormat10(0),
0);
D3D10_TECHNIQUE_DESC techDesc;
g_pTechnique->GetDesc(&techDesc);
SDKMESH_SUBSET* pSubset = NULL;
ID3D10ShaderResourceView* pDiffuseRV = NULL;
D3D10_PRIMITIVE_TOPOLOGY PrimType;
for (UINT p = 0; p < techDesc.Passes; ++p)
{
for (UINT subset = 0; subset < g_Mesh.GetNumSubsets(0); ++subset)
{
pSubset = g_Mesh.GetSubset(0, subset);
PrimType =
g_Mesh.GetPrimitiveType10((SDKMESH_PRIMITIVE_TYPE)pSubset-
>PrimitiveType);
pd3dDevice->IASetPrimitiveTopology(PrimType);
pDiffuseRV = g_Mesh.GetMaterial(pSubset->MaterialID)->pDiffuseRV10;
g_ptxDiffuseVariable->SetResource(pDiffuseRV);
g_pTechnique->GetPassByIndex(p)->Apply(0);
pd3dDevice->DrawIndexed((UINT)pSubset->IndexCount, 0, (UINT)pSubset-
>VertexStart);
}
}
// Render mesh2
pVB[0] = g_Mesh2.GetVB10(0, 0);
Strides[0] = (UINT)g_Mesh2.GetVertexStride(0, 0);
Offsets[0] = 0;
pd3dDevice->IASetVertexBuffers(0, 1, pVB, Strides, Offsets);
pd3dDevice->IASetIndexBuffer(g_Mesh2.GetIB10(0), g_Mesh2.GetIBFormat10(0),
0);
g_pTechnique->GetDesc(&techDesc);
for (UINT p = 0; p < techDesc.Passes; ++p)
{
for (UINT subset = 0; subset < g_Mesh2.GetNumSubsets(0); ++subset)
{
pSubset = g_Mesh2.GetSubset(0, subset);
PrimType =
g_Mesh2.GetPrimitiveType10((SDKMESH_PRIMITIVE_TYPE)pSubset-
>PrimitiveType);
pd3dDevice->IASetPrimitiveTopology(PrimType);
pDiffuseRV = g_Mesh2.GetMaterial(pSubset->MaterialID)->pDiffuseRV10;
g_ptxDiffuseVariable->SetResource(pDiffuseRV);
g_pTechnique->GetPassByIndex(p)->Apply(0);
pd3dDevice->DrawIndexed((UINT)pSubset->IndexCount, 0, (UINT)pSubset-
>VertexStart);
}
}
// Render Mesh3
pVB[0] = g_Mesh3.GetVB10(0, 0);
Strides[0] = (UINT)g_Mesh3.GetVertexStride(0, 0);
Offsets[0] = 0;
pd3dDevice->IASetVertexBuffers(0, 1, pVB, Strides, Offsets);
pd3dDevice->IASetIndexBuffer(g_Mesh3.GetIB10(0), g_Mesh3.GetIBFormat10(0),
0);
g_pTechnique->GetDesc(&techDesc);
for (UINT p = 0; p < techDesc.Passes; ++p)
{
for (UINT subset = 0; subset < g_Mesh3.GetNumSubsets(0); ++subset)
{
pSubset = g_Mesh3.GetSubset(0, subset);
PrimType =
g_Mesh3.GetPrimitiveType10((SDKMESH_PRIMITIVE_TYPE)pSubset-
>PrimitiveType);
pd3dDevice->IASetPrimitiveTopology(PrimType);
pDiffuseRV = g_Mesh3.GetMaterial(pSubset->MaterialID)->pDiffuseRV10;
g_ptxDiffuseVariable->SetResource(pDiffuseRV);
g_pTechnique->GetPassByIndex(p)->Apply(0);
pd3dDevice->DrawIndexed((UINT)pSubset->IndexCount, 0, (UINT)pSubset-
>VertexStart);
}
}
//the mesh class also had a render method that allows rendering the mesh
with the most common options
//g_Mesh.Render( pd3dDevice, g_pTechnique, g_ptxDiffuseVariable );
}
void CALLBACK OnD3D10ReleasingSwapChain(void* pUserContext)
{
}
void CALLBACK OnD3D10DestroyDevice(void* pUserContext)
{
DXUTGetGlobalResourceCache().OnDestroyDevice();
SAFE_RELEASE(g_pVertexLayout);
SAFE_RELEASE(g_pEffect);
g_Mesh.Destroy();
g_Mesh2.Destroy();
g_Mesh3.Destroy();
}
bool CALLBACK ModifyDeviceSettings(DXUTDeviceSettings* pDeviceSettings,
void* pUserContext)
{
return true;
}
void CALLBACK OnFrameMove(double fTime, float fElapsedTime, void*
pUserContext)
{
// Rotate cube around the origin
D3DXMatrixRotationY(&g_World, 60.0f * DEG2RAD((float)fTime));
}
LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
lParam,
bool* pbNoFurtherProcessing,
void* pUserContext)
{
return 0;
}
void CALLBACK OnKeyboard(UINT nChar, bool bKeyDown, bool bAltDown, void*
pUserContext)
{
if (bKeyDown)
{
switch (nChar)
{
case VK_F1: // Change as needed
break;
}
}
}