converting mouse 2d to 3d space problem

hello guys ,

sorry for reposting the same question . iam unable to get 3d co - ordinates

here is my code

case WM_LBUTTONDOWN :

GetMousepos(&point);

Device->GetTransform(D3DTS_VIEW ,&viewM);

Device->GetTransform(D3DTS_PROJECTION,&projM);

D3DXMatrixInverse(&InverseProjM , NULL,&projM);

D3DXMatrixInverse(&InverseViewM,NULL,&viewM);

later i dont know how to convert 2d coordinates to 3d co-ordiantes . actually this is continuous process i.e

case WM_MOUSEMOVE:

above code

dont mind this is basic question . because iam a 4 months buddy to 3d concepts



Answer this question

converting mouse 2d to 3d space problem

  • Baz Star

    thank u sir,

    i got the answer.it isworking

    but one more . when iam picking the object in world every time iam checkig against

    every object whether it is intersected or not like this

    D3DXIntersect() ; function. but if suppose my world consist of 2000 or more objects

    should i have to check all these objects or any other simple mecanisam


  • Jelle Kooi

    You want to convert 2D point of the mouse to 3D point

    It depend on what projection you are in, in Orthogonal Projection (2D)
    You simply take the x,y of the mouse for coordinate and put a value for the Z

    If you mean to point to something in 3D (perspective projection)
    with the mouse there is a sample
    that is called pick in the SDK...that send a ''ray'' into the scene
    when you click the screen (or move around)
    This will convert a 2D points on the screen to a 3D ray direction in the 3D scene

    The other possible use is to rotate something with the mouse
    This can be found in the Arcball function of the Framework in the SDK
    this actually only convert a 2D move of the mouse to a angle to rotate the object

    Either way your mouse get you only 2 coordinates, the z value is yours to defined


  • Eric Zhao

    thank u very much sir ,

    now i should prepare bsp trees .

    any way i got the best answer


  • LowRad0

    Maybe.

    In general games with lots of objects use space partitioning techniques such as Octrees or BSP or portal systems to divide the world up into larger chunks with yor objects inside those larger chunks.

    When you do your intersection tests you test the larger chunks first and then reject hundreds of items at a time. If the larger chunk passes then and nly them do you drop down and test the lower level objects.

    They are all fairly complex things and too complicated to explain in a forum post. Do some research on gamedev.net and gamasutra.com

    The most simple thing to do would be to group your items by proximity and then curround each group with a bounding sphere that you can test first.



  • converting mouse 2d to 3d space problem