Original Post
I am using this code:
it works, but in this situation, i have two mesh:

Now, when I click on the light, the mesh picked is first the street, and if I click again the light.
I want pick only the Light, because it is before.
Sorry, for my English.
It isn't my language
bool IsPicked()
{
BOOL pickedtmp;
if(m_Input_->MouseButtonDown(0))
{
//getting location of mouse relative to game window, not whole screen
POINT ptCursor;
GetCursorPos( &ptCursor );
ScreenToClient( hwnd, &ptCursor );
//getting viewport (p_Device is LPDIRECT3DDEVICE9)
D3DVIEWPORT9 view;
m_D3D::GetDevice()->GetViewport( &view );
//getting projection matrix
D3DXMATRIX projMat;
m_D3D::GetDevice()->GetTransform(D3DTS_PROJECTION,&projMat);
//calculating.. mouse ray
float vx = (+2.0f*ptCursor.x/view.Width - 1.0f)/projMat._11;
float vy = (-2.0f*ptCursor.y/view.Height + 1.0f)/projMat._22;
//Vector is D3DVECTOR
D3DXVECTOR3 Origin(0.0f, 0.0f, 0.0f);
// I used Z as my UP VECTOR, not sure how it will work for you
D3DXVECTOR3 Direction(vx, vy, 1.0f);
//getting projection matrix
D3DXMATRIX viewMat;
m_D3D::GetDevice()->GetTransform(D3DTS_VIEW,&viewMat);
//inversing projection matrix
D3DXMATRIX iviewMat;
D3DXMatrixInverse(&iviewMat, 0, &viewMat);
D3DXVec3TransformCoord(&Origin, &Origin, &iviewMat);
D3DXVec3TransformNormal(&Direction, &Direction, &iviewMat);
//setting variables
DWORD dwFace;
FLOAT fBary1, fBary2, fDist;
D3DXIntersect( g_Mesh, &Origin, &Direction, &pickedtmp, &dwFace, &fBary1, &fBary2, &fDist, NULL, NULL );
return pickedtmp;
}
}it works, but in this situation, i have two mesh:

Now, when I click on the light, the mesh picked is first the street, and if I click again the light.
I want pick only the Light, because it is before.
Sorry, for my English.
It isn't my language