Centre view on a rendered object

Basically, i have a little app going on where the app renders a direct3d surface, and the user can click on various items that are being rendered so they can centre the view on that item.

Now, the problem i'm having is that i can't make the view centre on one of the objects by using a mouseclick. I can get the mouseclicks coordinates relative to the 3d window. i.e. i can say they were at coordinates 100,200 i.e. 100 to the right and 200 down from the top left corner. I can then take those coordinates, and remap them slightly so as to tell which way i should move the view. I can get it so that the view moves in the right direction, but i can't make it move the right distance. i.e. they'd click on a circle in the top left, and it would move up and left BUT it woudl move much to far.

So how can i convert the mouse coordinates into proper "directx" coordinates so i can tell on what item they clicked on in the direct3d window. A perfect example of what i mean is demonstrated in www.liveplasma.com. You can select items by "clicking" on them. How can i achieve the same effect.

I'm coding in C# using managed directx.


Answer this question

Centre view on a rendered object

  • tmenier

    This is called picking - see the picking tutorial on MDXInfo

    To center an object, once you have worked out which item was 'picked' you can find its center using Geometry.BoundingSphere. Then use that center point as the LookAt when you create your view matrix.



  • Centre view on a rendered object