RayCast with DirectX9?

Anddos
Posts: 5
Joined: Wed Jun 30, 2010 2:18 am

RayCast with DirectX9?

Post by Anddos »

I would like to create a ray in bullet to work with DirectX,i am not sure where to start but this is an implentation of a ray cast in DirectX 9 against a .x Mesh and sets the position y height acordling to the terrain...

void Crowd::SetEntityGroundPos(D3DXVECTOR3 &pos)
{
//Create the test ray
D3DXVECTOR3 org = pos + D3DXVECTOR3(0.0f, 10.0f, 0.0f);
D3DXVECTOR3 dir = D3DXVECTOR3(0.0f, -1.0f, 0.0f);

BOOL Hit;
DWORD FaceIndex;
FLOAT U;
FLOAT V;
FLOAT Dist;

//Floor-ray intersection test
D3DXIntersect(m_pFloor->m_pMesh, &org, &dir, &Hit, &FaceIndex, &U, &V, &Dist, NULL, NULL);

if(Hit)
{
//Adjust position accordingly to the floor height
pos.y = org.y - Dist;
}
}