i have some questions about how to pick up mouse in 3d world.
Now i have several points in 3d world,by using these points i can draw curve
i want to choose a point on this curve using mouse, the viewport of the 3d world can be changed, so i want to know at any viewport when i chick mouse button near the curve, which point is the nearest to the mouse ?or which point is chose by me?
i do have no idea about how to implement it,help me please if you know.
Thanks. Good luck.
OpenGL has a selection mode, where you can take the position of a mouse click, and create a matrix that restricts drawing to some arbitrary (small) area around the mouse (e.g., a 7×7 pixel block). You can then draw your “stuff” (curve, points, whatever) and it’ll create a record of all the objects that fell inside of the block you defined. If more than one item fell inside that block, you get records of whatever did, one record per item, sorted by z-order from front to back.
When you’re done, you get a record of the points that were close to the mouse click. Most of the time, you’ll just use the closest to the front, but once in a while you’ll want to do a bit more work to figure out which of them (if there was more than one, obviously) was really closest to the original mouse click point.
gluProjectand (possibly)gluUnProjectcan be handy if you decide to do that.