Directx9 3d point in the ground

Hello.
I use this code to pick a mesh and he works well.
now that I can pick a mesh I want to put it in the ground.
So I'm looking for the 3d position of my mouse in the ground.
Someone can help me please.
this is my code about picking:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
D3DXMATRIX p_matProjection, p_matView, p_matWorld, p_matInverse;
    pDevice->GetTransform(D3DTS_PROJECTION,&p_matProjection);
    pDevice->GetTransform(D3DTS_VIEW, &p_matView);
    pDevice->GetTransform(D3DTS_WORLD, &p_matWorld);
    // use the mouse coordinates to get the mouse angle
    POINT MousePos;
    GetCursorPos(&MousePos);
	   ScreenToClient(hWnd, &MousePos);
	   if(MousePos.x <0)MousePos.x=0;
	   if(MousePos.y <0)MousePos.y=0;

    float xAngle = (((2.0f * MousePos.x) / vx) - 1.0f) / p_matProjection(0, 0);
    float yAngle = (((-2.0f * MousePos.y) / vy) + 1.0f) / p_matProjection(1, 1);

    D3DXVECTOR3 origin, direction;
    origin = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
    direction = D3DXVECTOR3(xAngle, yAngle, 1.0f);
    D3DXMatrixInverse(&p_matInverse, NULL, &(p_matWorld * p_matView));
    D3DXVec3TransformCoord(&origin, &origin, &p_matInverse);
    D3DXVec3TransformNormal(&direction, &direction, &p_matInverse);
    D3DXVec3Normalize(&direction, &direction);
    // detect picking
    BOOL hit=false;
    float dist = 0;
    D3DXIntersect(entity, &origin, &direction, &hit, NULL, NULL, NULL, &dist, NULL, NULL);
Last edited on
Up
I think:

 
intersectionPos = origin + direction * dist;
Thanks but doesn't work
Topic archived. No new replies allowed.