snapping in OpenGL 2

I would like to know about the “snapping”.
If I have 2 WireCubes (small one is in the big one).When I move the small one ,I need the snapping active for help user locate the any corners of the small one attach into the any corners or the any edges of the big one .

please help me again.
thanks a lot

Hi !

If you don’t have to many objects, then the easiest solution is to compare the vertices of the to objects, just take each vertex in one object and compare with all vertices in the other object (don’t forget to run them through your transformation matrix first so you get world coordinates), calculate the distance between the vertices and if the distance is below the snap value x then you can have found a “snap” and van update the objects position.

If you have zillions of objects then this will not work of course, in that case you need to do some simple test first to see if two objects are close to each other in some way (bounding boxes or something more fancy).