本文整理汇总了C++中LPD3DXMESH类的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXMESH类的具体用法?C++ LPD3DXMESH怎么用?C++ LPD3DXMESH使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LPD3DXMESH类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderMesh
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
int RenderMesh(LPD3DXMESH mesh,D3DMATERIAL9* pMeshMaterials,LPDIRECT3DTEXTURE9* pMeshTextures,DWORD dwNumMaterials,D3DXMATRIXA16* pMatWorld)
{
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 );
// 开始渲染 scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
SetupMatrices();
for( DWORD i = 0; i < dwNumMaterials; i++ )
{
//执行变换矩阵
g_pd3dDevice->SetTransform( D3DTS_WORLD, pMatWorld );
g_pd3dDevice->SetMaterial( &pMeshMaterials[i] );
g_pd3dDevice->SetTexture( 0, pMeshTextures[i] );
mesh->DrawSubset( i );
}
// End the scene
g_pd3dDevice->EndScene();
}
// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
return 1;
}
示例2: LoadMesh
HRESULT KModelWater::LoadMesh(LPSTR pFileName)
{
HRESULT hr = S_OK;
m_dwNumPoly_X = 63; //长方形网格的长,网格数
m_dwNumPoly_Z = 63; //长方形网格的宽,网格数
LPD3DXMESH pMesh = m_pWaterUp;
LPD3DXMESH pDMesh = m_pWaterDn;
DWORD m_dNumPloy = m_dwNumPoly_X * m_dwNumPoly_Z;
DWORD m_dNumFaces = m_dNumPloy * 2;
DWORD m_dNumVertices = (m_dwNumPoly_X+1)*(m_dwNumPoly_Z+1);
SAFE_RELEASE(pMesh);
SAFE_RELEASE(pDMesh);
WORD *pwIndices;
//建立水面网格
if(FAILED(hr = g_pd3dDevice->CreateIndexBuffer(m_dNumFaces * 3 * sizeof(WORD), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_pibIndices, NULL)))
{
return hr;
}
if (FAILED(hr = D3DXCreateMeshFVF(m_dNumFaces,m_dNumVertices,D3DXMESH_MANAGED|D3DXMESH_32BIT,
D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_NORMAL|D3DFVF_TEX1,g_pd3dDevice,&pMesh)))
{
return hr;
}
if (FAILED(hr = D3DXCreateMeshFVF(m_dNumFaces,m_dNumVertices,D3DXMESH_MANAGED|D3DXMESH_32BIT,
D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_NORMAL|D3DFVF_TEX1,g_pd3dDevice,&pDMesh)))
{
return hr;
}
VFormat::FACES_NORMAL_TEXTURE1 * pVers = NULL;
DWORD* pIndex = NULL;
DWORD * pAttrib = NULL;
VFormat::FACES_NORMAL_TEXTURE1 * pDVers = NULL;
DWORD* pDIndex = NULL;
DWORD * pDAttrib = NULL;
if(FAILED(hr = m_pibIndices->Lock(0, m_dNumFaces *3 * sizeof(WORD), (void**) &pwIndices, D3DLOCK_DISCARD)))
return E_FAIL;
if (FAILED(pMesh->LockVertexBuffer(0,(void**)&pVers)))
return E_FAIL;
if (FAILED(pMesh->LockIndexBuffer (0,(void**)&pIndex)))
return E_FAIL;
if (FAILED(pMesh->LockAttributeBuffer(0,(DWORD**)&pAttrib)))
return E_FAIL;
if (FAILED(pDMesh->LockVertexBuffer(0,(void**)&pDVers)))
return E_FAIL;
if (FAILED(pDMesh->LockIndexBuffer (0,(void**)&pDIndex)))
return E_FAIL;
if (FAILED(pDMesh->LockAttributeBuffer(0,(DWORD**)&pDAttrib)))
return E_FAIL;
DWORD i = 0;
float _X = 1.0f/m_dwNumPoly_X;
float _Z = 1.0f/m_dwNumPoly_Z;
float m_fPolyWidth = 200;
float m_fPolyHeight = 200;
for(DWORD X =0;X<=m_dwNumPoly_X;X++)
{
for(DWORD Y =0;Y<=m_dwNumPoly_Z;Y++)
{
float PX = X * m_fPolyWidth;
float PZ = Y * m_fPolyHeight;
D3DXVECTOR2 Pos(PX,PZ);
pVers[i].p = D3DXVECTOR3(PX,200,PZ);
pVers[i].Normal = D3DXVECTOR3(0,1,0);
pVers[i].tu1 = (X * _X);
pVers[i].tv1 = (1 - Y *_Z);
pDVers[i].p = D3DXVECTOR3(PX,0,PZ);
pDVers[i].Normal = D3DXVECTOR3(0,1,0);
pDVers[i].tu1 = (X * _X);
pDVers[i].tv1 = (1 - Y *_Z);
i++;
}
}
DWORD Weight = m_dwNumPoly_X + 1;
for(X =0;X<m_dwNumPoly_X;X++)
{
for(DWORD Y =0;Y<m_dwNumPoly_Z;Y++)
{
DWORD PloyIndex = Y*m_dwNumPoly_X +X;
//.........这里部分代码省略.........
示例3: CreateMeshContainer
//-----------------------------------------------------------------------------
// Desc: 在这里是调用了成员函数 GenerateGameSkinMesh(pMeshContainer);
// 是在这里加载了蒙皮信息
//-----------------------------------------------------------------------------
HRESULT DexAllocateHierarchy::CreateMeshContainer(LPCSTR Name,
CONST D3DXMESHDATA *pMeshData,
CONST D3DXMATERIAL *pMaterials,
CONST D3DXEFFECTINSTANCE *pEffectInstances,
DWORD NumMaterials,
CONST DWORD *pAdjacency,
LPD3DXSKININFO pSkinInfo,
LPD3DXMESHCONTAINER *ppNewMeshContainer)
{
HRESULT hr;
stDexMeshContainerEx *pMeshContainer = NULL;
LPDIRECT3DDEVICE9 device = NULL;
UINT NumFaces;
UINT iMaterial;
UINT iBone, cBones;
LPD3DXMESH pMesh = NULL;
*ppNewMeshContainer = NULL;
// this sample does not handle patch meshes, so fail when one is found
if (pMeshData->Type != D3DXMESHTYPE_MESH)
{
hr = E_FAIL;
return hr;
}
// get the pMesh interface pointer out of the mesh data structure
pMesh = pMeshData->pMesh;
pMesh->GetDevice( &device );
// this sample does not FVF compatible meshes, so fail when one is found
if (pMesh->GetFVF() == 0)
{
hr = E_FAIL;
return hr;
}
// allocate the overloaded structure to return as a D3DXMESHCONTAINER
pMeshContainer = new stDexMeshContainerEx;
if (pMeshContainer == NULL)
{
hr = E_OUTOFMEMORY;
return hr;
}
memset(pMeshContainer, 0, sizeof(stDexMeshContainerEx));
// make sure and copy the name. All memory as input belongs to caller, interfaces can be addref'd though
hr = AllocateName(Name, &pMeshContainer->Name);
if (FAILED(hr))
{
if (pMeshContainer != NULL)
{
DestroyMeshContainer(pMeshContainer);
}
return hr;
}
NumFaces = pMesh->GetNumFaces();
// if no normals are in the mesh, add them
if (!(pMesh->GetFVF() & D3DFVF_NORMAL))
{
pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;
// clone the mesh to make room for the normals
hr = pMesh->CloneMeshFVF( pMesh->GetOptions(),
pMesh->GetFVF() | D3DFVF_NORMAL,
device, &pMeshContainer->MeshData.pMesh );
if (FAILED(hr))
{
if (pMeshContainer != NULL)
{
DestroyMeshContainer(pMeshContainer);
}
return hr;
}
// get the new pMesh pointer back out of the mesh container to use
// NOTE: we do not release pMesh because we do not have a reference to it yet
pMesh = pMeshContainer->MeshData.pMesh;
// now generate the normals for the pmesh
D3DXComputeNormals( pMesh, NULL );
}
else // if no normals, just add a reference to the mesh for the mesh container
{
pMeshContainer->MeshData.pMesh = pMesh;
pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;
pMesh->AddRef();
}
// allocate memory to contain the material information. This sample uses
// the D3D9 materials and texture names instead of the EffectInstance style materials
pMeshContainer->NumMaterials = max(1, NumMaterials);
//.........这里部分代码省略.........
示例4: timeGetTime
HRESULT KG3DMesh::CreateBspFile()
{
HRESULT hrResult = E_FAIL;
HRESULT hrRetCode = E_FAIL;
int nRetCode = false;
TCHAR szBSPPathName[MAX_PATH];
void *pvVerticesBuffer = NULL;
WORD* pIndexBuffer = NULL;
D3DXVECTOR3 *pPos = NULL;
DWORD *pdwFaceIndex = NULL;
DWORD dwStride = 0;
DWORD i = 0;
DWORD dwNumFaces = 0;
DWORD dwNumVertices = 0;
DWORD dwStartTime = timeGetTime();
LPD3DXMESH piMesh = m_ppMeshes[SMBT_NORMAL];
KG3DBsp *pBSP = NULL;
KGLOG_PROCESS_ERROR(piMesh);
dwStride = piMesh->GetNumBytesPerVertex();
dwNumVertices = piMesh->GetNumVertices();
dwNumFaces = piMesh->GetNumFaces();
KG_PROCESS_SUCCESS(dwNumFaces < 256);
pPos = new D3DXVECTOR3[dwNumVertices];
KG_ASSERT_EXIT(pPos);
pdwFaceIndex = new DWORD[dwNumFaces * 3];
KG_ASSERT_EXIT(pdwFaceIndex);
hrRetCode = piMesh->LockVertexBuffer(D3DLOCK_READONLY, (void **)&pvVerticesBuffer);
KGLOG_COM_PROCESS_ERROR(hrRetCode);
hrRetCode = piMesh->LockIndexBuffer(D3DLOCK_READONLY, (void **)&pIndexBuffer);
KGLOG_COM_PROCESS_ERROR(hrRetCode);
for (i = 0; i < dwNumVertices; ++i)
{
pPos[i] = *(D3DXVECTOR3 *)(((BYTE *)pvVerticesBuffer) + dwStride * i);
}
for (i = 0; i < dwNumFaces * 3; ++i)
{
pdwFaceIndex[i] = pIndexBuffer[i];
}
// -------------------------- create BSP --------------------------
hrRetCode = ChangePathExtName(m_scName.c_str(), "bsp", sizeof(szBSPPathName), szBSPPathName);
KGLOG_COM_PROCESS_ERROR(hrRetCode);
pBSP = new KG3DBsp;
KGLOG_PROCESS_ERROR(pBSP);
hrRetCode = pBSP->CreateFromMesh(dwNumVertices, dwNumFaces, pPos, pdwFaceIndex);
KGLOG_COM_PROCESS_ERROR(hrRetCode);
hrRetCode = pBSP->SaveToFile(szBSPPathName);
KGLOG_COM_PROCESS_ERROR(hrRetCode);
DWORD dwCost = timeGetTime() - dwStartTime;
if(dwCost > 500)
{
KGLogPrintf(
KGLOG_WARNING, "BSP %d %d Face %s",
dwCost, dwNumFaces, szBSPPathName
);
}
KG_DELETE(m_lpBsp); // recreate
m_lpBsp = pBSP;
pBSP = NULL;
Exit1:
hrResult = S_OK;
Exit0:
KG_DELETE(pBSP);
if (pIndexBuffer)
{
piMesh->UnlockIndexBuffer();
pIndexBuffer = NULL;
}
if (pvVerticesBuffer)
{
piMesh->UnlockVertexBuffer();
pvVerticesBuffer = NULL;
}
KG_DELETE_ARRAY(pdwFaceIndex);
KG_DELETE_ARRAY(pPos);
if(FAILED(hrResult))
{
KGLogPrintf(KGLOG_ERR, "%s 创建失败", szBSPPathName);
}
return hrResult;
}
示例5: CreateBox
void CreateBox( const float &w, const float &h, const float &d, const bool ¢erWidth, const bool ¢erHeight, const bool ¢erDepth, LPD3DXMESH &mesh )
{
float offsetX = 0, offsetY = 0, offsetZ = 0;
if( centerWidth )
offsetX = -w / 2.f;
if( centerHeight )
offsetY = -h / 2.f;
if( centerDepth )
offsetZ = -d / 2.f;
std::vector<DWORD> vIB;
std::vector<VERTEX3> vVB;
std::vector<DWORD> vAB;
DWORD offset = 0;
// fill in the front face index data
vIB.push_back( 0 + offset );
vIB.push_back( 1 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 0 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 3 + offset );
// fill in the front face vertex data
vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, 0.f + offsetZ, 0.f, 0.f, -1.f, 0.f, 1.f ) );
vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, 0.f + offsetZ, 0.f, 0.f, -1.f, 0.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, h + offsetY, 0.f + offsetZ, 0.f, 0.f, -1.f, 1.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, 0.f + offsetZ, 0.f, 0.f, -1.f, 1.f, 1.f ) );
vAB.push_back( 0 );
vAB.push_back( 0 );
offset += 4;
// fill in the back face index data
vIB.push_back( 0 + offset );
vIB.push_back( 1 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 0 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 3 + offset );
// fill in the back face vertex data
vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, d + offsetZ, 0.f, 0.f, 1.f, 1.f, 1.f ) );
vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, d + offsetZ, 0.f, 0.f, 1.f, 0.f, 1.f ) );
vVB.push_back( VERTEX3( w + offsetX, h + offsetY, d + offsetZ, 0.f, 0.f, 1.f, 0.f, 0.f ) );
vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, d + offsetZ, 0.f, 0.f, 1.f, 1.f, 0.f ) );
vAB.push_back( 1 );
vAB.push_back( 1 );
offset += 4;
// fill in the top face index data
vIB.push_back( 0 + offset );
vIB.push_back( 1 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 0 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 3 + offset );
//fill in the top face vertex data
vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, 0.f + offsetZ, 0.f, 1.f, 0.f, 0.f, 1.f ) );
vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, d + offsetZ, 0.f, 1.f, 0.f, 0.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, h + offsetY, d + offsetZ, 0.f, 1.f, 0.f, 1.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, h + offsetY, 0.f + offsetZ, 0.f, 1.f, 0.f, 1.f, 1.f ) );
vAB.push_back( 2 );
vAB.push_back( 2 );
offset += 4;
// fill in the bottom face index data
vIB.push_back( 0 + offset );
vIB.push_back( 1 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 0 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 3 + offset );
// fill in the bottom face vertex data
vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, 0.f + offsetZ, 0.f, -1.f, 0.f, 0.f, 1.f ) );
vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, 0.f + offsetZ, 0.f, -1.f, 0.f, 0.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, d + offsetZ, 0.f, -1.f, 0.f, 1.f, 0.f ) );
vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, d + offsetZ, 0.f, -1.f, 0.f, 1.f, 1.f ) );
vAB.push_back( 3 );
vAB.push_back( 3 );
offset += 4;
// fill in the left face index data
vIB.push_back( 0 + offset );
vIB.push_back( 1 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 0 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 3 + offset );
// fill in the left face vertex data
//.........这里部分代码省略.........
示例6:
//メッシュコンテナ描画
void Dx_Graphics3D::DrawMeshContainer(LPD3DXMESHCONTAINER pMeshContainer, LPD3DXFRAME pFrame)
{
DxMeshContainer *mesh_container = (DxMeshContainer*)pMeshContainer;
DxFrame *frame = (DxFrame*)pFrame;
//
D3DMATERIAL9 mat;
LPDIRECT3DTEXTURE9 pTex=NULL;
//D3DXMESHDATA内のメッシュデータを抽出
LPD3DXMESH lpMesh = mesh_container->MeshData.pMesh;
//スキニング情報がない場合
if(pMeshContainer->pSkinInfo==NULL)
{
//デバイスにフレームのワールド行列を設置
this->device->SetTransform( D3DTS_WORLD, &frame->CombinedTransformationMatrix);
//メッシュ描画
for (DWORD i=0;i<mesh_container->NumMaterials;i++)
{
//マテリアル情報の取得
mat = mesh_container->pMaterials[i].MatD3D;
//テクスチャ情報の取得
pTex = mesh_container->ppTextures[i];
//メッシュサブセットを描画
this->DrawSubset(lpMesh,i,&mat,pTex);
}
}
//スキニング情報がある場合
else
{
D3DXMATRIX matId;
PBYTE pVerticesSrc;
PBYTE pVerticesDest;
//ボーン数を取得
DWORD NumBones = pMeshContainer->pSkinInfo->GetNumBones();
for( DWORD i = 0; i < NumBones; i++ ){
D3DXMatrixMultiply(
&mesh_container->pBoneMatrices[i],
&mesh_container->pBoneOffsetMatrices[i],
mesh_container->ppBoneMatrixPtrs[i]
);
}
//ワールド行列をクリア
D3DXMatrixIdentity(&matId);
this->device->SetTransform(D3DTS_WORLD, &matId);
//頂点バッファをロック
mesh_container->lpMesh->LockVertexBuffer( D3DLOCK_READONLY, (LPVOID*)&pVerticesSrc);
lpMesh->LockVertexBuffer( 0, (LPVOID*)&pVerticesDest);
//スキンメッシュ作成
mesh_container->pSkinInfo->UpdateSkinnedMesh( mesh_container->pBoneMatrices, NULL, pVerticesSrc, pVerticesDest);
//頂点バッファのロックを解除
mesh_container->lpMesh->UnlockVertexBuffer();
lpMesh->UnlockVertexBuffer();
//メッシュ描画
for(UINT i = 0;i<mesh_container->NumAttributeGroups;i++)
{
//メッシュサブセットの属性IDを取得
unsigned AttribId = mesh_container->pAttributeTable[i].AttribId;
//マテリアル情報を取得
mat = mesh_container->pMaterials[AttribId].MatD3D;
//テクスチャ情報を取得
pTex = mesh_container->ppTextures[AttribId];
//メッシュのサブセットを描画
this->DrawSubset(lpMesh,AttribId,&mat,pTex);
}
}
}
示例7:
/**
*
* PRECONDITION: parameter EFacePosition _eSide must be either FACE_TOP, or FACE_BOTTOM.
*
* @author Rebeccah Cox
* @param EFacePosition _eSide - the side the flag is on, either top or bottom.
* @param int32 _iX - the position along the X axis.
* @param int32 _iY - the position along the Z axis (looks like the y axis when
* looking at the flag plate).
* @param ETeam _eTeam - team the flagplate belongs to.
* @param uint32 _uiTextureID
* @param uint32 _uiModelID
* @return bool - returns true if the initialisation was successful.
*/
bool
CFlagPlate::Initialise(EFacePosition _eSide, int32 _iX, int32 _iY, ETeam _eTeam, uint32 _uiModelID, uint32 _uiTextureID)
{
// Set the position and side member variables in CTile.
m_eFace = _eSide;
m_iX = _iX;
m_iY = _iY;
m_vec3Position = g_atUpRightDirectionVecs[_eSide].vec3Up * 22.5f;
m_vec3Position += g_atUpRightDirectionVecs[_eSide].vec3Right * ((_iX * 3.0f) - 21.0f);
m_vec3Position -= g_atUpRightDirectionVecs[_eSide].vec3Direction * ((_iY * 3.0f) - 21.0f);
// Set the world matrix using the vectors.
m_matWorld._11 = g_atUpRightDirectionVecs[_eSide].vec3Right.x;
m_matWorld._21 = g_atUpRightDirectionVecs[_eSide].vec3Up.x;
m_matWorld._31 = g_atUpRightDirectionVecs[_eSide].vec3Direction.x;
m_matWorld._12 = g_atUpRightDirectionVecs[_eSide].vec3Right.y;
m_matWorld._22 = g_atUpRightDirectionVecs[_eSide].vec3Up.y;
m_matWorld._32 = g_atUpRightDirectionVecs[_eSide].vec3Direction.y;
m_matWorld._13 = g_atUpRightDirectionVecs[_eSide].vec3Right.z;
m_matWorld._23 = g_atUpRightDirectionVecs[_eSide].vec3Up.z;
m_matWorld._33 = g_atUpRightDirectionVecs[_eSide].vec3Direction.z;
m_matWorld._41 = m_vec3Position.x;
m_matWorld._42 = m_vec3Position.y;
m_matWorld._43 = m_vec3Position.z;
m_bTraversable = true;
m_iModelID = _uiModelID;
m_iTextureID = _uiTextureID;
/*// Set the model ID
if(BAD_ID == _uiModelID)
{
m_iModelID = CModelManager::GetInstance().CreateModel("../../models/tile_flagplate.x");
}
// Set the texture ID
if(BAD_ID == _uiTextureID)
{
if(TEAM_GREEN == _eTeam)
{
m_iTextureID = CTextureManager::GetInstance().CreateTexture("../../textures/tile_flagTile_green.png");
}
else
{
m_iTextureID = CTextureManager::GetInstance().CreateTexture("../../textures/tile_flagTile_purple.png");
}
}*/
D3DXVECTOR3* pFirstVertex = 0;
LPD3DXMESH pMesh = CModelManager::GetInstance().GetModel(m_iModelID)->GetModel();
pMesh->LockVertexBuffer(0, (void**)&pFirstVertex);
D3DXComputeBoundingBox(pFirstVertex,
pMesh->GetNumVertices(),
pMesh->GetNumBytesPerVertex(),
&m_tOBB.m_vec3Min, &m_tOBB.m_vec3Max);
pMesh->UnlockVertexBuffer();
CEntity::Initialise();
return (true);
}
示例8: D3DXMeshCreateDiamond
HRESULT D3DXMeshCreateDiamond( LPDIRECT3DDEVICE9 pDevice, DWORD dwFVF, DWORD dwOption, UINT uSlice
, FLOAT fRadius, FLOAT fUpperConeHeight, FLOAT fLowerConeHeight, LPD3DXMESH* pRet )
{
//创建上下各一棱锥的钻石型
_ASSERTE(fRadius > 0 && fUpperConeHeight >= 0 && fLowerConeHeight >= 0 && uSlice >= 3);
HRESULT hr = E_FAIL;
LPD3DXMESH pMesh = NULL;
KG_PROCESS_ERROR(NULL != pRet);
KG_PROCESS_ERROR(fRadius > 0 && fUpperConeHeight >= 0 && fLowerConeHeight >= 0 && uSlice >= 3);
{
UINT uNumVertices = uSlice + 2; //2是上下两个点
UINT uNumFaces = uSlice * 2;
_ASSERTE(IsMeshValidToBeCreated(dwOption, uNumVertices, uNumFaces * 3));
hr = D3DXCreateMeshFVF(uNumFaces, uNumVertices, dwOption, dwFVF, pDevice, &pMesh);
KG_COM_CHECK_ERROR(hr);
//点的分布是先填圆周的一圈,然后填上下两个点
{
D3DXMeshVertexEnumer vertexEnumer;
hr = D3DXMeshCreateVertexEnumer(pMesh, vertexEnumer);
KG_COM_PROCESS_ERROR(hr);
_ASSERTE(vertexEnumer.IsValid() && vertexEnumer.GetVertexCount() == uNumVertices);
float fAnglePerVertex = 2 * D3DX_PI /static_cast<FLOAT>(uSlice);
float fAngleRotate = D3DX_PI / 4.f; //把所有顶点旋转45度,这样子好些
//注意Angle是不可能超过cos和sin的值域的,不用检查了
for (UINT i = 0; i < vertexEnumer.GetVertexCount() - 2; ++i)
{
FLOAT fAngle = fAnglePerVertex * i;
D3DXVECTOR3 vTemp;
vTemp.x = fRadius * cosf(fAngle + fAngleRotate); //单位圆锥,最后再放缩,所以这里用1
vTemp.y = 0;
vTemp.z = fRadius * sinf(fAngle + fAngleRotate);
vertexEnumer.SetPos(i, vTemp);
}
_ASSERTE(vertexEnumer.GetVertexCount() > 2);
//填上上下两个点
UINT uTopPoint = vertexEnumer.GetVertexCount() - 2;
vertexEnumer.SetPos(uTopPoint, D3DXVECTOR3(0, fUpperConeHeight, 0));
UINT uBottomPoint = vertexEnumer.GetVertexCount() - 1;
vertexEnumer.SetPos(uBottomPoint, D3DXVECTOR3(0, -fLowerConeHeight, 0));
}
{
D3DXMeshIndexEnumer indexEnumer;
hr = D3DXMeshCreateIndexEnumer(pMesh, indexEnumer);
KG_COM_PROCESS_ERROR(hr);
_ASSERTE(indexEnumer.IsValid()&& indexEnumer.GetIndexCount() == 2 * uSlice * 3);
UINT uVertexCountInCircle = pMesh->GetNumVertices() - 2;
{
UINT uUpperFaceCount = uVertexCountInCircle;
DWORD uTopPointIndex = pMesh->GetNumVertices() - 2;
for (UINT uIt = 0, uIndexIndex = 0; uIt < uUpperFaceCount; ++uIt, uIndexIndex += 3)
{
indexEnumer.SetIndex(uIndexIndex, uIt);
indexEnumer.SetIndex(uIndexIndex + 1, uTopPointIndex);
indexEnumer.SetIndex(uIndexIndex + 2, (uIt + 1) % uVertexCountInCircle);
}
}
{
UINT uBottomFaceCount = uVertexCountInCircle;
UINT uUpperFaceCount = uVertexCountInCircle;
DWORD uBottomPointIndex = pMesh->GetNumVertices() - 1;
for (UINT uIt = 0, uIndexIndex = uUpperFaceCount * 3
; uIt < uBottomFaceCount; ++uIt, uIndexIndex += 3)
{
indexEnumer.SetIndex(uIndexIndex, uIt);
indexEnumer.SetIndex(uIndexIndex + 1, (uIt + 1) % uVertexCountInCircle);
indexEnumer.SetIndex(uIndexIndex + 2, uBottomPointIndex);
}
}
}
hr = D3DXMeshZeroMeshAttributes(pMesh);
}
_ASSERTE(NULL != pRet);
*pRet = pMesh;
return S_OK;
Exit0:
SAFE_RELEASE(pMesh);
return E_FAIL;
}
示例9: D3DXMeshCreatePlane
HRESULT D3DXMeshCreatePlane( LPDIRECT3DDEVICE9 pDevice, DWORD dwFVF, DWORD dwOption, UINT uXSlice, UINT uZSlice
, FLOAT fXLength, FLOAT fZLength, LPD3DXMESH* pRet )
{
HRESULT hr = E_FAIL;
LPD3DXMESH pMesh = NULL;
KG_PROCESS_ERROR(D3DFVF_XYZ & dwFVF);//不是XYZ型的Mesh无法自动处理
KG_PROCESS_ERROR(NULL != pRet);
KG_PROCESS_ERROR(uXSlice < 2048 && uZSlice < 2048 && _T("不能创建太大的Plane"));
{
DWORD dwVertexCountInXAxis = (uXSlice + 1);
DWORD dwVertexCountInZAxis = (uZSlice + 1);
DWORD dwVertexCount = dwVertexCountInXAxis * dwVertexCountInZAxis;
DWORD dwNumFaces = uXSlice * uZSlice;
_ASSERTE(IsMeshValidToBeCreated(dwOption, dwVertexCount, dwNumFaces * 3));
hr = D3DXCreateMeshFVF(dwNumFaces, dwVertexCount, dwOption, dwFVF, pDevice, &pMesh);
KG_COM_PROCESS_ERROR(hr);
_ASSERTE(sizeof(BYTE) == 1);
////填点,D3DXMeshVertexEnumer生命域
{
D3DXMeshVertexEnumer vertexEnumer;
hr = D3DXMeshCreateVertexEnumer(pMesh, vertexEnumer);
KG_COM_PROCESS_ERROR(hr);
FLOAT XSliceGap = fXLength / static_cast<FLOAT>(uXSlice);
FLOAT ZSliceGap = fZLength / static_cast<FLOAT>(uZSlice);
_ASSERTE(vertexEnumer.GetVertexCount() == dwVertexCount);
for (UINT i = 0; i < dwVertexCountInXAxis; ++i)
{
for (UINT j = 0; j < dwVertexCountInZAxis; ++j)
{
FLOAT xPos = i * XSliceGap;
FLOAT zPos = i * ZSliceGap;
UINT uIndex = i * dwVertexCountInXAxis + j;
vertexEnumer.SetPos(uIndex, D3DXVECTOR3(xPos, 0, zPos));
}
}
//把坐标填上
if (D3DFVF_TEX1 & dwFVF) //这个默认就是UV两个浮点的。如果用了D3DFVF_TEXCOORDn的话,位会变
{
D3DXMeshVertexTexCoordEnumer texEnumer;
hr = D3DXMeshCreateVertexTexCoordEnumer(vertexEnumer, texEnumer);
FLOAT xUGap = 1.f / static_cast<FLOAT>(uXSlice);
FLOAT zVGap = 1.f / static_cast<FLOAT>(uZSlice);
if (SUCCEEDED(hr))
{
_ASSERTE(2 == texEnumer.GetTexCoordSize());
for (UINT i = 0; i < dwVertexCountInXAxis; ++i)
{
for (UINT j = 0; j < dwVertexCountInZAxis; ++j)
{
UINT uIndex = i * dwVertexCountInXAxis + j;
texEnumer.GetTexCoord2(uIndex) = D3DXVECTOR2(xUGap * i, zVGap * j);
}
}
}
}
}////填点,D3DXMeshVertexEnumer生命域
//填Index
{
D3DXMeshIndexEnumer indexEnumer;
hr = D3DXMeshCreateIndexEnumer(pMesh, indexEnumer);
KG_COM_PROCESS_ERROR(hr);
if (! indexEnumer.Is32Bit())
{
KG_PROCESS_ERROR((pMesh->GetNumVertices() < SHRT_MAX) && _T("顶点数超过IndexBuffer的最大数"));
}
for (UINT i = 0; i < uXSlice; ++i)
{
for (UINT j = 0; j < uZSlice; ++j)
{
DWORD uLowerLeftVertexIndex = i * (uXSlice + 1) + j;
DWORD uLowerRightVertexIndex = uLowerLeftVertexIndex + 1;
DWORD uUpperLeftVertexIndex = uLowerLeftVertexIndex + (uXSlice + 1);
DWORD uUpperRightVertexIndex = uUpperLeftVertexIndex + 1;
UINT uRegionIndexBegin = (i * uXSlice + j) * 6;
indexEnumer.SetIndex(uRegionIndexBegin, uLowerLeftVertexIndex);
indexEnumer.SetIndex(uRegionIndexBegin + 1, uUpperLeftVertexIndex);
indexEnumer.SetIndex(uRegionIndexBegin + 2, uLowerRightVertexIndex);
indexEnumer.SetIndex(uRegionIndexBegin + 3, uLowerLeftVertexIndex);
indexEnumer.SetIndex(uRegionIndexBegin + 4, uUpperLeftVertexIndex);
indexEnumer.SetIndex(uRegionIndexBegin + 5, uUpperRightVertexIndex);
indexEnumer.SetIndex(uRegionIndexBegin + 6, uLowerRightVertexIndex);
}
}
//.........这里部分代码省略.........
示例10: fopen
//.........这里部分代码省略.........
for(int j=0; j < 3 ; ++j)
{
VertexTextureNormal NewVertex;
NewVertex.SetPosition( Vertexs[quadP[j]] );
if( quadT[j] != (DWORD(-1)-1) )
NewVertex.SetTexture ( Textures[quadT[j]].x, Textures[quadT[j]].y );
if( quadN[j] != (DWORD(-1)-1) )
NewVertex.SetNormal ( Normals[quadN[j]] );
DWORD index = AddVertex(quadP[j], NewVertex);
mIndexs.push_back(index);
}
}
}
break;
}
#pragma endregion
}
fclose(fileHandle);
DWORD FVF = NULL;
D3DVERTEXELEMENT9* pMeshVDeclaration = NULL;
int code = 0;
IdentifieLoadedFormat(FVF, pMeshVDeclaration, code);
if( code == 0 )
return;
//Setup Mesh with VertexDeclaration corresponding to the loaded data
LPD3DXMESH pMesh = NULL;
HRESULT hr = NULL;
int FacesCount = mIndexs.size()/3;
switch( m_VertexMetaFormat )
{
case VertexMetaFormat::VertexDeclaration:
{
if( FacesCount > 65535 )// if huge mesh, 32 bits face index
hr = D3DXCreateMesh(FacesCount, mVertexs.size(), D3DXMESH_32BIT | D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM | D3DXMESH_SYSTEMMEM ,
pMeshVDeclaration, pDevice, &pMesh);
else
hr = D3DXCreateMesh(FacesCount, mVertexs.size(), D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM | D3DXMESH_SYSTEMMEM ,
pMeshVDeclaration, pDevice, &pMesh);
}
break;
case VertexMetaFormat::FVF:
{
if( FacesCount > 65535 )// if huge mesh, 32 bits face index
hr = D3DXCreateMeshFVF(FacesCount, Vertexs.size(), D3DXMESH_32BIT | D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM | D3DXMESH_SYSTEMMEM ,
FVF, pDevice, &pMesh);
else
hr = D3DXCreateMeshFVF(FacesCount, Vertexs.size(), D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM | D3DXMESH_SYSTEMMEM ,
FVF, pDevice, &pMesh);
}
break;
default:
assert( false );
}
assert( !FAILED(hr) );
//Puts vertex data inside loadedData in the smallest format needed
示例11: Cleanup
VOID Cleanup( )
{
if (NULL != g_pFont)
{
g_pFont->Release();
}
if (NULL != g_pMesh)
{
g_pMesh->Release();
}
if ( NULL != g_pD3DDevice )
{
g_pD3DDevice->Release();
}
if ( NULL != g_pD3D )
{
g_pD3D->Release();
}
}
示例12: Cleanup
VOID Cleanup()
{
if( g_pMeshMaterials != NULL )
delete[] g_pMeshMaterials;
if( g_pMeshTextures )
{
for( DWORD i = 0; i < g_dwNumMaterials; i++ )
{
if( g_pMeshTextures[i] )
g_pMeshTextures[i]->Release();
}
delete[] g_pMeshTextures;
}
if( g_pMesh != NULL )
g_pMesh->Release();
if( g_pd3dDevice != NULL )
g_pd3dDevice->Release();
if( g_pD3D != NULL )
g_pD3D->Release();
}
示例13: Cleanup
void Cleanup()
{
if (g_pMeshMaterials)
delete[] g_pMeshMaterials;
if (g_pMeshTextures)
{
for (DWORD i = 0; i < g_dwNumMaterials; i++)
{
if (g_pMeshTextures[i])
g_pMeshTextures[i]->Release();
}
delete[] g_pMeshTextures;
}
if (g_pMesh)
g_pMesh->Release();
if (g_pd3dDevice)
g_pd3dDevice->Release();
if (g_pD3D)
g_pD3D->Release();
}
示例14: Cleanup
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
// release all textures used
if ( g_pTexture != NULL )
g_pTexture->Release();
if ( g_pTexture2 != NULL )
g_pTexture2->Release();
if ( marbleTexture != NULL )
marbleTexture->Release();
if ( backgroundTexture != NULL )
backgroundTexture->Release();
if( g_pMeshMaterials != NULL )
delete[] g_pMeshMaterials;
if( g_pMeshTextures )
{
for( DWORD i = 0; i < g_dwNumMaterials; i++ )
{
if( g_pMeshTextures[i] )
g_pMeshTextures[i]->Release();
}
delete[] g_pMeshTextures;
}
if( g_pMesh != NULL )
g_pMesh->Release();
if( g_pd3dDevice != NULL )
g_pd3dDevice->Release();
if( g_pD3D != NULL )
g_pD3D->Release();
}
示例15: Render
//*************************************************************************************************************
void Render(float alpha, float elapsedtime)
{
D3DXMATRIX vp, inv;
D3DXVECTOR3 axis(0, 1, 0);
device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff6694ed, 1.0f, 0);
device->SetTexture(0, tex);
device->SetTexture(1, normalmap);
D3DXMatrixMultiply(&vp, &view, &proj);
D3DXMatrixInverse(&inv, NULL, &view);
effect->SetVector("eyePos", (D3DXVECTOR4*)inv.m[3]);
D3DXMatrixRotationAxis(&world, &axis, timeGetTime() / 1000.0f);
D3DXMatrixInverse(&inv, NULL, &world);
effect->SetMatrix("matWorld", &world);
effect->SetMatrix("matWorldInv", &inv);
effect->SetMatrix("matViewProj", &vp);
if( SUCCEEDED(device->BeginScene()) )
{
effect->Begin(NULL, 0);
effect->BeginPass(0);
{
mesh->DrawSubset(0);
}
effect->EndPass();
effect->End();
device->EndScene();
}
device->Present(NULL, NULL, NULL, NULL);
}