// 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) {
How to get vertex under mouse?
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement