# Picking MeshFVF ?

This topic is 4884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

this things makes my head blow.... i have try picking using D3DXIntersect to select mesh.... if the mesh is load from .x file, the picking just can sometime select a part of the mesh. and the main problem: i used D3DXCreateMeshFVF to create my terrain, but I can't select the terrain.... Can someone show me example to select triangle of my terrain mesh... i heard that we must check every triangle vertices in vertex buffer of mesh? is it true...? how to do that..? PLEASE HELP ME .... this is the ray techniques i used, i took it from book: Introduction to Game Programming using Direct X 9.0, Frank Luna
//ray structure
namespace d3d{
struct Ray  //digunakan untuk intersect
{
D3DXVECTOR3 _origin;
D3DXVECTOR3 _direction;
};
}

d3d::Ray CalcPickingRay(int x, int y,IDirect3DDevice9* Device)
{
float px = 0.0f;
float py = 0.0f;

D3DVIEWPORT9 vp;
Device->GetViewport(&vp);

D3DXMATRIX proj;
Device->GetTransform(D3DTS_PROJECTION, &proj);

px = ((( 2.0f*x) / vp.Width)  - 1.0f) / proj(0, 0);
py = (((-2.0f*y) / vp.Height) + 1.0f) / proj(1, 1);

d3d::Ray ray;
ray._origin    = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
ray._direction = D3DXVECTOR3(px, py, 1.0f);

return ray;
}

// after calculate ray, the ray and the Inverse of view matrix passing through this function

void TransformRay(d3d::Ray* ray, D3DXMATRIX* T)
{
// transform the ray's origin, w = 1.
D3DXVec3TransformCoord(
&ray->_origin,
&ray->_origin,
T);

// transform the ray's direction, w = 0.
D3DXVec3TransformNormal(
&ray->_direction,
&ray->_direction,
T);

// normalize the direction
D3DXVec3Normalize(&ray->_direction, &ray->_direction);
}

after that i use D3DXintersect...

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633726
• Total Posts
3013572
×