Jump to content
  • Advertisement
Sign in to follow this  
Ramilol

My picking function not working

This topic is 2702 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

I have this picking function that looks perfect to me but it won't work. I have done this a while ago but i can't remember how to. I let you have a remote access to my laptop.
anyway here is my code


BOOL Directx::Picking(HWND hWnd, AnimatedMesh *entity)
{
D3DXMATRIX matProj;
POINT pt;
D3DVIEWPORT9 vp;
D3DXMATRIX matWorld;
D3DXMATRIX matView;

GetCursorPos(&pt);
ScreenToClient(hWnd, &pt);
d3ddev->GetTransform(D3DTS_PROJECTION, &matProj);
d3ddev->GetViewport(&vp);
d3ddev->GetTransform(D3DTS_VIEW, &matView);

s.x = pt.x;
s.y = pt.y;

matWorld = entity->objTransformation;
// Use inverse of matrix
D3DXVECTOR3 rayPos((float)pt.x, (float)pt.y,0); // near-plane position
D3DXVECTOR3 rayDir((float)pt.x, (float)pt.y,1); // far-plane position
D3DXVec3Unproject(&rayPos,&rayPos,&vp,&matProj,&matView,&matWorld);
D3DXVec3Unproject(&rayDir,&rayDir,&vp,&matProj,&matView,&matWorld);
rayDir -= rayPos; // make a direction from the 2 positions
D3DXVec3Normalize(&rayDir,&rayDir);
Program::mesh->FillInTransformation(0, 0, 0, 0, 0, 0, rayPos.x, rayPos.y, 1, true, false, false);
float distanceToCollision;
BOOL hasHit = 0;
if(FAILED(D3DXIntersect(entity->pDrawMesh, &rayPos, &rayDir, &hasHit, NULL, NULL, NULL, &distanceToCollision, NULL, NULL)))
{
PostQuitMessage(0);
};

return hasHit;
}


PM me if you want to do remote access.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!