Jump to content

  • Log In with Google      Sign In   
  • Create Account


D3D9 Picking


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Anddos   Members   -  Reputation: 471

Like
0Likes
Like

Posted 06 January 2013 - 05:06 PM

This is the code i am following

 

void detect_picking()
{
    // get the current transform matrices
    D3DXMATRIX matProjection, matView, matWorld, matInverse;
    d3ddev->GetTransform(D3DTS_PROJECTION, &matProjection);
    d3ddev->GetTransform(D3DTS_VIEW, &matView);
    d3ddev->GetTransform(D3DTS_WORLD, &matWorld);
    // use the mouse coordinates to get the mouse angle
    GetCursorPos(&MousePos);
    float xAngle = (((2.0f * MousePos.x) / SCREEN_WIDTH) - 1.0f) / matProjection(0, 0);
    float yAngle = (((-2.0f * MousePos.y) / SCREEN_HEIGHT) + 1.0f) / matProjection(1, 1);
    D3DXVECTOR3 origin, direction;
    origin = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
    direction = D3DXVECTOR3(xAngle, yAngle, 1.0f);
    // find the inverse matrix
    D3DXMatrixInverse(&matInverse, NULL, &(matWorld * matView));
    // convert origin and direction into model space
    D3DXVec3TransformCoord(&origin, &origin, &matInverse);
    D3DXVec3TransformNormal(&direction, &direction, &matInverse);
    D3DXVec3Normalize(&direction, &direction);
    // detect picking
    BOOL hit;
    D3DXIntersect(meshTeapot, &origin, &direction, &hit, NULL, NULL, NULL, NULL, NULL, NULL);
    if(hit)
        d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
    else
        d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE);
}

 

now this is the line i am trying to understand

D3DXMatrixInverse(&matInverse, NULL, &(matWorld * matView));

 the inverse of matView goes to WorldSpace Cordinates and the inverse of matWorld go to the cordinates of the meshs local cordinates, can anyone tell me if i am right with this?


:)

Sponsor:

#2 Jason Z   Crossbones+   -  Reputation: 4690

Like
0Likes
Like

Posted 07 January 2013 - 09:01 PM

That sounds correct - the code sample is finding the 'angles' in view space based on the projection parameters (I use quotes because they don't actually look like angles...), and then it converts from view space vector to object space.  Then the intersection test is carried out on the object.  That seems like a perfectly rational way to do picking.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS