示例#1
0
文件: mesh.c 项目: bilboed/wine
static void D3DXComputeBoundingSphereTest(void)
{
    D3DXVECTOR3 exp_cen, got_cen, vertex[5];
    FLOAT exp_rad, got_rad;
    HRESULT hr;

    vertex[0].x = 1.0f; vertex[0].y = 1.0f; vertex[0].z = 1.0f;
    vertex[1].x = 1.0f; vertex[1].y = 1.0f; vertex[1].z = 1.0f;
    vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 1.0f;
    vertex[3].x = 1.0f; vertex[3].y = 1.0f; vertex[3].z = 1.0f;
    vertex[4].x = 9.0f; vertex[4].y = 9.0f; vertex[4].z = 9.0f;

    exp_rad = 6.928203f;
    exp_cen.x = 5.0; exp_cen.y = 5.0; exp_cen.z = 5.0;

    hr = D3DXComputeBoundingSphere(&vertex[3],2,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_cen,&got_rad);

    ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
    ok( compare(exp_rad, got_rad), "Expected radius: %f, got radius: %f\n", exp_rad, got_rad);
    ok( compare_vec3(exp_cen,got_cen), "Expected center: (%f, %f, %f), got center: (%f, %f, %f)\n", exp_cen.x,exp_cen.y,exp_cen.z,got_cen.x,got_cen.y,got_cen.z);

/*________________________*/

    vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
    vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
    vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
    vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
    vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;

    exp_rad = 13.707883f;
    exp_cen.x = 2.408f; exp_cen.y = 2.22f; exp_cen.z = 3.76f;

    hr = D3DXComputeBoundingSphere(&vertex[0],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_cen,&got_rad);

    ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
    ok( compare(exp_rad, got_rad), "Expected radius: %f, got radius: %f\n", exp_rad, got_rad);
    ok( compare_vec3(exp_cen,got_cen), "Expected center: (%f, %f, %f), got center: (%f, %f, %f)\n", exp_cen.x,exp_cen.y,exp_cen.z,got_cen.x,got_cen.y,got_cen.z);

/*________________________*/
    hr = D3DXComputeBoundingSphere(NULL,5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_cen,&got_rad);
    ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);

/*________________________*/
    hr = D3DXComputeBoundingSphere(&vertex[3],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),NULL,&got_rad);
    ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);

/*________________________*/
    hr = D3DXComputeBoundingSphere(&vertex[3],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_cen,NULL);
    ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
}
示例#2
0
INT CLcMdl2D::Create(void* p1, void* p2, void* p3, void* p4)
{
	char*	sFile = (char*)p1;

	if(FAILED(LoadFromFile(sFile)))
		return -1;


	char fname[128]={0};
	char fext [ 32]={0};
	LcStr_SplitPath(sFile, NULL, NULL, fname, fext);
	sprintf(m_sName, "%s%s", fname, fext);


	D3DXVECTOR3 vcMin;
	D3DXVECTOR3 vcMax;

	// Set Max and Min vertex Position
	D3DXComputeBoundingBox(	(D3DXVECTOR3*)m_pVtx
							, 4
							, D3DXGetFVFVertexSize(VtxDUV1::FVF)
							, &vcMin
							, &vcMax);

	m_BndInf.Set(vcMin, vcMax);

	return 0;
}
示例#3
0
文件: D3DUtils.cpp 项目: galek/xray
void SPrimitiveBuffer::CreateFromData(D3DPRIMITIVETYPE _pt, u32 _p_cnt, u32 FVF, LPVOID vertices, u32 _v_cnt, u16* indices, u32 _i_cnt)
{
#ifdef	USE_DX10
//	TODO: DX10: Implement SPrimitiveBuffer::CreateFromData for DX10
//	VERIFY(!"SPrimitiveBuffer::CreateFromData not implemented for dx10");
#else	//	USE_DX10
	ID3DVertexBuffer*	pVB=0;
	ID3DIndexBuffer*	pIB=0;
	p_cnt				= _p_cnt;
	p_type				= _pt;
	v_cnt				= _v_cnt;
	i_cnt				= _i_cnt;
	u32 stride			= D3DXGetFVFVertexSize(FVF);
	R_CHK(HW.pDevice->CreateVertexBuffer(v_cnt*stride, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &pVB, 0));
	u8* 				bytes;
	R_CHK				(pVB->Lock(0,0,(LPVOID*)&bytes,0));
	FLvertexVec	verts	(v_cnt);
	for (u32 k=0; k<v_cnt; ++k)
		verts[k].set	(((Fvector*)vertices)[k],0xFFFFFFFF);
	Memory.mem_copy		(bytes,&*verts.begin(),v_cnt*stride);
	R_CHK				(pVB->Unlock());
	if (i_cnt){ 
		R_CHK(HW.pDevice->CreateIndexBuffer(i_cnt*sizeof(u16),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_MANAGED,&pIB,NULL));
		R_CHK			(pIB->Lock(0,0,(LPVOID*)&bytes,0));
		Memory.mem_copy	(bytes,indices,i_cnt*sizeof(u16));
		R_CHK			(pIB->Unlock());
		OnRender.bind	(this,&SPrimitiveBuffer::RenderDIP);
	}else{
		OnRender.bind	(this,&SPrimitiveBuffer::RenderDP);
	}
	pGeom.create		(FVF,pVB,pIB);
#endif	//	USE_DX10
}
BOOL DoInit(HWND hWnd)
{
  // Initialize Direct3D
  InitD3D(&g_pD3D, &g_pD3DDevice, hWnd);

  // Load a skeletal mesh
  LoadMesh(&g_Mesh, &g_Frame, g_pD3DDevice, "..\\Data\\tiny.x", "..\\Data\\");

  // Get the bounding radius of the object
  g_MeshRadius = 0.0f;
  D3DXMESHCONTAINER_EX *pMesh = g_Mesh;
  while(pMesh) {

    // Lock the vertex buffer, get its radius, and unlock buffer
    if(pMesh->MeshData.pMesh) {
      D3DXVECTOR3 *pVertices, vecCenter;
      float Radius;
      pMesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&pVertices);
      D3DXComputeBoundingSphere(pVertices, 
                                pMesh->MeshData.pMesh->GetNumVertices(),
                                D3DXGetFVFVertexSize(pMesh->MeshData.pMesh->GetFVF()),
                                &vecCenter, &Radius);
      pMesh->MeshData.pMesh->UnlockVertexBuffer();

      // Update radius
      if(Radius > g_MeshRadius)
        g_MeshRadius = Radius;
    }

    // Go to next mesh
    pMesh = (D3DXMESHCONTAINER_EX*)pMesh->pNextMeshContainer;
  }

  return TRUE;
}
示例#5
0
//---------------------------------------------------------------------------------
// Name: ComputeBoundingBox
// Desc: 
// pMin:[out] Pointer to a D3DXVECTOR3 structure, describing the returned lower-left 
// corner of the bounding box. See Remarks. 
// pMax:[out] Pointer to a D3DXVECTOR3 structure, describing the returned upper-right 
// corner of the bounding box. See Remarks.
//---------------------------------------------------------------------------------
FLOAT CD3DMesh::ComputeBoundingBox(D3DXVECTOR3 *pMin, D3DXVECTOR3 *pMax )
{
	HRESULT hr;
	 // Lock the vertex buffer, to generate a simple bounding sphere
	LPDIRECT3DVERTEXBUFFER9 pMeshVB   = NULL;

	hr = m_pSysMemMesh->GetVertexBuffer( &pMeshVB );
    if( SUCCEEDED(hr) )
    {
		VOID *       pVertices;
        hr = pMeshVB->Lock( 0, 0, &pVertices, D3DLOCK_NOSYSLOCK );
        if( SUCCEEDED(hr) )
        {
            hr = D3DXComputeBoundingBox( (D3DXVECTOR3 *)pVertices, 
                                            m_pSysMemMesh->GetNumVertices(),
                                            D3DXGetFVFVertexSize(m_pSysMemMesh->GetFVF()),
                                            pMin,
											pMax);
            pMeshVB->Unlock();
        }
        pMeshVB->Release();
    }
    if( FAILED(hr) )
		return 0;   
	return 1;
}
示例#6
0
////////////////////////////////////////////////////////////////////////
///
/// Calculates the bounding sphere. 
///
/// @return true if the bounding sphere was properly calculated
///
////////////////////////////////////////////////////////////////////////
const VCNBool VCNDXMesh::ComputeBoundingSphere(ID3DXMesh* d3dMesh)
{
  D3DXVECTOR3 center;
  float radius;
  DWORD numVertices = d3dMesh->GetNumVertices();
  DWORD fvfSize = D3DXGetFVFVertexSize( d3dMesh->GetFVF() );
  char* pData = NULL;
  if ( FAILED( d3dMesh->LockVertexBuffer( 0, (void**)&pData ) ) )
  {
    VCN_ASSERT_FAIL( VCNTXT("Failed to lock mesh vertex buffer.") );
    return false;
  }
  D3DXComputeBoundingSphere( (D3DXVECTOR3*)pData, numVertices, fvfSize, &center, &radius );
  mBoundingSphere = VCNSphere(radius, V2V<Vector3>(center));


  // ***Hack use same flow as Bounding sphere
  D3DXVECTOR3 aabbMin, aabbMax;
  D3DXComputeBoundingBox((D3DXVECTOR3*)pData, numVertices, fvfSize, &aabbMin, &aabbMax);
  mBoundingAabb = VCNAabb(V2V<Vector3>(aabbMin), V2V<Vector3>(aabbMax));
  if ( FAILED( d3dMesh->UnlockVertexBuffer() ) )
  {
	  VCN_ASSERT_FAIL( VCNTXT("Failed to unlock mesh vertex buffer.") );
	  return false;
  } 

  return true;
}
示例#7
0
HRESULT InitSphere(LPDIRECT3DDEVICE9 pDevice, THING* pThing, float collisiondif)
{
	HRESULT hr = NULL;
	LPDIRECT3DVERTEXBUFFER9 pVB = NULL;
	VOID* pVertices = NULL;
	D3DXVECTOR3 vecCenter;
	FLOAT fRadius;

	//メッシュの頂点バッファーをロックする
	if (FAILED(pThing->pMesh->GetVertexBuffer(&pVB)))
	{
		return E_FAIL;
	}
	if (FAILED(pVB->Lock(0, 0, &pVertices, 0)))
	{
		SAFE_RELEASE(pVB);
		return E_FAIL;
	}
	//3Dモデルの中心座標を取得する。
	// メッシュの外接円の中心と半径を計算する
	hr = D3DXComputeBoundingSphere((D3DXVECTOR3*)pVertices, pThing->pMesh->GetNumVertices(),
		D3DXGetFVFVertexSize(pThing->pMesh->GetFVF()), &vecCenter,
		&fRadius);
	fRadius += collisiondif;
	//vecCenter.z += senterdif;
	pVB->Unlock();
	SAFE_RELEASE(pVB);

	if (FAILED(hr))
	{
		return hr;
	}
	pThing->Sphere.vecCenter = vecCenter;
	pThing->Sphere.fRadius = fRadius;
	// 得られた中心と半径を基にメッシュとしてのスフィアを作成する
	hr = D3DXCreateSphere(pDevice, fRadius, 24, 24, &pThing->pSphereMesh, NULL);
	if (FAILED(hr))
	{
		return hr;
	}
	//スフィアメッシュのマテリアル 白色、半透明、光沢強
	pThing->pSphereMeshMaterials = new D3DMATERIAL9;
	pThing->pSphereMeshMaterials->Diffuse.r = 1.0f;
	pThing->pSphereMeshMaterials->Diffuse.g = 1.0f;
	pThing->pSphereMeshMaterials->Diffuse.b = 1.0f;
	pThing->pSphereMeshMaterials->Diffuse.a = 0.5f;
	pThing->pSphereMeshMaterials->Ambient = pThing->pSphereMeshMaterials->Diffuse;
	pThing->pSphereMeshMaterials->Specular.r = 1.0f;
	pThing->pSphereMeshMaterials->Specular.g = 1.0f;
	pThing->pSphereMeshMaterials->Specular.b = 1.0f;
	pThing->pSphereMeshMaterials->Emissive.r = 0.1f;
	pThing->pSphereMeshMaterials->Emissive.g = 0.1f;
	pThing->pSphereMeshMaterials->Emissive.b = 0.1f;
	pThing->pSphereMeshMaterials->Power = 120.0f;

	return S_OK;
}
示例#8
0
HRESULT CMyD3DApplication::DrawMeshData(SMeshData *pMeshData)
{
    HRESULT hr;
    DWORD iCurFace;

    // Set and draw each of the materials in the mesh
    for( DWORD iMaterial=0; iMaterial < m_dwNumMaterials; iMaterial++ )
    {
        m_pd3dDevice->SetMaterial( &m_pMeshMaterials[iMaterial] );
        m_pd3dDevice->SetTexture( 0, m_pMeshTextures[iMaterial] );

        if( !m_bShowStrips && !m_bShowSingleStrip)
        {
            pMeshData->m_pMesh->DrawSubset( iMaterial );
        }
        else  // drawing strips
        {
            DWORD dwFVF;
            DWORD cBytesPerVertex;
            DWORD iStrip;

            dwFVF = pMeshData->m_pMesh->GetFVF();
            cBytesPerVertex = D3DXGetFVFVertexSize(dwFVF);

            m_pd3dDevice->SetVertexShader(dwFVF);
            m_pd3dDevice->SetStreamSource(0, pMeshData->m_pVertexBuffer, cBytesPerVertex);

            if(m_bShowSingleStrip)
            {
                m_pd3dDevice->SetIndices(pMeshData->m_rgStripData[iMaterial].m_pStrips, 0);

                hr = m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 
                                             0, pMeshData->m_pMesh->GetNumVertices(),
                                             0, pMeshData->m_rgStripData[iMaterial].m_cStripIndices - 2);
                if (FAILED(hr))
                    return hr;
            }
            else
            {
                m_pd3dDevice->SetIndices(pMeshData->m_rgStripData[iMaterial].m_pStripsMany, 0);

                iCurFace = 0;
                for (iStrip = 0; iStrip < pMeshData->m_rgStripData[iMaterial].m_cStrips; iStrip++)
                {
                    hr = m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 
                                                 0, pMeshData->m_pMesh->GetNumVertices(),
                                                 iCurFace, pMeshData->m_rgStripData[iMaterial].m_rgcStripLengths[iStrip]);
                    if (FAILED(hr))
                        return hr;
                iCurFace += 2 + pMeshData->m_rgStripData[iMaterial].m_rgcStripLengths[iStrip];
                }
            }
        }
    }

    return S_OK;
}
示例#9
0
// 进入循环之前的设置
bool SetUp()
{
	HRESULT hr = 0;
	hr = D3DXCreateTeapot(g_pDevice, &g_pTeapot,NULL);
	if (FAILED(hr))
	{
		MessageBox(0, "Create teapot failed!", 0, 0);
		return false;
	}

	BYTE* v = NULL;
	g_pTeapot->LockVertexBuffer(0, (void**)&v);
	hr = D3DXComputeBoundingSphere(
		(D3DXVECTOR3*)v,
		g_pTeapot->GetNumVertices(),
		D3DXGetFVFVertexSize(g_pTeapot->GetFVF()),
		&g_BSephere._center,
		&g_BSephere._radius
		);

	g_pTeapot->UnlockVertexBuffer();

	if (FAILED(hr))
	{
		MessageBox(0, "Compute Sephere failed!", 0, 0);
		return false;
	}
	hr = D3DXCreateSphere(g_pDevice, g_BSephere._radius, 20, 20, &g_pSephere, NULL);
	if (FAILED(hr))
	{
		MessageBox(0, "Create Sephere failed!", 0, 0);
		return false;
	}

	D3DXVECTOR3 dir(0.707f, -0.0f, 0.707f);
	D3DLIGHT9 light = d3d9::InitDirLight(&dir, &d3d9::WHITE_COLOR);

	g_pDevice->SetLight(0, &light);
	g_pDevice->LightEnable(0, true); 
	g_pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	g_pDevice->SetRenderState(D3DRS_SPECULARENABLE, false);

	D3DXVECTOR3 pos(0.0f, 0.0f, -10.0f);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);

	D3DXMATRIX view;
	D3DXMatrixLookAtLH(&view, &pos, &target, &up);
	g_pDevice->SetTransform(D3DTS_VIEW, &view);

	// 竖直视角,宽/高比,近裁剪面,远裁剪面
	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI*0.25f, (float)Width / (float)Height, 1.0f, 1000.0f);
	g_pDevice->SetTransform(D3DTS_PROJECTION, &proj);

	return true;
}
示例#10
0
BOOL RenderPick::Init(UINT width, UINT height, HWND hwnd, BOOL windowed, D3DDEVTYPE devType) {
    HRESULT hr = Render::Init(width, height, hwnd, windowed, devType);
    SGL_FAILED_DO(hr, MYTRACE_DX("Render::Init", hr); return FALSE);

    // Create the teapot.
    ID3DXMesh* teapot;
    D3DXCreateTeapot(m_D3DDev, &teapot, NULL);
    m_Teapot.Attach(teapot);

    // Compute the bounding sphere.
    BYTE* v = 0;
    teapot->LockVertexBuffer(0, (void**) &v);

    D3DXComputeBoundingSphere((D3DXVECTOR3*) v, teapot->GetNumVertices(), D3DXGetFVFVertexSize(teapot->GetFVF()), &m_BSphere.center, &m_BSphere.radius);
    teapot->UnlockVertexBuffer();

    // Build a sphere mesh that describes the teapot's bounding sphere.
    ID3DXMesh* sphere;
    D3DXCreateSphere(m_D3DDev, m_BSphere.radius, 20, 20, &sphere, NULL);
    m_Sphere.Attach(sphere);

    // Set light.
    D3DXVECTOR3 dir(0.707f, -0.0f, 0.707f);
    D3DXCOLOR clr(1.0f, 1.0f, 1.0f, 1.0f);
    D3DLIGHT9 light;
    SGL::InitDirLight(&light, dir, clr);

    m_D3DDev->SetLight(0, &light);
    m_D3DDev->LightEnable(0, TRUE);
    m_D3DDev->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
    m_D3DDev->SetRenderState(D3DRS_SPECULARENABLE, FALSE);

    // Set view matrix.
    D3DXVECTOR3 pos(0.0f, 0.0f, -10.0f);
    D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);

    D3DXMATRIX V;
    D3DXMatrixLookAtLH(&V, &pos, &target, &up);
    m_D3DDev->SetTransform(D3DTS_VIEW, &V);

    // Set projection matrix.
    D3DXMATRIX proj;
    D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI * 0.25f, (float) width / (float) height, 1.0f, 1000.0f);
    m_D3DDev->SetTransform(D3DTS_PROJECTION, &proj);

    // Setup a basic scene.
    m_BasicScene.reset(new BasicScene(m_D3DDev));
    if (!m_BasicScene->Init())
        return FALSE;

    if (!InitFont())
        return FALSE;

    return TRUE;
}
示例#11
0
//=============================================================================
// PRIVATE FUNCTIONS
//=============================================================================
static physx::unique_ptr<PxConvexMesh> GenerateConvexFromDXMesh(PxPhysics &iPhysics, ID3DXMesh *iMesh)
{
	//Used to retrieve information from X file
	struct Mesh_FVF {
		D3DXVECTOR3 VertexPos;
		D3DXVECTOR3 Normal;
		D3DXVECTOR2 TexCoord;
	};

	int aNumVerticies = iMesh->GetNumVertices();
	DWORD FVFSize = D3DXGetFVFVertexSize(iMesh->GetFVF());

	//Create pointer for vertices
	PxVec3* verts = new PxVec3[aNumVerticies];

	char *DXMeshPtr;
	iMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&DXMeshPtr);
	for(int i = 0; i < aNumVerticies; i++)
	{
		Mesh_FVF *DXMeshFVF = (Mesh_FVF*)DXMeshPtr;
		verts[i] = PxVec3(DXMeshFVF->VertexPos.x, DXMeshFVF->VertexPos.y, DXMeshFVF->VertexPos.z);
		DXMeshPtr += FVFSize;
	}
	iMesh->UnlockVertexBuffer();

	// Create descriptor for convex mesh
	PxConvexMeshDesc convexDesc;
	convexDesc.points.count		= aNumVerticies;
	convexDesc.points.stride	= sizeof(PxVec3);
	convexDesc.points.data		= verts;
	convexDesc.flags			= PxConvexFlag::eCOMPUTE_CONVEX;

	PxTolerancesScale toleranceScale;
	toleranceScale.length = 1.0f;
	toleranceScale.mass = 1000.0f;
	toleranceScale.speed = 9.8f;

	assert(toleranceScale.isValid());

	physx::unique_ptr<PxCooking> cooker = physx::unique_ptr<PxCooking>(
		PxCreateCooking(PX_PHYSICS_VERSION, iPhysics.getFoundation(), PxCookingParams(toleranceScale))
		);

	// Cooking from memory
	MemoryStream buf;
	physx::unique_ptr<PxConvexMesh> convexMesh;
	if(cooker->cookConvexMesh(convexDesc, buf))
	{
		convexMesh = physx::unique_ptr<PxConvexMesh>(iPhysics.createConvexMesh(buf));
	}	

	delete[] verts;

	return convexMesh;
}
示例#12
0
void VertexObject::ReculcBounds()
{
	D3DXVECTOR3 Ul;
	D3DXVECTOR3 Lr;
	GAMVERTEX* c_vertices;
	vertex_bufer->Lock( 0, 0, (void**)&c_vertices, 0 );
	D3DXComputeBoundingBox(&c_vertices[0].p, vertex_count, D3DXGetFVFVertexSize(D3DFVF_MESHVERTEX), &Lr, &Ul);
	vertex_bufer->Unlock();
	//RecalcMatrixGlobal();
	bounds.SetBounds(Lr, Ul);
	bounds.SetTransformByMatrix(GetMatrxGlobalTransform());
}
示例#13
0
void computeBoundingBox(ID3DXMesh *mesh, BoundingBox *box)
{
	BYTE *_data;
	mesh->LockVertexBuffer(0, reinterpret_cast<void **>(&_data));
	D3DXComputeBoundingBox(
		reinterpret_cast<D3DXVECTOR3 *>(_data), 
		mesh->GetNumVertices(), 
		D3DXGetFVFVertexSize(mesh->GetFVF()), 
		&box->min, 
		&box->max);
	mesh->UnlockVertexBuffer();
}
示例#14
0
void computeBoundingSphere(ID3DXMesh *mesh, BoundingSphere *sphere)
{
	BYTE *_data;
	mesh->LockVertexBuffer(0, reinterpret_cast<void **>(&_data));
	D3DXComputeBoundingSphere(
		reinterpret_cast<D3DXVECTOR3 *>(_data), 
		mesh->GetNumVertices(), 
		D3DXGetFVFVertexSize(mesh->GetFVF()), 
		&sphere->center, 
		&sphere->radius);
	mesh->UnlockVertexBuffer();
}
示例#15
0
CModelX::CModelX(LPDIRECT3DDEVICE9 device, char* filename):CModel()
{
	m_device = device; 
	//m_posX = m_posY = m_posZ = 0;
	//m_scaleX = m_scaleY = m_scaleZ = 1.0f;
	//m_rotateX = m_rotateY = m_rotateZ = 0.0f;
	int64 mseconds = getTime()->GetTotalMillSeconds();
	if(FAILED(D3DXLoadMeshFromX(filename, D3DXMESH_SYSTEMMEM,
		m_device, NULL, &m_matBuffer, NULL,
		&m_numMaterials, &m_model))) 
	{
		MessageBox(NULL, "加载Model.x失败!",TEXT("提示"),MB_OK);
		getLog()->BeginLog();
		getLog()->Log(log_allert, "加载模型%s失败!",filename);
		getLog()->EndLog();
		return ;
	}
	getLog()->BeginLog();
	getLog()->Log(log_ok, "加载模型%s成功!用时:%dms",filename, getTime()->GetTotalMillSeconds() - mseconds);
	getLog()->EndLog();
	m_matList = new D3DMATERIAL9[m_numMaterials];
	m_textureList  = new LPDIRECT3DTEXTURE9[m_numMaterials];
	D3DXMATERIAL* mat = (D3DXMATERIAL*)m_matBuffer->GetBufferPointer();

	// Loop and load each textture and get each material.
	for(DWORD i = 0; i < m_numMaterials; i++)
	{
		// Copy the materials from the buffer into our list.
		m_matList[i] = mat[i].MatD3D;

		// Load the textures into the list.
		if(FAILED(D3DXCreateTextureFromFile(m_device,
			mat[i].pTextureFilename,
			&m_textureList[i]))) 
			m_textureList[i] = NULL;
	}
	unsigned char * data;
	m_model->LockVertexBuffer( D3DLOCK_READONLY, (LPVOID*)&data );
	D3DXVECTOR3 center;
	memcpy(&center, &m_iniBall.m_center, sizeof(D3DXVECTOR3));
	D3DXComputeBoundingSphere((D3DXVECTOR3 *)data,m_model->GetNumVertices(), D3DXGetFVFVertexSize(m_model->GetFVF()), 
		&center, &m_iniBall.m_radius);
	m_model->UnlockVertexBuffer();
	m_referBall = m_iniBall;
	m_referBall.m_radius =	m_iniBall.m_radius * BALL_SCALE; //稍微缩放,提高精度
	m_ball = m_referBall;

#ifdef DEX_DEBGU
	D3DXCreateSphere(m_device, m_ball.m_radius, 20, 20, &m_sphere, NULL);
#endif

}
示例#16
0
//
// MeshNode::CalcBoundingSphere				-  3rd Edition, Chapter 14, page 507
//
float D3DMeshNode9::CalcBoundingSphere()
{
    D3DXVECTOR3* pData;
    D3DXVECTOR3 vCenter;
    FLOAT fObjectRadius;
	HRESULT hr;
	V( m_pMesh->LockVertexBuffer( 0, ( LPVOID* )&pData ) );
    V( D3DXComputeBoundingSphere( pData, m_pMesh->GetNumVertices(),
                                  D3DXGetFVFVertexSize( m_pMesh->GetFVF() ), &vCenter, &fObjectRadius ) );
    V( m_pMesh->UnlockVertexBuffer() );

	return fObjectRadius;
}
示例#17
0
	void AABB::MakeAABB(iexMesh* lpMesh){

	//	情報取得	
	u32 fvf = lpMesh->GetMesh()->GetFVF();
	
	//	頂点サイズ計算
	int VertexSize = D3DXGetFVFVertexSize(fvf) / sizeof(float);

	//	バッファロック
	float	*pVertices;
	lpMesh->GetMesh()->LockVertexBuffer( D3DLOCK_READONLY, (void**)&pVertices );
	

	Vector pos;
	int a;
	Vector3 localmax(0,0,0);
	Vector3 localmin(0,0,0);

	for(unsigned int i=0; i<lpMesh->GetMesh()->GetNumVertices(); i++){
		a = i*3;
		pos.x = pVertices[a];
		pos.y = pVertices[a+1];
		pos.z = pVertices[a+2];

		if(pos.x > localmax.x) localmax.x = pos.x;
		if(pos.x < localmin.x) localmin.x = pos.x;

		if(pos.y > localmax.y) localmax.y = pos.y;
		if(pos.y < localmin.y) localmin.y = pos.y;

		if(pos.z > localmax.z) localmax.z = pos.z;
		if(pos.z < localmin.z) localmin.z = pos.z;
	}

	//Matrix mat = lpMesh->TransMatrix;
	//D3DXMatrixInverse( &mat, NULL, &mat );
	//Vector3 local_min,local_max;

	//m_max = Matrix3CrossMatrix4(m_max, mat);
	//m_min = Matrix3CrossMatrix4(m_min, mat);

	m_center.x = (localmax.x+localmin.x)*0.5f;
	m_center.y = (localmax.y+localmin.y)*0.5f;
	m_center.z = (localmax.y+localmin.y)*0.5f;

	m_half.x = (localmax.x - m_half.x) + 0.1f;
	m_half.y = (localmax.y - m_half.y) + 0.1f;
	m_half.z = (localmax.z - m_half.z) + 0.1f;

	lpMesh->GetMesh()->UnlockVertexBuffer();
	}
bool CXMesh::PickPoly(D3DXVECTOR3* PickRayOrig, D3DXVECTOR3* PickRayDir)
{
	if(!m_BlendedMesh) return false;

	HRESULT res;

	DWORD FvfSize = D3DXGetFVFVertexSize(m_BlendedMesh->GetFVF());
	DWORD NumVertices = m_BlendedMesh->GetNumVertices();
	DWORD NumFaces = m_BlendedMesh->GetNumFaces();

	// lock vertex buffer
	BYTE* Points = NULL;
	res = m_BlendedMesh->LockVertexBufferUni(D3DLOCK_READONLY, &Points);
	if (FAILED(res)) return false;

	// lock index buffer
	WORD* Indices;
	res = m_BlendedMesh->LockIndexBufferUni(D3DLOCK_READONLY, &Indices);
	if (FAILED(res))
	{
		m_BlendedMesh->UnlockVertexBuffer();
		return false;
	}


	bool Found = false;
	D3DXVECTOR3 Intersection;

	for(DWORD i=0; i<NumFaces; i++)
	{
		WORD i1, i2, i3;
		i1 = Indices[3*i+0];
		i2 = Indices[3*i+1];
		i3 = Indices[3*i+2];

		D3DXVECTOR3 v0 = *(D3DXVECTOR3*)(Points + Indices[3*i+0] * FvfSize);
		D3DXVECTOR3 v1 = *(D3DXVECTOR3*)(Points + Indices[3*i+1] * FvfSize);
		D3DXVECTOR3 v2 = *(D3DXVECTOR3*)(Points + Indices[3*i+2] * FvfSize);

		if(_isnan(v0.x)) continue;

		Found = C3DUtils::IntersectTriangle(*PickRayOrig, *PickRayDir, v0, v1, v2, &Intersection.x, &Intersection.y, &Intersection.z) != FALSE;
		if(Found) break;
	}

	m_BlendedMesh->UnlockVertexBuffer();
	m_BlendedMesh->UnlockIndexBuffer();

	return Found;
}
示例#19
0
void DefaultBullet::Initialize()
{
	// build bounding box for the mesh
	BYTE* vertices = NULL;
	Initializer::GetInstance()->GetDefaultBulletMesh().mesh->LockVertexBuffer(
		D3DLOCK_READONLY, (LPVOID*)&vertices);

	D3DXComputeBoundingBox((D3DXVECTOR3*)vertices, 
		Initializer::GetInstance()->GetDefaultBulletMesh().mesh->GetNumVertices(),
		D3DXGetFVFVertexSize(
		Initializer::GetInstance()->GetDefaultBulletMesh().mesh->GetFVF()), 
		&meshBox.minPt, &meshBox.maxPt);

	Initializer::GetInstance()->GetDefaultBulletMesh().mesh->UnlockVertexBuffer();
}
示例#20
0
void GameObject::SetMesh( CMesh3D* pMesh )
{ 
	if( pMesh )
	{
		m_pMeshObject = pMesh;
		if( ID3DXMesh* Mesh = pMesh->GetMesh() )
		{
			m_BufVertices.clear();			
			DWORD stride = D3DXGetFVFVertexSize( Mesh->GetFVF() );
			BYTE* vbptr  = 0;
			Mesh->LockVertexBuffer( 0, (LPVOID*)&vbptr );
			int ii = -1;
			m_dwNumVertices = Mesh->GetNumVertices();

			for( DWORD i = 0; i < m_dwNumVertices; ++i )
			{
				ii++;
				D3DXVECTOR3* pos = (D3DXVECTOR3*)vbptr;
				m_BufVertices.push_back( pos->x );
				m_BufVertices.push_back( pos->y );
				m_BufVertices.push_back( pos->z );
				vbptr += stride;
			}

			Mesh->UnlockVertexBuffer();

			LPVOID* ppData = 0;
			stride = sizeof( short );
			BYTE* ibptr = 0;
			m_dwNumNumFaces = Mesh->GetNumFaces();
			short* indices = new short[ m_dwNumNumFaces * 3 ];
			m_BufIndices.clear();			

			Mesh->LockIndexBuffer( 0, (LPVOID*)&indices );
			for( DWORD i = 0; i < m_dwNumNumFaces * 3; ++i )
			{
				m_BufIndices.push_back( indices[ i ] );
			}

			Mesh->UnlockIndexBuffer();			
		}
	}
}
bool ComputeBoundingBox(ID3DXMesh* mesh, byhj::BoundingBox* box)
{
	HRESULT hr = 0;

	BYTE* v = 0;
	mesh->LockVertexBuffer(0, (void**)&v);

	hr = D3DXComputeBoundingBox(
		(D3DXVECTOR3*)v,
		mesh->GetNumVertices(),
		D3DXGetFVFVertexSize(mesh->GetFVF()),
		&box->_min,
		&box->_max);

	mesh->UnlockVertexBuffer();

	if( FAILED(hr) )
		return false;

	return true;
}
bool ComputeBoundingSphere(ID3DXMesh* mesh, byhj::BoundingSphere* sphere)
{
	HRESULT hr = 0;

	BYTE* v = 0;
	mesh->LockVertexBuffer(0, (void**)&v);

	hr = D3DXComputeBoundingSphere(
		(D3DXVECTOR3*)v,
		mesh->GetNumVertices(),
		D3DXGetFVFVertexSize(mesh->GetFVF()),
		&sphere->_center,
		&sphere->_radius);

	mesh->UnlockVertexBuffer();

	if( FAILED(hr) )
		return false;

	return true;
}
示例#23
0
CSFObject::CSFObject(LPCWSTR Model, D3DXVECTOR3 Position)
{
	MeshId = sCore.GenerateMeshId();

	D3DXLoadMeshFromX(Model,    // load this file
                      D3DXMESH_SYSTEMMEM,    // load the mesh into system memory
                      sCore.DeviceHandler(),    // the Direct3D Device
                      NULL,    // we aren't using adjacency
                      &bufMaterial,    // 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*)bufMaterial->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...
    {
        material[i] = tempMaterials[i].MatD3D;    // get the material info
        material[i].Ambient = material[i].Diffuse;    // make ambient the same as diffuse
        USES_CONVERSION;    // allows certain string conversions
        // if there is a texture to load, load it
        if(FAILED(D3DXCreateTextureFromFile(sCore.DeviceHandler(),
                                            CA2W(tempMaterials[i].pTextureFilename),
                                            &texture[i])))
			texture[i] = NULL;    // if there is no texture, set the texture to NULL
      }
	BYTE *v = NULL;
	HR(mesh->LockVertexBuffer(0, (LPVOID*)&v));
	HR(D3DXComputeBoundingBox((D3DXVECTOR3*)v, mesh->GetNumVertices(), 
		D3DXGetFVFVertexSize(mesh->GetFVF()), &bb.minPt, &bb.maxPt));
	HR(mesh->UnlockVertexBuffer());
	Pos = Position;
	Orientation = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	Scaler = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
}
void DrawMorphMesh(D3DXMESHCONTAINER_EX *SourceMesh,
                   D3DXMESHCONTAINER_EX *TargetMesh,
                   float Scalar)
{
  // Get the world, view, and projection matrices
  D3DXMATRIX matWorld, matView, matProj;
  g_pD3DDevice->GetTransform(D3DTS_WORLD, &matWorld);
  g_pD3DDevice->GetTransform(D3DTS_VIEW, &matView);
  g_pD3DDevice->GetTransform(D3DTS_PROJECTION, &matProj);

  // Get the world*view*proj matrix and set it
  D3DXMATRIX matWVP;
  matWVP = matWorld * matView * matProj;
  D3DXMatrixTranspose(&matWVP, &matWVP);
  g_pD3DDevice->SetVertexShaderConstantF(0, (float*)&matWVP, 4);

  // Set the scalar value to use
  g_pD3DDevice->SetVertexShaderConstantF(4, (float*)&D3DXVECTOR4(1.0f-Scalar, Scalar, 0.0f, 0.0f), 1);

  // Set the light direction (convert from model space to view space)
  D3DXMATRIX matInvWorld;
  D3DXMatrixInverse(&matInvWorld, NULL, &matWorld);
  D3DXVECTOR3 vecLight = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
  D3DXVec3TransformCoord(&vecLight, &vecLight, &matInvWorld);
  g_pD3DDevice->SetVertexShaderConstantF(5, (float*)&D3DXVECTOR4(vecLight.x, vecLight.y, vecLight.z, 0.0f), 1);

  // Set the 2nd stream source
  IDirect3DVertexBuffer9 *pVB = NULL;
  TargetMesh->MeshData.pMesh->GetVertexBuffer(&pVB);
  g_pD3DDevice->SetStreamSource(1, pVB, 0, D3DXGetFVFVertexSize(TargetMesh->MeshData.pMesh->GetFVF()));

  // Draw the mesh in the vertex shader
  DrawMesh(SourceMesh, g_VS, g_Decl);

  // Clear the 2nd stream source and free the vertex buffer interface
  g_pD3DDevice->SetStreamSource(1, NULL, 0, 0);
  ReleaseCOM(pVB);
}
示例#25
0
float iexMesh::Length_of_furthest_point()
{
	//	情報取得	
	u32 fvf = lpMesh->GetFVF();
	//	頂点サイズ計算
	int vertexSize = D3DXGetFVFVertexSize( fvf ) / sizeof( float );
	//	バッファロック
	float	*pVertices;
	u32 numVertices = lpMesh->GetNumVertices();
	lpMesh->LockVertexBuffer( D3DLOCK_READONLY, ( void** ) &pVertices );

	float length( 0 );
	Vector3 vertex( 0, 0, 0 );
	for( u32 index = 0; index < numVertices; index += 3 )
	{
		vertex.x = pVertices[index] * vertexSize; vertex.y = pVertices[index + 1] * vertexSize; vertex.z = pVertices[index + 2] * vertexSize;
		length = max( length, vertex.LengthSq() );
	}

	lpMesh->UnlockVertexBuffer();

	return sqrtf( length );
}
示例#26
0
bool XMeshData::Init(const std::wstring& FilePath) {
    Node::Init();

    // 재질을 임시로 보관할 버퍼선언
    LPD3DXBUFFER pD3DXMtrlBuffer;

    mEffect = ResourceManager::GetInstance()->LoadHLSL(L"Shader\\SkinnedMesh.fx");
    if (!mEffect) {
        MessageBox(NULL, L"Could not HLSL file", L"ERROR", MB_OK);
        assert(false);
        return false;
    }

    if (FAILED(D3DXLoadMeshFromX(FilePath.c_str(), D3DXMESH_SYSTEMMEM,
                                 GetDevice(), NULL,
                                 &pD3DXMtrlBuffer, NULL, &mNumMaterial,
                                 &mXMesh)))
    {
        MessageBox(NULL, L"Could not find mesh file", L"ERROR", MB_OK);
        return false;
    }

    // 재질정보와 텍스쳐 정보를 따로 뽑아낸다.
    D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    mMaterial = new D3DMATERIAL9[mNumMaterial];			// 재질개수만큼 재질구조체 배열 생성
    mTexture = new LPDIRECT3DTEXTURE9[mNumMaterial];	// 재질개수만큼 텍스쳐 배열 생성

    for (DWORD j = 0; j<mNumMaterial; j++) {
        // 재질정보를 복사
        mMaterial[j] = d3dxMaterials[j].MatD3D;

        // 주변광원정보를 Diffuse정보로
        mMaterial[j].Ambient = mMaterial[j].Diffuse;

        mTexture[j] = NULL;

        if (d3dxMaterials[j].pTextureFilename != NULL &&
                strlen(d3dxMaterials[j].pTextureFilename) > 0)
        {
            // 텍스쳐를 파일에서 로드한다
            // w로 통일할껀지 정해야함
            std::string FileName = "Model\\";
            FileName += d3dxMaterials[j].pTextureFilename;

            if (FAILED(D3DXCreateTextureFromFileA(GetDevice(),
                                                  FileName.c_str(),
                                                  &mTexture[j])))
            {
                MessageBox(NULL, L"Could not find texture map", L"ERROR", MB_OK);
                assert(false);

                return false;
            }
        }
    }
    SAFE_RELEASE( pD3DXMtrlBuffer );

    //메쉬에 법선백터를 추가하는 부분
    if (!(mXMesh->GetFVF() & D3DFVF_NORMAL)) {
        //가지고 있지 않다면 메쉬를 복제하고 D3DFVF_NORMAL을 추가한다.
        ID3DXMesh* pTempMesh = 0;

        mXMesh->CloneMeshFVF(D3DXMESH_MANAGED,
                             mXMesh->GetFVF() | D3DFVF_NORMAL,  //이곳에 추가
                             GetDevice(),
                             &pTempMesh);

        // 법선을 계산한다.
        D3DXComputeNormals(pTempMesh, 0);

        mXMesh->Release(); // 기존메쉬를 제거한다
        mXMesh = pTempMesh; // 기존메쉬를 법선이 계산된 메쉬로 지정한다.
    }

    // Init Vertices and Indices

    int VerticesNum = mXMesh->GetNumVertices();
    BYTE* vertexBuffer;
    DWORD numBytesPerVertex = mXMesh->GetNumBytesPerVertex();
    unsigned int offset = D3DXGetFVFVertexSize(mXMesh->GetFVF());

    mXMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&vertexBuffer);
    for (WORD i = 0; i < VerticesNum; i++)
        mVertices.push_back(*((D3DXVECTOR3*)(vertexBuffer + i * offset)));
    mXMesh->UnlockVertexBuffer();


    void *pIB;
    int IndicesNum = mXMesh->GetNumFaces();
    WORD *indexBuffer = new WORD[IndicesNum * 3];

    mXMesh->LockIndexBuffer(D3DLOCK_READONLY, (void**)&pIB);
    memcpy(indexBuffer, pIB, sizeof(WORD)*IndicesNum * 3);

    for (int i = 0; i < IndicesNum; ++i)
        mIndices.push_back(D3DXVECTOR3(indexBuffer[i * 3], indexBuffer[i * 3 + 1], indexBuffer[i * 3 + 2]));

    mXMesh->UnlockIndexBuffer();
    delete[]indexBuffer;

    return true;
}
示例#27
0
文件: mesh.c 项目: bilboed/wine
static void D3DXComputeBoundingBoxTest(void)
{
    D3DXVECTOR3 exp_max, exp_min, got_max, got_min, vertex[5];
    HRESULT hr;

    vertex[0].x = 1.0f; vertex[0].y = 1.0f; vertex[0].z = 1.0f;
    vertex[1].x = 1.0f; vertex[1].y = 1.0f; vertex[1].z = 1.0f;
    vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 1.0f;
    vertex[3].x = 1.0f; vertex[3].y = 1.0f; vertex[3].z = 1.0f;
    vertex[4].x = 9.0f; vertex[4].y = 9.0f; vertex[4].z = 9.0f;

    exp_min.x = 1.0f; exp_min.y = 1.0f; exp_min.z = 1.0f;
    exp_max.x = 9.0f; exp_max.y = 9.0f; exp_max.z = 9.0f;

    hr = D3DXComputeBoundingBox(&vertex[3],2,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,&got_max);

    ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
    ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
    ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);

/*________________________*/

    vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
    vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
    vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
    vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
    vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;

    exp_min.x = -6.92f; exp_min.y = -8.1f; exp_min.z = -3.80f;
    exp_max.x = 11.4f; exp_max.y = 7.90f; exp_max.z = 11.9f;

    hr = D3DXComputeBoundingBox(&vertex[0],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,&got_max);

    ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
    ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
    ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);

/*________________________*/

    vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
    vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
    vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
    vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
    vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;

    exp_min.x = -6.92f; exp_min.y = -0.9f; exp_min.z = -3.8f;
    exp_max.x = 7.43f; exp_max.y = 7.90f; exp_max.z = 11.9f;

    hr = D3DXComputeBoundingBox(&vertex[0],4,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,&got_max);

    ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
    ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
    ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);

/*________________________*/
    hr = D3DXComputeBoundingBox(NULL,5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,&got_max);
    ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);

/*________________________*/
    hr = D3DXComputeBoundingBox(&vertex[3],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),NULL,&got_max);
    ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);

/*________________________*/
    hr = D3DXComputeBoundingBox(&vertex[3],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,NULL);
    ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
}
示例#28
0
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED)
// and aren't tied to the back buffer size
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
                                 void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D9CreateDevice( pd3dDevice ) );
    V_RETURN( g_SettingsDlg.OnD3D9CreateDevice( pd3dDevice ) );

    // Initialize the font
    V_RETURN( D3DXCreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
                              OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
                              L"Arial", &g_pFont ) );

    // Load the mesh
    V_RETURN( g_Mesh.Create( pd3dDevice, L"dwarf\\dwarf.x" ) );

    // Find the mesh's center, then generate a centering matrix.
    IDirect3DVertexBuffer9* pVB = NULL;
    V_RETURN( g_Mesh.m_pMesh->GetVertexBuffer( &pVB ) );

    void* pVertices = NULL;
    hr = pVB->Lock( 0, 0, &pVertices, 0 );
    if( FAILED( hr ) )
    {
        SAFE_RELEASE( pVB );
        return hr;
    }

    hr = D3DXComputeBoundingSphere( ( D3DXVECTOR3* )pVertices, g_Mesh.m_pMesh->GetNumVertices(),
                                    D3DXGetFVFVertexSize( g_Mesh.m_pMesh->GetFVF() ), &g_vObjectCenter,
                                    &g_fObjectRadius );

    pVB->Unlock();
    SAFE_RELEASE( pVB );

    if( FAILED( hr ) )
        return hr;

    D3DXMatrixTranslation( &g_mCenterWorld, -g_vObjectCenter.x, -g_vObjectCenter.y, -g_vObjectCenter.z );

    // Read the D3DX effect file
    TCHAR str[MAX_PATH];
    hr = DXUTFindDXSDKMediaFileCch( str, MAX_PATH, TEXT( "CompiledEffect.fxo" ) );
    if( FAILED( hr ) )
    {
        MessageBox( DXUTGetHWND(), TEXT( "Could not locate \"CompiledEffect.fxo\".\n\n" )
                                   TEXT( "This file is created as part of the project build process,\n" )
                                   TEXT( "so the associated project must be compiled inside Visual\n" )
                                   TEXT( "Studio before attempting to run this sample.\n\n" )
                                   TEXT( "If receiving this error even after compiling the project,\n" )
                                   TEXT( "it's likely there was a problem compiling the effect file.\n" )
                                   TEXT( "Check the build log to verify the custom build step was\n" )
                                   TEXT( "run and to look for possible fxc compile errors." ),
                                   TEXT( "File Not Found" ), MB_OK );
        return E_FAIL;
    }

    // Since we are loading a binary file here and this effect has already been compiled,
    // you can not pass compiler flags here (for example to debug the shaders). 
    // To debug the shaders, you must pass these flags to the compiler that generated the
    // binary (for example fxc.exe).  In this sample, there are 2 extra Visual Studio configurations
    // called "Debug Shaders" and "Unicode Debug Shaders" that pass the debug shader flags to fxc.exe.
    V_RETURN( D3DXCreateEffectFromFile( pd3dDevice, str, NULL, NULL, D3DXFX_NOT_CLONEABLE, NULL, &g_pEffect, NULL ) );

    // Setup the camera's view parameters
    D3DXVECTOR3 vecEye( 0.0f, 0.0f, -5.0f );
    D3DXVECTOR3 vecAt ( 0.0f, 0.0f, -0.0f );
    g_Camera.SetViewParams( &vecEye, &vecAt );

    return S_OK;
}
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED)
// and aren't tied to the back buffer size 
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
                                     void* pUserContext )
{
	MessageBox(0, L"We aren't using DirectX9", L"We aren't using DirectX9", 0);
	exit(1);
	
	HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D9CreateDevice( pd3dDevice ) );
    V_RETURN( g_D3DSettingsDlg.OnD3D9CreateDevice( pd3dDevice ) );

    // Initialize the font
    V_RETURN( D3DXCreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
                              OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
                              L"Arial", &g_pFont9 ) );

    // Load the mesh
    V_RETURN( LoadMesh( pd3dDevice, L"tiny\\tiny.x", &g_pMesh9 ) );

    D3DXVECTOR3* pData;
    D3DXVECTOR3 vCenter;
    FLOAT fObjectRadius;
    V( g_pMesh9->LockVertexBuffer( 0, ( LPVOID* )&pData ) );
    V( D3DXComputeBoundingSphere( pData, g_pMesh9->GetNumVertices(),
                                  D3DXGetFVFVertexSize( g_pMesh9->GetFVF() ), &vCenter, &fObjectRadius ) );
    V( g_pMesh9->UnlockVertexBuffer() );

    D3DXMatrixTranslation( &g_mCenterMesh, -vCenter.x, -vCenter.y, -vCenter.z );
    D3DXMATRIXA16 m;
    D3DXMatrixRotationY( &m, D3DX_PI );
    g_mCenterMesh *= m;
    D3DXMatrixRotationX( &m, D3DX_PI / 2.0f );
    g_mCenterMesh *= m;

    V_RETURN( CDXUTDirectionWidget::StaticOnD3D9CreateDevice( pd3dDevice ) );
    g_LightControl.SetRadius( fObjectRadius );

    // Read the D3DX effect file
    WCHAR str[MAX_PATH];
    DWORD dwShaderFlags = D3DXFX_NOT_CLONEABLE | D3DXSHADER_NO_PRESHADER | D3DXFX_LARGEADDRESSAWARE;
#ifdef DEBUG_VS
        dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT;
    #endif
#ifdef DEBUG_PS
        dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT;
    #endif
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"BasicHLSL.fx" ) );
    V_RETURN( D3DXCreateEffectFromFile( pd3dDevice, str, NULL, NULL, dwShaderFlags, NULL, &g_pEffect9, NULL ) );

    // Create the mesh texture from a file
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"tiny\\tiny_skin.dds" ) );

    V_RETURN( D3DXCreateTextureFromFileEx( pd3dDevice, str, D3DX_DEFAULT, D3DX_DEFAULT,
                                           D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
                                           D3DX_DEFAULT, D3DX_DEFAULT, 0,
                                           NULL, NULL, &g_pMeshTexture9 ) );

    // Set effect variables as needed
    D3DXCOLOR colorMtrlDiffuse( 1.0f, 1.0f, 1.0f, 1.0f );
    D3DXCOLOR colorMtrlAmbient( 0.35f, 0.35f, 0.35f, 0 );

    D3DXHANDLE hMaterialAmbientColor = g_pEffect9->GetParameterByName( NULL, "g_MaterialAmbientColor" );
    D3DXHANDLE hMaterialDiffuseColor = g_pEffect9->GetParameterByName( NULL, "g_MaterialDiffuseColor" );
    D3DXHANDLE hMeshTexture = g_pEffect9->GetParameterByName( NULL, "g_MeshTexture" );

    V_RETURN( g_pEffect9->SetValue( hMaterialAmbientColor, &colorMtrlAmbient, sizeof( D3DXCOLOR ) ) );
    V_RETURN( g_pEffect9->SetValue( hMaterialDiffuseColor, &colorMtrlDiffuse, sizeof( D3DXCOLOR ) ) );
    V_RETURN( g_pEffect9->SetTexture( hMeshTexture, g_pMeshTexture9 ) );

    g_hLightDir = g_pEffect9->GetParameterByName( NULL, "g_LightDir" );
    g_hLightDiffuse = g_pEffect9->GetParameterByName( NULL, "g_LightDiffuse" );
    g_hmWorldViewProjection = g_pEffect9->GetParameterByName( NULL, "g_mWorldViewProjection" );
    g_hmWorld = g_pEffect9->GetParameterByName( NULL, "g_mWorld" );
    g_hMaterialDiffuseColor = g_pEffect9->GetParameterByName( NULL, "g_MaterialDiffuseColor" );
    g_hfTime = g_pEffect9->GetParameterByName( NULL, "g_fTime" );
    g_hnNumLights = g_pEffect9->GetParameterByName( NULL, "g_nNumLights" );
    g_hRenderSceneWithTexture1Light = g_pEffect9->GetTechniqueByName( "RenderSceneWithTexture1Light" );
    g_hRenderSceneWithTexture2Light = g_pEffect9->GetTechniqueByName( "RenderSceneWithTexture2Light" );
    g_hRenderSceneWithTexture3Light = g_pEffect9->GetTechniqueByName( "RenderSceneWithTexture3Light" );

    // Setup the camera's view parameters
    D3DXVECTOR3 vecEye( 0.0f, 0.0f, -15.0f );
    D3DXVECTOR3 vecAt ( 0.0f, 0.0f, -0.0f );
    g_Camera.SetViewParams( &vecEye, &vecAt );
    g_Camera.SetRadius( fObjectRadius * 3.0f, fObjectRadius * 0.5f, fObjectRadius * 10.0f );

    return S_OK;
}
示例#30
0
文件: Face.cpp 项目: 7zhang/studies
void Face::Render(FaceController *pController) {
    if (m_pBaseMesh == NULL || pController == NULL)
        return;

    //Set Active Vertex Declaration
    g_pDevice->SetVertexDeclaration(m_pFaceVertexDecl);

    //Set streams
    D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE];
    m_pBaseMesh->GetDeclaration(decl);
    DWORD vSize = D3DXGetDeclVertexSize(decl, 0);
    IDirect3DVertexBuffer9* baseMeshBuffer = NULL;
    m_pBaseMesh->GetVertexBuffer(&baseMeshBuffer);
    g_pDevice->SetStreamSource(0, baseMeshBuffer, 0, vSize);

    //Set Blink Source
    vSize = D3DXGetFVFVertexSize(m_pBlinkMesh->GetFVF());
    IDirect3DVertexBuffer9* blinkBuffer = NULL;
    m_pBlinkMesh->GetVertexBuffer(&blinkBuffer);
    g_pDevice->SetStreamSource(1, blinkBuffer, 0, vSize);

    //Set Emotion Source
    IDirect3DVertexBuffer9* emotionBuffer = NULL;
    m_emotionMeshes[pController->m_emotionIndex]->GetVertexBuffer(&emotionBuffer);
    g_pDevice->SetStreamSource(2, emotionBuffer, 0, vSize);

    //Set Speech Sources
    for (int i=0; i<2; i++) {
        IDirect3DVertexBuffer9* speechBuffer = NULL;
        m_speechMeshes[pController->m_speechIndices[i]]->GetVertexBuffer(&speechBuffer);
        g_pDevice->SetStreamSource(3 + i, speechBuffer, 0, vSize);
    }

    //Set Index buffer
    IDirect3DIndexBuffer9* ib = NULL;
    m_pBaseMesh->GetIndexBuffer(&ib);
    g_pDevice->SetIndices(ib);

    //Set Shader variables
    D3DXMATRIX view, proj;
    g_pDevice->GetTransform(D3DTS_VIEW, &view);
    g_pDevice->GetTransform(D3DTS_PROJECTION, &proj);

    g_pEffect->SetMatrix("matW", &pController->m_headMatrix);
    g_pEffect->SetMatrix("matVP", &(view * proj));
    g_pEffect->SetTexture("texDiffuse", m_pFaceTexture);
    g_pEffect->SetTexture("texNormalMap", m_pFaceNormalMap);
    g_pEffect->SetVector("weights", &pController->m_morphWeights);

    //Start Technique
    D3DXHANDLE hTech = g_pEffect->GetTechniqueByName("FaceMorphNormalMap");
    g_pEffect->SetTechnique(hTech);
    g_pEffect->Begin(NULL, NULL);
    g_pEffect->BeginPass(0);

    //Draw mesh
    g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0,
                                    m_pBaseMesh->GetNumVertices(), 0,
                                    m_pBaseMesh->GetNumFaces());

    g_pEffect->EndPass();
    g_pEffect->End();

    //Restore vertex declaration and stream sources
    g_pDevice->SetVertexDeclaration(NULL);

    for (int i=0; i<5; i++) {
        g_pDevice->SetStreamSource(i, NULL, 0, 0);
    }
}