当前位置: 首页>>代码示例>>C++>>正文


C++ LPD3DXMESH::GetNumVertices方法代码示例

本文整理汇总了C++中LPD3DXMESH::GetNumVertices方法的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXMESH::GetNumVertices方法的具体用法?C++ LPD3DXMESH::GetNumVertices怎么用?C++ LPD3DXMESH::GetNumVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPD3DXMESH的用法示例。


在下文中一共展示了LPD3DXMESH::GetNumVertices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateCompatibleDC

LPD3DXMESH Renderer::CreateD3DXTextMesh( const char* pString, bool bCentered )
{
	HRESULT hr;
	LPD3DXMESH pMeshNew = NULL;

	HDC hdc = CreateCompatibleDC( NULL );
	if( hdc == NULL )
		return NULL;

	HFONT newfont=CreateFont(10,         //Height
		0,          //Width
		0,          //Escapement
		0,          //Orientation
		FW_NORMAL,  //Weight
		false,      //Italic
		false,      //Underline
		false,      //Strikeout
		DEFAULT_CHARSET,//Charset 
		OUT_DEFAULT_PRECIS,  //Output Precision
		CLIP_DEFAULT_PRECIS, //Clipping Precision
		DEFAULT_QUALITY,     //Quality
		DEFAULT_PITCH|FF_DONTCARE, //Pitch and Family
		"Arial");



	HFONT hFontOld;
	hFontOld = ( HFONT )SelectObject( hdc, newfont );
	hr = D3DXCreateText( m_pD3DDevice, hdc, pString, 0.001f, 0.2f, &pMeshNew, NULL, NULL );
	SelectObject( hdc, hFontOld );
	DeleteDC( hdc );

	if( SUCCEEDED( hr ) )
	{
		if( bCentered )
		{
			// Center text
			D3DXVECTOR3 vMin, vMax;

			PosNormalVertex* pVertices;
			pMeshNew->LockVertexBuffer( 0, reinterpret_cast<VOID**>(&pVertices));
			D3DXComputeBoundingBox( (D3DXVECTOR3*)pVertices, pMeshNew->GetNumVertices(), sizeof ( PosNormalVertex ), &vMin, &vMax );

			D3DXVECTOR3 vOffset;
			D3DXVec3Subtract( &vOffset, &vMax, &vMin );
			D3DXVec3Scale( &vOffset, &vOffset, 0.5f );
			for ( unsigned int i = 0; i < pMeshNew->GetNumVertices(); i++)
			{
				D3DXVec3Subtract( &pVertices[i].Coord, &pVertices[i].Coord, &vOffset );
			}
			pMeshNew->UnlockVertexBuffer();
		}
	}

	return pMeshNew;
}
开发者ID:SHPURDYdBurt,项目名称:https-github.com-xbmc-atv2,代码行数:56,代码来源:Renderer.cpp

示例2: D3DXMeshTransformation

HRESULT D3DXMeshTransformation( LPD3DXMESH pMesh, const D3DXMATRIX* pMatrix
							   , VisitorForD3DXVECTOR3* pPointFilter)
{
	KG_PROCESS_ERROR(NULL != pMesh && NULL != pMatrix);

	{
		DWORD fvf = pMesh->GetFVF();
		KG_PROCESS_ERROR(fvf | D3DFVF_XYZ);

		DWORD dwNumBytePerVertex = pMesh->GetNumBytesPerVertex();
		_ASSERTE(dwNumBytePerVertex >= sizeof(D3DXVECTOR3));

		DWORD dwNumVertex = pMesh->GetNumVertices();

		BYTE* pBufferStart = NULL;
		_ASSERTE(sizeof(BYTE) == 1);
		

		if(NULL == pPointFilter)
		{
			HRESULT hr = pMesh->LockVertexBuffer(0, (LPVOID*)&pBufferStart);
			KG_COM_PROCESS_ERROR(hr);
			D3DXVec3TransformCoordArray((D3DXVECTOR3*)(pBufferStart), dwNumBytePerVertex
				, (D3DXVECTOR3*)pBufferStart, dwNumBytePerVertex, pMatrix, dwNumVertex);
			pMesh->UnlockVertexBuffer();
		}
		else
		{
			//加了Filter之后性能下降是当然的,但是这不是给实时用的,所以没有关系,控制
			//调用次数和调用时机就好了
			D3DXMeshVertexEnumer vertexEnumer;
			HRESULT hr = D3DXMeshCreateVertexEnumer(pMesh, vertexEnumer);
			KG_COM_PROCESS_ERROR(hr);
			_ASSERTE(vertexEnumer.IsValid());
			HRESULT hrForVisitor = E_FAIL;
			for (UINT i = 0; i < vertexEnumer.GetVertexCount(); ++i)
			{
				const D3DXVECTOR3& vTemp = vertexEnumer.GetPos(i);
				hrForVisitor = pPointFilter->Accept(vTemp);
				if (FAILED(hr))
				{
					continue;
				}

				D3DXVECTOR3 vTransformed;
				D3DXVec3TransformCoord(&vTransformed, &vTemp, pMatrix);
				vertexEnumer.SetPos(i, vTransformed);
			}
		}

		
	}		

	return S_OK;
Exit0:
	return E_FAIL;
}
开发者ID:1suming,项目名称:pap2,代码行数:57,代码来源:KG3DMeshHelpers.cpp

示例3: CreateMappedSphere

LPD3DXMESH SkyBox::CreateMappedSphere(float fRad, UINT slices, UINT stacks)
{
	// create the sphere
	LPD3DXMESH mesh;
	if (FAILED(D3DXCreateSphere(GameManager::GetDevice( ), fRad, slices, stacks, &mesh, NULL)))
		return NULL;

	// create a copy of the mesh with texture coordinates,
	// since the D3DX function doesn't include them
	LPD3DXMESH texMesh;
	if (FAILED(mesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM, FVF_PositionNormalTexture::FVF, GameManager::GetDevice( ), &texMesh)))
		return mesh;	// failed, return un-textured mesh
	
	mesh->Release( );		// finished with the original mesh, release it


	// lock the vertex buffer
	FVF_PositionNormalTexture* pVerts;
	//if (SUCCEEDED(texMesh->LockVertexBuffer(0, (BYTE **)&pVerts)))
	if (SUCCEEDED(texMesh->LockVertexBuffer(0, (LPVOID*)&pVerts)))
	{
		int numVerts = texMesh->GetNumVertices( );		// get vertex count

		// loop through the vertices
		for (int i = 0; i < numVerts; i++)
		{
			// calculate texture coordinates
			pVerts->tex.x = asinf(pVerts->normal.x) / D3DX_PI + 0.5f;
			pVerts->tex.y = asinf(pVerts->normal.y) / D3DX_PI + 0.5f;

			//pVerts->tex.x = 0.5f - (atan2f(pVerts->normal.z, pVerts->normal.x) / (2 * D3DX_PI));
			//pVerts->tex.y = 0.5f - asinf(pVerts->normal.y) / (D3DX_PI);
			
			//pVerts->tex.y = pVerts->normal.y * 0.5 + 0.5;

			//if (pVerts->tex.x <(FLOAT)0.9) pVerts->tex.x = (FLOAT)0.0;


			//pVerts->tex.x = pVerts->pos.x / sqrtf((pVerts->pos.x * pVerts->pos.x) + (pVerts->pos.y * pVerts->pos.x) + (pVerts->pos.z * pVerts->pos.z));
			//pVerts->tex.y = pVerts->pos.y / sqrtf((pVerts->pos.x * pVerts->pos.x) + (pVerts->pos.y * pVerts->pos.x) + (pVerts->pos.z * pVerts->pos.z));

			//float theta = asinf(pVerts->normal.z);
			//float phi = atan2(pVerts->normal.y, pVerts->normal.x);
			//
			//pVerts->tex = D3DXVECTOR2(phi / 2 / 3.14159265, theta /  3.14159265);

			// go to next vertex
			pVerts++; 

		}
	
		texMesh->UnlockVertexBuffer( );		// unlock the vertex buffer
	}

	// return pointer to caller
	return texMesh;
}
开发者ID:naknaknak,项目名称:3D_Game_Portfolio,代码行数:57,代码来源:SkyBox.cpp

示例4: convertMesh

LPD3DXMESH CWall::convertMesh(IDirect3DDevice9* pDevice, LPD3DXMESH& mesh){

	D3DVERTEXELEMENT9 decl[] =
	{
		{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
		{ 0, sizeof(D3DXVECTOR3), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
		{ 0, sizeof(D3DXVECTOR3) * 2, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
		D3DDECL_END()//will be declared on 
	};

	LPD3DXMESH newMesh = nullptr;
	VERTEX* pVerts;
	HRESULT result = mesh->CloneMesh(D3DXMESH_SYSTEMMEM, decl, pDevice, &newMesh);

	if (FAILED(result)) return nullptr;
	float u = 0;
	float v = 0;
	bool reverse = false;
	if (SUCCEEDED(newMesh->LockVertexBuffer(0, (LPVOID*)&pVerts))){
		int numVerts = newMesh->GetNumVertices();
		for (int i = 0; i < numVerts; i++){
			pVerts->tu = u;
			pVerts->tv = v;
		
			if (u == 0 && v==0){
				if (reverse)
					u++;
				else
					v++;
				
			}
			else if (v == 1 && u == 0){
				u++;
			
			}
			else if (v == 0 && u == 1){
				v++;
			
			}
			else{
				if (reverse)
					reverse = false;
				else reverse = true;
				u = 0;
				v = 0;
			}
			pVerts++;
		}
		newMesh->UnlockVertexBuffer();
		//temporary uv generator
		return newMesh;
	}
	else{
		return nullptr;
	}
}
开发者ID:neropsys,项目名称:DX9_0_Billiard,代码行数:56,代码来源:CWall.cpp

示例5: DrawMeshContainer

/**
 * \brief Called to render a mesh
 * \param device - the Direct3D device object
 * \param meshContainerBase - the mesh container
 * \param frameBase - frame containing the mesh
 * \author Keith Ditchburn \date 18 July 2005
*/
void CXFileEntity::DrawMeshContainer(LPD3DXMESHCONTAINER meshContainerBase, LPD3DXFRAME frameBase)
{
	DWORD attrSize = 0;
	// Cast to our extended frame type
	D3DXFRAME_EXTENDED *frame = (D3DXFRAME_EXTENDED*)frameBase;		

	// Cast to our extended mesh container
	D3DXMESHCONTAINER_EXTENDED *meshContainer = (D3DXMESHCONTAINER_EXTENDED*)meshContainerBase;
	
	// Set the world transform
    m_d3dDevice->SetTransform(D3DTS_WORLD, &frame->exCombinedTransformationMatrix);

	unsigned int pass;
	if (effect) {
		effect->SetMatrix("worldmat",&frame->exCombinedTransformationMatrix);

		effect->Begin(&pass,0);
		effect->BeginPass(0);
	}

	// Loop through all the materials in the mesh rendering each subset
    for (unsigned int iMaterial = 0; iMaterial < meshContainer->NumMaterials; iMaterial++)
    {
		// use the material in our extended data rather than the one in meshContainer->pMaterials[iMaterial].MatD3D
		//m_d3dDevice->SetMaterial( &meshContainer->exMaterials[iMaterial] );
		//m_d3dDevice->SetTexture( 0, meshContainer->exTextures[iMaterial] );

		// Select the mesh to draw, if there is skin then use the skinned mesh else the normal one
		LPD3DXMESH pDrawMesh = (meshContainer->pSkinInfo) ? meshContainer->exSkinMesh: meshContainer->MeshData.pMesh;

		// Finally Call the mesh draw function
        //pDrawMesh->DrawSubset(iMaterial);

		pDrawMesh->GetVertexBuffer(&vb.vb);
		pDrawMesh->GetIndexBuffer(&ib.ib);

		//D3DVERTEXELEMENT9 pDecl[MAX_FVF_DECL_SIZE];
		//pDrawMesh->GetDeclaration(pDecl);
		//renderSystem->CreateVertexDeclaration(&pDecl[0],&vb.declaration);
		// Получение данных о количестве вершин, индексов и полигонов
		dwNumVerticies	= pDrawMesh->GetNumVertices();
		dwNumIndecies	= pDrawMesh->GetNumFaces()*3;
		dwNumFaces		= pDrawMesh->GetNumFaces();
		vb.vertexSize = (short)pDrawMesh->GetNumBytesPerVertex();

		renderSystem->DrawIndexedPrimitive(vb,0,dwNumVerticies,ib,0,dwNumFaces);
    }

	if (effect) {
		effect->EndPass();
		effect->End();
	}
}
开发者ID:corpsofengineers,项目名称:ffed3d,代码行数:60,代码来源:XfileEntity.cpp

示例6: ComputeBoundingBox

bool Floor::ComputeBoundingBox()
{
	if( m_computedBoundingBox) return true;
	BYTE* pVertices = NULL;
	LPD3DXMESH mesh = m_mesh->GetD3DMesh();
	HRESULT hr = mesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);
	if(FAILED(hr))
		return false;
	D3DXComputeBoundingBox((D3DXVECTOR3*)pVertices, mesh->GetNumVertices(), mesh->GetNumBytesPerVertex(), &m_bottomLeft, &m_topRight);
	mesh->UnlockVertexBuffer();
	m_computedBoundingBox = true;
	return true;
}
开发者ID:ludwigpe,项目名称:DungeonGame,代码行数:13,代码来源:Floor.cpp

示例7: LoadMesh

void cMyASELoader::LoadMesh(){
#ifdef _DEBUG
	_ASSERT(m_bLoaded && "Data Not Loaded");
#endif
	int check = 0;
	for (size_t i = 0; i < m_vecASENode.size(); i++){
		if (m_vecASENode[i].nRef != INT_MAX){
			m_vecsubSet.push_back(m_vecASENode[i].nRef);
			LPD3DXMESH pMesh = NULL;
			HRESULT hr = D3DXCreateMeshFVF(m_vecASENode[i].vecVertex.size() / 3,
				m_vecASENode[i].vecVertex.size(),
				D3DXMESH_MANAGED,
				ST_PNT_VERTEX::FVF,
				g_pD3DDevice,
				&pMesh);

			ST_PNT_VERTEX* pV = NULL;
			pMesh->LockVertexBuffer(0, (LPVOID*)&pV);
			memcpy(pV, &m_vecASENode[i].vecVertex[0], m_vecASENode[i].vecVertex.size() * sizeof(ST_PNT_VERTEX));
			pMesh->UnlockVertexBuffer();

			WORD* pI = NULL;
			pMesh->LockIndexBuffer(0, (LPVOID*)&pI);
			for (size_t j = 0; j < pMesh->GetNumVertices(); ++j)
			{
				pI[j] = j;
			}
			pMesh->UnlockIndexBuffer();

			DWORD* pA = NULL;
			pMesh->LockAttributeBuffer(0, &pA);
			for (size_t j = 0; j < pMesh->GetNumFaces(); j++){
				pA[j] = m_vecASENode[i].nRef;
			}
			pMesh->UnlockAttributeBuffer();

			std::vector<DWORD> vecAdjBuffer(m_vecASENode[i].vecVertex.size());
			pMesh->GenerateAdjacency(0.0f, &vecAdjBuffer[0]);

			pMesh->OptimizeInplace(
				D3DXMESHOPT_ATTRSORT |
				D3DXMESHOPT_COMPACT |
				D3DXMESHOPT_VERTEXCACHE,
				&vecAdjBuffer[0], 0, 0, 0);

			m_vecMeshs.push_back(pMesh);
		}
	}
	m_bMeshed = true;
}
开发者ID:arkiny,项目名称:Direct3D,代码行数:50,代码来源:cMyASELoader.cpp

示例8: initGeometry

HRESULT initGeometry(){
	LPD3DXBUFFER pD3DXMtrlBuffer;
	if(FAILED(D3DXLoadMeshFromX(L"seafloor.x", D3DXMESH_MANAGED,
		g_pDevice, NULL, &pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, &g_pMesh)))
		return E_FAIL;
	//Extract material & texture
	D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
	g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];

	if(g_pMeshMaterials == NULL)
		return E_OUTOFMEMORY;

	g_pMeshTextures = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];
	if(g_pMeshTextures == NULL)
		return E_OUTOFMEMORY;
	//Extract
	for(DWORD i=0; i<g_dwNumMaterials; ++i){
		g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
		g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;

		g_pMeshTextures[i] = NULL;
		if(d3dxMaterials[i].pTextureFilename != NULL && strlen(d3dxMaterials[i].pTextureFilename) > 0){
			WCHAR name[256];
			removePathFromFileName(d3dxMaterials[i].pTextureFilename, name);

			if(FAILED(D3DXCreateTextureFromFile(g_pDevice, name, &g_pMeshTextures[i]))){
				MessageBox(NULL, L"Cound not find texture file", L"initGeometry()", MB_OK);
			}
		}
	}
	pD3DXMtrlBuffer->Release();

	//Modify the mesh
	LPDIRECT3DVERTEXBUFFER9 pVB;
	if(SUCCEEDED(g_pMesh->GetVertexBuffer(&pVB))){
		struct VERTEX{FLOAT x,y,z,tu,tv;};
		VERTEX* pVertices;
		DWORD dwNumVertices = g_pMesh->GetNumVertices();

		pVB->Lock(0,0,(void**)&pVertices, 0);

		for(DWORD i=0; i<dwNumVertices; ++i)
			pVertices[i].y = heightField(pVertices[i].x, pVertices[i].z);

		pVB->Unlock();
		pVB->Release();
	}

	return S_OK;
};
开发者ID:junglek,项目名称:DirectX-Basic,代码行数:50,代码来源:Main.cpp

示例9:

PRIVATE inline void _MDLCenterMesh(float trans[eMaxPt], LPD3DXMESH mesh)
{
	gfxVtx *pVtx;

	if(SUCCEEDED(mesh->LockVertexBuffer(0, (BYTE**)&pVtx)))
	{
		for(int i = 0; i < mesh->GetNumVertices(); i++)
		{
			pVtx[i].x -= trans[eX];
			pVtx[i].y -= trans[eY];
			pVtx[i].z -= trans[eZ];
		}

		mesh->UnlockVertexBuffer();
	}
}
开发者ID:PtrickH,项目名称:homies,代码行数:16,代码来源:GFX_Model.cpp

示例10: __GetBoundBox

bool CMesh::__GetBoundBox(const LPD3DXMESH pMesh, CRectangle3D& Rect3d)
{
	if (pMesh == NULL)
		return false;

	UINT uVertexNum = pMesh->GetNumVertices();

	LPD3DXMESH pTempMesh;
	pMesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_XYZ, &DEVICE, &pTempMesh);
	
	LPDIRECT3DVERTEXBUFFER9 pVertexBuffer;
	pTempMesh->GetVertexBuffer(&pVertexBuffer);

	FLOAT maxX = 0.0f, maxY = 0.0f, maxZ = 0.0f;
	FLOAT minX = 0.0f, minY = 0.0f, minZ = 0.0f;

	D3DXVECTOR3* pVertices;

	pVertexBuffer->Lock(0, 0, (void**)&pVertices, 0);

	for(UINT i = 0; i < uVertexNum; i ++)
	{
		if(pVertices[i].x > maxX)
			maxX = pVertices[i].x;
		if(pVertices[i].y > maxY)
			maxY = pVertices[i].y;
		if(pVertices[i].z > maxZ)
			maxZ = pVertices[i].z;

		if(pVertices[i].x < minX)
			minX = pVertices[i].x;
		if(pVertices[i].y < minY)
			minY = pVertices[i].y;
		if(pVertices[i].z < minZ)
			minZ = pVertices[i].z;
	}
	pVertexBuffer->Unlock();

	Rect3d.Set(minX, maxX, minY, maxY, minZ, maxZ);

	DEBUG_RELEASE(pVertexBuffer);
	DEBUG_RELEASE(pTempMesh);

	return true;
}
开发者ID:dreamsxin,项目名称:zero3d,代码行数:45,代码来源:Mesh.cpp

示例11: ASSERT

HRESULT KG3DMesh::_LoadBSPFileFromMemory(IKG_Buffer *piBSPFile)
{
	HRESULT hrResult  = E_FAIL;
    HRESULT hrRetCode = E_FAIL;
    DWORD dwBSPVertexCount = 0;
    DWORD dwBSPFaceCount = 0;
    DWORD dwMeshVerticesCount = 0;
    DWORD dwMeshFacesCount = 0;
    LPD3DXMESH piMesh = m_ppMeshes[SMBT_NORMAL];
    KG3DBsp *pBSP = NULL;
   
    ASSERT(piBSPFile);

    KGLOG_PROCESS_ERROR(piMesh);
    dwMeshFacesCount    = piMesh->GetNumFaces();
    dwMeshVerticesCount = piMesh->GetNumVertices();

    pBSP = new KG3DBsp;
    KGLOG_PROCESS_ERROR(pBSP);

	hrRetCode = pBSP->LoadFromMemory(piBSPFile);
	KGLOG_COM_PROCESS_ERROR(hrRetCode);

    hrRetCode = pBSP->GetMeshInfo(&dwBSPVertexCount, &dwBSPFaceCount);
    KGLOG_COM_PROCESS_ERROR(hrRetCode);

    if ((dwBSPVertexCount != dwMeshVerticesCount) || (dwBSPFaceCount != dwMeshFacesCount))
    {
        KGLogPrintf(KGLOG_ERR, "%s, BSP unmatch Mesh :(", m_scName.c_str());
        KG_PROCESS_ERROR(FALSE);
    }

    ASSERT(!m_lpBsp);
    m_lpBsp = pBSP;
    pBSP = NULL;
	hrResult = S_OK;
Exit0:
    KG_DELETE(pBSP);
	if(FAILED(hrResult))
	{
		KGLogPrintf(KGLOG_ERR, "%s BSP加载失败", m_scName.c_str());
	}
	return hrResult;
}
开发者ID:1suming,项目名称:pap2,代码行数:44,代码来源:KG3DMeshLoader.cpp

示例12: D3DXMeshCreateVertexEnumer

HRESULT D3DXMeshCreateVertexEnumer( LPD3DXMESH pMesh, D3DXMeshVertexEnumer& enumer )
{
	_ASSERTE(! enumer.IsValid());
	ZeroMemory(&enumer, sizeof(D3DXMeshVertexEnumer));//因为外部传入的enumer是可能重用的,这里绝对要重新清空一次

	_ASSERTE(NULL != pMesh);
	KG_PROCESS_ERROR(NULL != pMesh);
	{
		BOOL bIsAcceptableMesh = pMesh->GetFVF() & D3DFVF_XYZ;

		KG_PROCESS_ERROR(bIsAcceptableMesh && _T("不支持没有XYZ标志的Mesh,那样不能保证每个节点开头是顶点"));

		HRESULT hr = pMesh->LockVertexBuffer(0, reinterpret_cast<LPVOID*>(&enumer.m_pBuffer));
		KG_COM_PROCESS_ERROR(hr);
		_ASSERTE(1 == sizeof(BYTE));
		enumer.m_pMesh = pMesh;
		enumer.m_pMesh->AddRef();
		enumer.m_dwNumBytePerVertex = pMesh->GetNumBytesPerVertex();
		enumer.m_dwNumVertexCount = pMesh->GetNumVertices();
		return S_OK;
	}
Exit0:
	return E_FAIL;
}
开发者ID:1suming,项目名称:pap2,代码行数:24,代码来源:KG3DMeshHelpers.cpp

示例13: Update

VOID Update()
{
	DWORD currentTime = GetTickCount();
	static DWORD preTime;
	g_ElapsedTime = currentTime - preTime;
	preTime = currentTime;

	if ( GetAsyncKeyState( VK_LEFT ) )
	{
		g_Box[0].CenterPos.x -= g_ElapsedTime*0.002f;
	}
	if ( GetAsyncKeyState( VK_RIGHT ) )
	{
		g_Box[0].CenterPos.x += g_ElapsedTime*0.002f;
	}
	if ( GetAsyncKeyState( VK_UP ) )
	{
		g_Box[0].CenterPos.y += g_ElapsedTime*0.002f;
	}
	if ( GetAsyncKeyState( VK_DOWN ) )
	{
		g_Box[0].CenterPos.y -= g_ElapsedTime*0.002f;
	}
	if ( GetAsyncKeyState( VK_LBUTTON ) )
	{
		if (g_ElapsedTime > 20)
		{
			g_Method = !g_Method;
		}
		
	}
	if ( GetAsyncKeyState( VK_HOME ) )
	{
		g_Box[1].BoxRotateZ -= 0.2f;
	}
	if ( GetAsyncKeyState( VK_END ) )
	{
		g_Box[1].BoxRotateZ += 0.2f;
	}

	D3DXVECTOR3 *vertices;

	g_pMesh->LockVertexBuffer( D3DLOCK_READONLY, (void**) &vertices );
	D3DXComputeBoundingBox( vertices, g_pMesh->GetNumVertices(), g_pMesh->GetNumBytesPerVertex(), &g_MinPoint, &g_MaxPoint );
	g_pMesh->UnlockVertexBuffer();

	D3DXMATRIX matScale, matTrans, matRotateZ, matWorld;
	D3DXMatrixTranslation( &matTrans, g_Box[0].CenterPos.x, g_Box[0].CenterPos.y, g_Box[0].CenterPos.z );
	D3DXMatrixScaling( &matScale, g_Box[0].BoxScaling, g_Box[0].BoxScaling, g_Box[0].BoxScaling );
	D3DXMatrixRotationZ( &matRotateZ, g_Box[0].BoxRotateZ );

	matWorld = matRotateZ* matScale * matTrans;
	D3DXVec3TransformCoord( &g_Box[0].MinPoint, &g_MinPoint, &matWorld );
	D3DXVec3TransformCoord( &g_Box[0].MaxPoint, &g_MaxPoint, &matWorld );
	
	if (!g_Method)
	{
		g_CheckFlag = CheckAABBIntersection( &g_Box[0].MinPoint, &g_Box[0].MaxPoint, &g_Box[1].MinPoint, &g_Box[1].MaxPoint );
	}
	else
	{
		g_CheckFlag = CheckOBBIntersection( &g_Box[0], &g_Box[1] );
	}
	
}
开发者ID:trizdreaming,项目名称:AABB_OBB_collision,代码行数:65,代码来源:AABB_OBB_collision.cpp

示例14: InitGeometry

HRESULT InitGeometry( )
{
	if (FAILED(D3DXCreateBox(g_pD3DDevice, 1.f, 1.f, 1.f, &g_pMesh, NULL)))
	{
		return E_FAIL;
	}

	D3DXVECTOR3 *vertices;
	
	
	g_pMesh->LockVertexBuffer( D3DLOCK_READONLY, (void**) &vertices );
	D3DXComputeBoundingBox( vertices, g_pMesh->GetNumVertices(), g_pMesh->GetNumBytesPerVertex(), &g_MinPoint, &g_MaxPoint );
	g_pMesh->UnlockVertexBuffer();

	
	D3DXMATRIX matScale, matTrans, matRotateZ, matWorld;

	g_Box[0].BoxScaling = 1.5f;
	g_Box[0].CenterPos = D3DXVECTOR3( 0.f, 0.f, 0.f );
	g_Box[0].BoxRotateZ = 0.f;
	g_Box[0].AxisDir[0] = D3DXVECTOR3( 1, 0, 0 );
	g_Box[0].AxisDir[1] = D3DXVECTOR3( 0, 1, 0 );
	g_Box[0].AxisDir[2] = D3DXVECTOR3( 0, 0, 1 );

	for ( int i = 0; i < 3; ++i )
	{
		g_Box[0].AxisLen[i] = 0.5f;

		D3DXVec3TransformNormal( &(g_Box[0].AxisDir[i]), &(g_Box[0].AxisDir[i]), &matRotateZ );
		D3DXVec3Normalize( &( g_Box[0].AxisDir[i] ), &( g_Box[0].AxisDir[i] ) );
		g_Box[0].AxisLen[i] = g_Box[0].AxisLen[i] * g_Box[0].BoxScaling;
	}
	D3DXMatrixTranslation( &matTrans, g_Box[0].CenterPos.x, g_Box[0].CenterPos.y, g_Box[0].CenterPos.z );
	D3DXMatrixScaling( &matScale, g_Box[0].BoxScaling, g_Box[0].BoxScaling, g_Box[0].BoxScaling );
	D3DXMatrixRotationZ( &matRotateZ, g_Box[0].BoxRotateZ );

	matWorld = matRotateZ* matScale * matTrans;
	D3DXVec3TransformCoord( &g_Box[0].MinPoint, &g_MinPoint, &matWorld );
	D3DXVec3TransformCoord( &g_Box[0].MaxPoint, &g_MaxPoint, &matWorld );

	
	g_Box[1].BoxScaling = 2.f;
	g_Box[1].CenterPos = D3DXVECTOR3( 3.f, 3.f, 0.f );
	g_Box[1].BoxRotateZ = 0.f;
	g_Box[1].AxisDir[0] = D3DXVECTOR3( 1, 0, 0 );
	g_Box[1].AxisDir[1] = D3DXVECTOR3( 0, 1, 0 );
	g_Box[1].AxisDir[2] = D3DXVECTOR3( 0, 0, 1 );

	for ( int i = 0; i < 3; ++i )
	{
		g_Box[1].AxisLen[i] = 0.5f;

		D3DXVec3TransformNormal( &( g_Box[0].AxisDir[i] ), &( g_Box[1].AxisDir[i] ), &matRotateZ );
		D3DXVec3Normalize( &( g_Box[1].AxisDir[i] ), &( g_Box[1].AxisDir[i] ) );
		g_Box[1].AxisLen[i] = g_Box[1].AxisLen[i] * g_Box[1].BoxScaling;
	}

	D3DXMatrixTranslation( &matTrans, g_Box[1].CenterPos.x, g_Box[1].CenterPos.y, g_Box[1].CenterPos.z );
	D3DXMatrixScaling( &matScale, g_Box[1].BoxScaling, g_Box[1].BoxScaling, g_Box[1].BoxScaling );
	D3DXMatrixRotationZ( &matRotateZ, g_Box[1].BoxRotateZ );

	matWorld = matRotateZ* matScale * matTrans;
	D3DXVec3TransformCoord( &g_Box[1].MinPoint, &g_MinPoint, &matWorld );
	D3DXVec3TransformCoord( &g_Box[1].MaxPoint, &g_MaxPoint, &matWorld );


	return S_OK;
}
开发者ID:trizdreaming,项目名称:AABB_OBB_collision,代码行数:68,代码来源:AABB_OBB_collision.cpp

示例15: checkPick

//------------------------------------------------------------------------------
//this is a check function
//------------------------------------------------------------------------------
void TriPickDemo::checkPick(LPD3DXMESH mesh, D3DXMATRIX matWorld)
{
	HRESULT hr;

	D3DXMATRIX mWorldViewProjection;
	mWorldViewProjection = matWorld * g_Camera->viewProj();

	HR(m_FX->SetTechnique("RenderScene"));

	// send matrix to shader
	HR(m_FX->SetMatrix("g_mWorldViewProjection", &mWorldViewProjection));
	HR(m_FX->SetMatrix("g_mWorld", &matWorld));
	UINT uPasses;
	V(m_FX->Begin(&uPasses, 0));

	g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);

	V(m_FX->BeginPass(0));
	//get select ray
	D3DXVECTOR3 originW(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 dirW(0.0f, 0.0f, 0.0f);
	if (gDInput->mouseButtonDown(0))
	{
		getWorldPickingRay(originW, dirW, matWorld);
		LPD3DXMESH pMesh;

		mesh->CloneMeshFVF(D3DXMESH_MANAGED, D3DVERTEX::FVF, g_pDevice, &pMesh);
		BOOL hit = 0;
		DWORD faceIndex = -1;
		float u = 0.0f;
		float v = 0.0f;
		float dist = 0.0f;
		ID3DXBuffer* allhits = 0;
		DWORD numHits = 0;
		HR(D3DXIntersect(pMesh, &originW, &dirW, &hit,
			&faceIndex, &u, &v, &dist, &allhits, &numHits));
		SAFE_RELEASE(allhits);
		//if hit
		if (hit)
		{
			IDirect3DVertexBuffer9* vb = 0;
			IDirect3DIndexBuffer9* ib = 0;
			HR(pMesh->GetVertexBuffer(&vb));
			HR(pMesh->GetIndexBuffer(&ib));

			HR(g_pDevice->SetIndices(ib));
			HR(g_pDevice->SetFVF(D3DVERTEX::FVF));
			HR(g_pDevice->SetStreamSource(0, vb, 0, sizeof(D3DVERTEX)));

			//render hit surface
			HR(g_pDevice->DrawIndexedPrimitive(
				D3DPT_TRIANGLELIST, 0, 0, pMesh->GetNumVertices(), faceIndex * 3, 1))

				g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
			SAFE_RELEASE(vb);
			SAFE_RELEASE(ib);
			SAFE_RELEASE(pMesh);
		}
	}

	HR(m_FX->EndPass());
	HR(m_FX->End());
}
开发者ID:duoshengyu,项目名称:InverseIK,代码行数:66,代码来源:MyApp.cpp


注:本文中的LPD3DXMESH::GetNumVertices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。