How to get vertex under mouse?

Started by
9 comments, last by DXnut 17 years, 8 months ago
I have a vertex picking function in my mesh editor. I don't use the D3DXIntersect for it. Here is what I have. My vertex buffer has the position (D3DXVECTOR3) and a D3DCOLOR for each one. It is a clone of the mesh vertex buffer that I use so I can draw the points only, and I set their color if they are picked differently.

// lock the vertex bufferV_RETURN( mPointBuffer->Lock(0, 0, (LPVOID*)&VC, 0) );for (UINT i = 0; i < VertexCount; i++){	D3DXVECTOR3 p = VC.pos;  // get the vertex position        // transform the position into world space (same as pick ray)	D3DXVec3TransformCoord(&p, &p, &mWorldMatrix);                // Get camera to vertex vector	VfromCamera = p - PickRay.RayOrigin;	D3DXVec3Normalize(&VfromCamera, &VfromCamera);        // x = pickray.direction dot camToPosVector	float x = D3DXVec3Dot(&PickRay.RayDirection, &VfromCamera);         // angle in degrees between the pickray.direction and camToPosVector	float angle = abs(D3DXToDegree(acosf(x)));		        // Do I want to check back facing ones?	BOOL checkpoint = TRUE;	if (g_bIgnoreBack)   // Ignore back facing ones	{                // vector of object center to the vertex		D3DXVECTOR3 c = mVecObjectPos - p;                 // if that vector dotted with camToPosVector < 0 it is back facing		if (D3DXVec3Dot(&VfromCamera, &c) < 0)					checkpoint = FALSE;  // don't check it	}        // if the angle is < 0.2 I consider it picked	if (angle < 0.2f && checkpoint)	{
--------------------------Most of what I know came from Frank D. Luna's DirectX books

This topic is closed to new replies.

Advertisement