Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMedo3337

Posted 26 January 2013 - 05:29 PM

I'm triangle to use raycasting to get the intersected triangle, here is the code that I'm using:

 

LPD3DXMESH pMesh = GetMesh();
pMesh->CloneMeshFVF( D3DXMESH_MANAGED, pMesh->GetFVF(), d3ddev, &pMesh );

LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DINDEXBUFFER9 pIB;

pMesh->GetVertexBuffer( &pVB );
pMesh->GetIndexBuffer( &pIB );

WORD* pIndices;
D3DVERTEX* pVertices;

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

BOOL pHit;
DWORD pFaceIndex;
FLOAT pU, pV, pDist;
D3DXIntersect(pMesh, &rayFrom, &rayTo, &pHit, &pFaceIndex, &pU, &pV, &pDist, NULL, NULL);
if (pHit)
{
    DWORD dwNumFaces = pMesh->GetNumFaces();
    for(DWORD i = 0; i < dwNumFaces; i++)
    {
        D3DXVECTOR3 v0 = pVertices[pIndices[3 * i + 0]].p;
        D3DXVECTOR3 v1 = pVertices[pIndices[3 * i + 1]].p;
        D3DXVECTOR3 v2 = pVertices[pIndices[3 * i + 2]].p;


        if ( D3DXIntersectTri(&v0, &v1, &v2, &rayFrom, &rayTo, &pU, &pV, &pDist) )
        {
             // Intersected triangle found
        }
    }
}

// Unlock
pMesh->UnlockVertexBuffer();
pMesh->UnlockIndexBuffer();
 
Why the above code doesn't work as expected?
I'm not getting a valid intersected triangle in (v0, v1, v2).

#3Medo3337

Posted 26 January 2013 - 05:29 PM

I'm triangle to use raycasting to get the intersected triangle, here is the code that I'm using:

 

LPD3DXMESH pMesh = GetMesh();
pMesh->CloneMeshFVF( D3DXMESH_MANAGED, pMesh->GetFVF(), d3ddev, &pMesh );

LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DINDEXBUFFER9 pIB;

pMesh->GetVertexBuffer( &pVB );
pMesh->GetIndexBuffer( &pIB );

WORD* pIndices;
D3DVERTEX* pVertices;

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

BOOL pHit;
DWORD pFaceIndex;
FLOAT pU, pV, pDist;
D3DXIntersect(pMesh, &rayFrom, &rayTo, &pHit, &pFaceIndex, &pU, &pV, &pDist, NULL, NULL);
if (pHit)
{
    DWORD dwNumFaces = pMesh->GetNumFaces();
    for(DWORD i = 0; i < dwNumFaces; i++)
    {
        D3DXVECTOR3 v0 = pVertices[pIndices[3 * i + 0]].p;
        D3DXVECTOR3 v1 = pVertices[pIndices[3 * i + 1]].p;
        D3DXVECTOR3 v2 = pVertices[pIndices[3 * i + 2]].p;


        if ( D3DXIntersectTri(&v0, &v1, &v2, &rayFrom, &rayTo, &pU, &pV, &pDist) )
        {
             // Intersected triangle found
        }
    }
}

// Unlock
pMesh->UnlockVertexBuffer();
pMesh->UnlockIndexBuffer();
 
Why the above code doesn't work as expected? I'm not getting a valid intersected triangle in (v0, v1, v2).

#2Medo3337

Posted 26 January 2013 - 05:28 PM

I'm triangle to use raycasting to get the intersected triangle, here is the code that I'm using:

 

LPD3DXMESH pMesh = GetMesh();
pMesh->CloneMeshFVF( D3DXMESH_MANAGED, pMesh->GetFVF(), d3ddev, &pMesh );

LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DINDEXBUFFER9 pIB;

pMesh->GetVertexBuffer( &pVB );
pMesh->GetIndexBuffer( &pIB );

WORD* pIndices;
D3DVERTEX* pVertices;

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

BOOL pHit;
DWORD pFaceIndex;
FLOAT pU, pV, pDist;
D3DXIntersect(pMesh, &rayFrom, &rayTo, &pHit, &pFaceIndex, &pU, &pV, &pDist, NULL, NULL);
if (pHit)
{
    DWORD dwNumFaces = pMesh->GetNumFaces();
    for(DWORD i = 0; i < dwNumFaces; i++)
    {
        D3DXVECTOR3 v0 = pVertices[pIndices[3 * i + 0]].p;
        D3DXVECTOR3 v1 = pVertices[pIndices[3 * i + 1]].p;
        D3DXVECTOR3 v2 = pVertices[pIndices[3 * i + 2]].p;


        if ( D3DXIntersectTri(&v0, &v1, &v2, &rayFrom, &rayTo, &pU, &pV, &pDist) )
        {
             // Intersected triangle found
        }
    }
}

// Unlock
pMesh->UnlockVertexBuffer();
pMesh->UnlockIndexBuffer();
Why the above code doesn't work as expected? I'm not getting a valid intersected triangle in (v0, v1, v2).

#1Medo3337

Posted 26 January 2013 - 07:58 AM

I'm triangle to use raycasting to get the intersected triangle, here is the code that I'm using:

 

LPD3DXMESH pMesh = GetMesh();
pMesh->CloneMeshFVF( D3DXMESH_MANAGED, pMesh->GetFVF(), d3ddev, &pMesh );

LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DINDEXBUFFER9 pIB;

pMesh->GetVertexBuffer( &pVB );
pMesh->GetIndexBuffer( &pIB );

WORD* pIndices;
D3DVERTEX* pVertices;

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

BOOL pHit;
DWORD pFaceIndex;
FLOAT pU, pV, pDist;
D3DXIntersect(pMesh, &rayFrom, &rayTo, &pHit, &pFaceIndex, &pU, &pV, &pDist, NULL, NULL);
if (pHit)
{
    DWORD dwNumFaces = pMesh->GetNumFaces();
    for(DWORD i = 0; i < dwNumFaces; i++)
    {
        D3DXVECTOR3 v0 = pVertices[pIndices[3 * i + 0]].p;
        D3DXVECTOR3 v1 = pVertices[pIndices[3 * i + 1]].p;
        D3DXVECTOR3 v2 = pVertices[pIndices[3 * i + 2]].p;


        if ( D3DXIntersectTri(&v0, &v1, &v2, &rayFrom, &rayTo, &pU, &pV, &pDist) )
        {
             // Intersected triangle found
        }
    }
}

// Unlock
pMesh->UnlockVertexBuffer();
pMesh->UnlockIndexBuffer();
Why the above code doesn't work as expected? I'm not getting a valid intersected triangle in (v0, v1, v2).

PARTNERS