コード例 #1
0
ファイル: Mesh.cpp プロジェクト: nilimsarma/Blokus_FPGA
																																					//
// Creates a polygon mesh
void DirectX::Mesh::createPolygon( float length, unsigned int sides )
{
	D3DXCreatePolygon( DirectX::Manager::instance( )->getD3DDev( ), length, sides, &m_mesh, NULL );	
	update( );
	
	// Register with the manager
	DirectX::Manager::instance()->addResource( this );
}
コード例 #2
0
ファイル: d3dfile.cpp プロジェクト: LiXizhi/NPLRuntime
//-----------------------------------------------------------------------------
// Name: RestorePolygonMesh()
// Desc: Initialize device dependent objects.
// Params:
// pd3dDevice
//	[in] Pointer to an IDirect3DDevice9 interface, representing the device associated with the created polygon mesh. 
// Length
//	[in] Length of each side. 
// Sides
//	[in] Number of sides for the polygon. Value must be greater than or equal to 3. 
// ppMesh
//	[out] Address of a pointer to the output shape, an ID3DXMesh interface. 
//-----------------------------------------------------------------------------
HRESULT CD3DMesh::RestorePolygonMesh(LPDIRECT3DDEVICE9 pd3dDevice,FLOAT Length, UINT Sides, LPD3DXMESH *ppMesh)
{
	HRESULT hr;
	// create the floor geometry
    LPD3DXMESH pMesh;
    hr = D3DXCreatePolygon( pd3dDevice, Length, Sides, & pMesh, NULL );
    if( FAILED( hr ) )
        return hr;

    hr = pMesh->CloneMeshFVF( D3DXMESH_SYSTEMMEM, D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, pd3dDevice, ppMesh );
    pMesh->Release();
    if( FAILED( hr ) )
        return hr;

    LPD3DXMESH pMeshFloor = *ppMesh;				// rename variable
    
	DWORD dwNumVx = pMeshFloor->GetNumVertices();

    struct Vx
    {
        D3DXVECTOR3 vPos;
        D3DXVECTOR3 vNorm;
        float fTex[ 2 ];
    };

    // Initialize its texture coordinates
	const int FLOOR_TILECOUNT = 2;
	Vx * pVx;
    hr = pMeshFloor->LockVertexBuffer( 0, (VOID **) & pVx );
    if( FAILED( hr ) )
        return hr;

    for( DWORD i = 0; i < dwNumVx; ++ i )
    {
        if( fabs( pVx->vPos.x ) < 0.01 )
        {
            if( pVx->vPos.y > 0 )
            {
                pVx->fTex[ 0 ] = 0.0f;
                pVx->fTex[ 1 ] = 0.0f;
            } else
            if( pVx->vPos.y < 0.0f )
            {
                pVx->fTex[ 0 ] = 1.0f * FLOOR_TILECOUNT;
                pVx->fTex[ 1 ] = 1.0f * FLOOR_TILECOUNT;
            } else
            {
                pVx->fTex[ 0 ] = 0.5f * FLOOR_TILECOUNT;
                pVx->fTex[ 1 ] = 0.5f * FLOOR_TILECOUNT;
            }
        } else
        if( pVx->vPos.x > 0.0f )
        {
            pVx->fTex[ 0 ] = 1.0f * FLOOR_TILECOUNT;
            pVx->fTex[ 1 ] = 0.0f;
        } else
        {
            pVx->fTex[ 0 ] = 0.0f;
            pVx->fTex[ 1 ] = 1.0f * FLOOR_TILECOUNT;
        }

        ++ pVx;
    }

    pMeshFloor->UnlockVertexBuffer();
	return S_OK;
}