Jump to content
  • Advertisement
Sign in to follow this  
be17_17y

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.

If you intended to correct an error in the post then please contact us.

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...

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!