View Full Version : How can I approach this problem (newbie trying to be cool) :-(

08-05-2003, 09:20 PM
I've tried to experiment with some OpenGl interactive modeling, but I have no idea how to do it and I can't find any examples of that... I'l really appreciate any help you guys can offer me on this one. This is what I'd like to do:
Imagine starting up with a simple polygon cube. I would like the used to be able to click on one of the points of the cube and then "+" would bevel this point (that is the point would be turned into a triangle on the corner of the cube...) I don't even know how to approach this... here are some of my problems:
- how do I do the selection? It seems that the selection buffer only works for objects, not components...
- if I store the geometry in polygons (4 vertices per poly) then beveling one point will create 3 sides that have 5 points, not 4
- finally, the hardest part... how do I update the array of vertices? I mean this is hard for even a cube, but if I have say more complex object whose vertices are stored in an array, then how do I know which point in the array was picked... how do I now add the extra 2 points created, so the sctructure of the object would still be valid (e.g. indives kept intact, if used)?
I know this question is huge and I really appreciate any help. It would really make me feel that I'm getting good with OpenGL :-)
Finally, I'm still looking for some good point-beveling algorithms...
As always, huge thanks,

08-06-2003, 01:04 AM
About your selection problem:

As you said, the selection-mode works only with objects. So use objects! Just render a billboarded quad (or circle) in the selection buffer, where the vertex should be. If the quad is big enough, than one doesn´t have to click exactly on the vertex, but can click slightly besides it and still it will be recognized as selected (and this will make the selection much easier).

Just give the quad the index of that vertex as its ID.


08-06-2003, 01:48 AM
Most applications use their scene graph for this kind of thing. Construct the ray from the camera through the click point on the screen (and out to the far plane). Run this ray through your scene, finding the closest vertex IN SCREEN SPACE. If that vertex was close enough, then that's what the user clicked.

08-06-2003, 08:53 AM
jwatte, that's exactly what I have problems with :-) I don't know how to 'cast a ray through scene graph and find closest point'...
I was trying to search goolge, but all the tutorials I found sue selectiong buffer and only for selecting objects...

08-06-2003, 09:29 AM
Try to find a ray tracing tutorial or an introduction to computational geometry and/or basic linear algebra.

08-06-2003, 09:35 AM
if I store the geometry in polygons (4 vertices per poly) then beveling one point will create 3 sides that have 5 points, not 4OpenGL can draw polygons: glBegin(GL_POLYGON); ... glEnd(); Or just draw them as a triangle fan.

- finally, the hardest part... how do I update the array of vertices?This isn't so hard. You will have to find all of the polys that contain that vertex and modify their list of indices. You're changing one vertex (the selected one), and creating two new ones. Just add the new ones on to the end of the object vertex list. If you know STL, you might consider using something like std::vector<Vertex3d>, where Vertex3d is your vertex class, for your object vertex list.

As for selection, you could do it by finding the distance between the screen coordinates of each point in your object, and the point where the mouse was clicked. Of all of the ones below a certain threshold (say, 2 pixels), pick the one which is closest to the viewer.

Good luck.