View Full Version : pick point
08-06-2011, 01:17 PM
hallo, i have 10 points in 3D and would like to know how to pick any of them. thanks for any help
08-06-2011, 02:24 PM
You can use gluUnproject to obtain the 3D position from say your mouse x/y position. You could then just loop through the 10 points and compare.
08-06-2011, 03:15 PM
ok thanks for that, it worked. but how can i now move that picked point?
08-06-2011, 04:08 PM
You can move point (or any other object) by modifying it's coordinates before next frame.
If You used GLUT for window management, then You are drawing Your points in display Function, and handling kb and mouse events in callbacks passed to glutKeyboardFunc and glutMouseFunc.
You clicked one of your points, that triggered mouse callback where You should figure out which point was clicked and save it somewhere. When next click or move occurs it's callback function will be triggered, using information saved earlier You can calculate new coordinates for your point (and call glutPostRedisplay() to trigger display callback and draw new scene).
You can also setup timer which redraws scene at specified rate,
so You do not have to worry about posting redisplays, just modify coordinates in callback.
btw. there is another simple method of picking, it's called color picking:
Draw each object in unique color, read pixel at coordinates of click, now You can find out what was clicked comparing read value with colors of objects (You can use this method to pick any kind of objects (spheres, quads, complex models...), but it does not work very well if they are intersecting)
08-07-2011, 02:29 AM
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.