PICKING OBJECTS by MOUSE doesnt work correctly

Hello,

I'm making a 3D game and I need to implement PICKING. But I've done everything as it is in the book and was also comparing code line by line with tutorial from other source http://www.toymaker.info/Games/html/picking.html

and it doesn't work correctly - the picking RAY is somehow translated upper than it should be. I can click on the object a bit lower than it already is and i cannot click on it from the top, but a bit lower.

Also I checked a sample from that book and I found out it does the same for it too.

So pls, could you look at it:

http://www.moon-labs.com/ml_book_samples.htm

download - Download Part III Sample Programs

and load the sample in chapter 15 - "pick"

- one last thing - just make it not to rotate, so you can try picking exactly when its staying still in the space. - change it in DISPLAY function in "pickSample.cpp"

I think there must be some inaccuracy in calculation of Transforming the ray, but why would they put there wrong code...or most probably, I did something wrong, but I cannot find where is the bug.

I'm looking forward to hearing from you soon.

Peto



Answer this question

PICKING OBJECTS by MOUSE doesnt work correctly

  • paulisme

    Look in C++/Samples - called 'Pick'. There is only a C++ sample but the ideas are the same.

  • J.Bizzle

    LOL...I've found it eventually...I thought its a documentation in SDK, and its just a sample....
  • gustave

    OK. I will do it now.
  • M Landy

    It does the same...

    I changed the code -as it is in the PICK example, its more messy than mine, but I post it here like that so I have to post just 1 function

    void GameEngine::MouseMove(int x, int y)

    {

    // initialize picking ray

    // Extra instance of ray, so we don't change it permanently, just for this object

    d3d::Ray temp_ray;

    // Check for every sprite in the menu screen

    vector<MenuSprite*>::iterator menuObject;

    for (menuObject = m_GameMenu->m_menuMeshes.begin();menuObject != m_GameMenu->m_menuMeshes.end();menuObject++)

    {

    // test for a hit - but not background

    if ((*menuObject)->getActionType() == BACKGROUND)

    continue;

    D3DXVECTOR3 v;

    D3DXMATRIX proj;

    m_Device->GetTransform(D3DTS_PROJECTION, &proj);

    v.x = ((( 2.0f*x) / m_mainViewport.Width) - 1.0f) / proj._11;

    v.y = -((( 2.0f*y) / m_mainViewport.Height) - 1.0f) / proj._22;

    v.z = 1.0f;

    //temp_ray = ray;

    D3DXMATRIX view;

    m_Device->GetTransform(D3DTS_VIEW, &view);

    // Variables for transforming ray to mesh's local space

    D3DXVECTOR3 mPos = (*menuObject)->GetPosition(); // Mesh position in the world space

    D3DXMATRIX meshTInverse; // Transform matrix from world to local space

    D3DXMatrixTranslation(&meshTInverse,mPos.x,mPos.y,mPos.z);

    D3DXMATRIX mWorldView = view*meshTInverse;

    D3DXMATRIX m;

    D3DXMatrixInverse(&m, 0, &mWorldView);

    temp_ray._direction.x = v.x*m._11 + v.y*m._21 + v.z*m._31;

    temp_ray._direction.y = v.x*m._12 + v.y*m._22 + v.z*m._32;

    temp_ray._direction.z = v.x*m._13 + v.y*m._23 + v.z*m._33;

    temp_ray._origin.x = m._41;

    temp_ray._origin.y = m._42;

    temp_ray._origin.z = m._43;

    // Do a mesh test

    if (RayMeshIntTest(&temp_ray, (*menuObject)->m_mesh))

    {

    (*menuObject)->m_pointingAtMesh = true;

    break;

    }

    }

    }

    And it does all the same, I can pick the object like one half of the object lower than it really is.

    Any solutions

    THX


  • SharonF

    I cannot find that example...

    I have SDK from December 05, and I searched, browsed and have not found it...


  • Sharon277

    I must be looking somewhere else, because I cannot find it.

    Am I going right : in VS2005 - I open CONTENTS(help) -> Directx 9.0 SDK -> ...

    I am doing a game in C++ so it is more than fine for me when it is in C++


  • anand_vsd

    Please look at the "Pick" example in the SDK and compare your results to the sample.

  • PICKING OBJECTS by MOUSE doesnt work correctly