C语言编写小球在桌面上做圆周运动
1个回答
2013-12-14
展开全部
这源代码应该有个桌面类(Table),球类(Sphere),游戏类等等。我用C++
#pragma once (Table.h)
#endif // _MSC_VER > 1000
#include "Base.h"
#define MESH_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
class CTable:public CBase
{
public:
DWORD Render();
CTable(LPDIRECT3DDEVICE8 pD3DDevice,LPSTR pFilename);
virtual ~CTable();
LPD3DXMESH GetMeshTablePointer();
private:
void TransformTable();
LPDIRECT3DDEVICE8 m_pD3DDevice;
DWORD m_dwNumMaterials;
LPD3DXMESH m_pMeshTable;
D3DMATERIAL8 *m_pMeshTableMaterials;
LPDIRECT3DTEXTURE8 *m_pMeshTableTextures;
};#endif
#include "Table.h" (Table.cpp)
CTable::CTable(LPDIRECT3DDEVICE8 pD3DDevice,LPSTR pFilename)
{
LPD3DXBUFFER pMaterialsBuffer=NULL;
LPD3DXMESH pMeshTable=NULL;
m_pD3DDevice=pD3DDevice;
if(FAILED(D3DXLoadMeshFromX(pFilename,D3DXMESH_MANAGED,m_pD3DDevice,NULL,
&pMaterialsBuffer,&m_dwNumMaterials,&pMeshTable)))
{
m_pMeshTable=NULL;
m_pMeshTableMaterials=NULL;
m_pMeshTableTextures=NULL;
LogError("<li>Table Mesh '%s' failed to load",pFilename);
return;
}
D3DXMATERIAL *matMaterials=(D3DXMATERIAL*)pMaterialsBuffer->GetBufferPointer();
//Create two arrays. One to hold the materials and one to hold the textures
m_pMeshTableMaterials=new D3DMATERIAL8[m_dwNumMaterials];
m_pMeshTableTextures=new LPDIRECT3DTEXTURE8[m_dwNumMaterials];
for(DWORD i=0;i<m_dwNumMaterials;i++)
{
//Copy the material
m_pMeshTableMaterials[i]=matMaterials[i].MatD3D;
//Set the ambient color for the material(D3DX does not do this)
m_pMeshTableMaterials[i].Ambient=m_pMeshTableMaterials[i].Diffuse;
D3DCOLORVALUE rgbaSpecular=;
m_pMeshTableMaterials[i].Specular=rgbaSpecular;
m_pMeshTableMaterials[i].Power=50.0f
#pragma once (Table.h)
#endif // _MSC_VER > 1000
#include "Base.h"
#define MESH_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
class CTable:public CBase
{
public:
DWORD Render();
CTable(LPDIRECT3DDEVICE8 pD3DDevice,LPSTR pFilename);
virtual ~CTable();
LPD3DXMESH GetMeshTablePointer();
private:
void TransformTable();
LPDIRECT3DDEVICE8 m_pD3DDevice;
DWORD m_dwNumMaterials;
LPD3DXMESH m_pMeshTable;
D3DMATERIAL8 *m_pMeshTableMaterials;
LPDIRECT3DTEXTURE8 *m_pMeshTableTextures;
};#endif
#include "Table.h" (Table.cpp)
CTable::CTable(LPDIRECT3DDEVICE8 pD3DDevice,LPSTR pFilename)
{
LPD3DXBUFFER pMaterialsBuffer=NULL;
LPD3DXMESH pMeshTable=NULL;
m_pD3DDevice=pD3DDevice;
if(FAILED(D3DXLoadMeshFromX(pFilename,D3DXMESH_MANAGED,m_pD3DDevice,NULL,
&pMaterialsBuffer,&m_dwNumMaterials,&pMeshTable)))
{
m_pMeshTable=NULL;
m_pMeshTableMaterials=NULL;
m_pMeshTableTextures=NULL;
LogError("<li>Table Mesh '%s' failed to load",pFilename);
return;
}
D3DXMATERIAL *matMaterials=(D3DXMATERIAL*)pMaterialsBuffer->GetBufferPointer();
//Create two arrays. One to hold the materials and one to hold the textures
m_pMeshTableMaterials=new D3DMATERIAL8[m_dwNumMaterials];
m_pMeshTableTextures=new LPDIRECT3DTEXTURE8[m_dwNumMaterials];
for(DWORD i=0;i<m_dwNumMaterials;i++)
{
//Copy the material
m_pMeshTableMaterials[i]=matMaterials[i].MatD3D;
//Set the ambient color for the material(D3DX does not do this)
m_pMeshTableMaterials[i].Ambient=m_pMeshTableMaterials[i].Diffuse;
D3DCOLORVALUE rgbaSpecular=;
m_pMeshTableMaterials[i].Specular=rgbaSpecular;
m_pMeshTableMaterials[i].Power=50.0f
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询