D3DXIntersect

Abd4b56ff96074042dda5243e99a5d14
0
Anddos 103 Oct 10, 2012 at 11:49

if my model i am rendering is using a effect shader like this

VS_OUTPUT VertScene( float4 Pos : POSITION,
                     float3 Normal : NORMAL,
                     float2 Tex0 : TEXCOORD0 )
{
    VS_OUTPUT o;
    
    o.Pos = mul( Pos, g_mWorld );
    o.Pos = mul( o.Pos, g_mViewProj );
    o.Tex0 = Tex0;
    float3 N = normalize( mul( Normal, (float3x3)g_mWorld ) );

    // Always fully lit the floor
    o.Diffuse = 1.0f;
    
    return o;
}

what space so i need to convert the ray to ? , i am not using picking btw, i am placing a ray at a position of an object and and the direction is 0.0f,-1.0f,0.0f

this is the intersect function

void CTiny::IntersetFloor(IDirect3DDevice9* pd3dDevice,ID3DXMesh* mesh,D3DXMATRIX Param)
{
    pd3dDevice->GetTransform(D3DTS_WORLD, &matWorld);
    pd3dDevice->GetTransform(D3DTS_VIEW, &matView);

    origin = D3DXVECTOR3(m_vPos.x, m_vPos.y, m_vPos.z);
    direction = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

    // find the inverse matrix
    D3DXMatrixInverse(&matInverse, NULL, &(Param* matView));   //(matWorld * matView));

    // convert origin and direction into model space
    D3DXVec3TransformCoord(&origin, &origin, &matInverse);
    D3DXVec3TransformNormal(&direction, &direction, &matInverse);
    D3DXVec3Normalize(&direction, &direction);

    // detect picking
    BOOL hit;
    D3DXIntersect(mesh, &origin, &direction, &hit, NULL, NULL, NULL, NULL, NULL, NULL);
    if(hit)
    {
        pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
        pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
        
     //MessageBox(NULL,L"Hit",L"",0);
    }
    else
    {
        pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
        pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
    }
}

the call

 // draw each tiny
        vector <CTiny*>::iterator itCur, itEnd = g_v_pCharacters.end();
        for( itCur = g_v_pCharacters.begin(); itCur != itEnd; ++ itCur )
        {
            // set the time to update the hierarchy
            ( *itCur )->AdvanceTime( fElapsedTime, &vEye );
            // draw the mesh
            ( *itCur )->Draw();
            ( *itCur )->IntersetFloor(pd3dDevice,g_pMeshFloor,g_mxFloor); //last param is the floor matrix rot and translate...
            
        }

0 Replies

Please log in or register to post a reply.

No replies have been made yet.