Directx + picking
Hello,
i am trying to build a simple cad program,and since i decided to build it in managed code (C#), i would like to ask you if directx offers picking (picking lines, curves etc) capabilities. I was told that opengl has some picking capabilities but i would like to stay with managed code.
Thank you
I can't offer much help, but I would hate to see this thread die with no replies. You may get better replies in the DirectX forum.
OpenGL apparently automates the picking procedure. In DirectX, you have to code this procedure yourself; however, this isn't as hard as it sounds. If you paid attention when learning about the rendering pipeline (particularly, the transformations between coordinate systems, such as world transform, view transform, etc), then you'll be fine. Picking is the inverse of projection.
You can try googling for a guide on picking in Direct3D. I was able to find this (scroll all the way down, it's under "TwistyCube"), and I'm sure there are more guides.
OpenGL apparently automates the picking procedure. In DirectX, you have to code this procedure yourself; however, this isn't as hard as it sounds. If you paid attention when learning about the rendering pipeline (particularly, the transformations between coordinate systems, such as world transform, view transform, etc), then you'll be fine. Picking is the inverse of projection.
You can try googling for a guide on picking in Direct3D. I was able to find this (scroll all the way down, it's under "TwistyCube"), and I'm sure there are more guides.
As far as I know there is no "automated" way, but this is something you want to write yourself (at least as far as the search goes).
The first step is to convert the coordinate of the mouse to world/object space, and you can do that using "Vector3.Unproject". Then you can get the direction of the ray by subtracting the camera position from what you got by unprojecting. That gives you a line in 3D to work with.
Once you have that you need to search through the objects you have to find the correct object that intersects it. There are a lot of things to help you though, like "Mesh.Intersect" that will tell you if a ray intersects the mesh. You can also take advantage of whatever partitioning you may be using to speed up this search.
The first step is to convert the coordinate of the mouse to world/object space, and you can do that using "Vector3.Unproject". Then you can get the direction of the ray by subtracting the camera position from what you got by unprojecting. That gives you a line in 3D to work with.
Once you have that you need to search through the objects you have to find the correct object that intersects it. There are a lot of things to help you though, like "Mesh.Intersect" that will tell you if a ray intersects the mesh. You can also take advantage of whatever partitioning you may be using to speed up this search.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement