Archived

This topic is now archived and is closed to further replies.

iNsAn1tY

Texture coordinate generation...

Recommended Posts

Hi. To finish off my map maker, I need a robust system for creating texture coordinates. Now, using glTexGen[idf] is out, as I actually need the coordinates to save in the map for the triangles. I thought I had a system a while ago, planned out on paper, but I''ve foolishly lost the piece of paper, and the thought happened in a flash of inspiration anyway, so I''m not too likely to remember. Can anyone help? Also, while I''m here, I might as well ask again if anyone knows a way of creating a robust selection system? I''m having a lot of trouble using OpenGL''s selection buffer. It simply doesn''t work for 3D scenes. Once again, does anyone know how a professional program like 3D Studio Max handles selection of objects?
Movie Quote of the Week:

"The greatest trick the Devil ever pulled was convincing the
world he didn''t exist."
- Roger "Verbal" Kint, The Usual Suspects.
Try http://uk.geocities.com/mentalmantle - DarkVertex Coming Soon!

Share this post


Link to post
Share on other sites
>>Also, while I''m here, I might as well ask again if anyone knows a way of creating a robust selection system? I''m having a lot of trouble using OpenGL''s selection buffer. It simply doesn''t work for 3D scenes. <<

selection does work (even for 1000000 object scenes) one thing it does is select everything within the region, ie not just the closet thing

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
Well, pertaining to selection...



The image above shows two box brushes, Objects 1 and 2. Object 2 is partially inside Object 1 and partially outside. I tried two clicks, Click 1 and Click 2. However, both clicks told me that Object 1 had been selected, even though it is clear that Object 2 should be selected by Click 1. Whatever I try, however much I analyse the z depth values returned in the selection buffer, I can't get it to select the correct object.

I'm using the gluPickMatrix method, and I'm thinking that there might be another, better method. The damn thing just won't work. I mean, it even says in the OpenGL Superbible (and I quote):

"You can use the z values to determine which object was closest to the user in viewspace, which is the mot likely object that was clicked. Still, for some shapes and geometry, if you aren't careful, it can be difficult to sort out precisely what the user intended to pick."

However, when Click 1 happens, Object 1 is the closest to the camera, so it just returns that Object 1 was selected, which is wrong. I set up this exact situation with gmax, and had no problem selecting Object 1 and Object 2 in the way I'd expect. And to answer what you pointed out about about gluPickMatrix, I set it up to have a 1x1 selection box, and it still didn't work...

EDIT: If the above image doesn't show, right clicking on the placeholder, copying the address of the image into the browser address bar and pressing Enter seems to work...


Movie Quote of the Week:

"The greatest trick the Devil ever pulled was convincing the
world he didn't exist."

- Roger "Verbal" Kint, The Usual Suspects.

Try http://uk.geocities.com/mentalmantle - DarkVertex Coming Soon!


[edited by - iNsAn1tY on August 18, 2002 9:42:42 AM]

Share this post


Link to post
Share on other sites
About the selection issue:

Most professional programs determine selection using various geometric algorithms (eg. ray/face intersections, bounding volume checks, etc). The problem is that hardware assisted selection only works well on filled objects. It's very problematic on wireframe objects.

If you want to select filled objects only, you could use an ID buffer. This is approximately how it works:

1) render your 3D scene normally (incl. buffer swap)
2) clear the backbuffer
3) do a quick pick-ray/bounding box test to find the objects that are possible candidates
4) Render those objects into the backbuffer, but without lighting or texturing. Just assign them a constant colour. This colour will be your object ID. Just assign one ID per object. A 32bit buffer can store up to 4 billion IDs, that should be enough
5) Unproject the pickposition, and read back the ID value (RGBA). It will be the selected object ID.

You can also move point 1 after point 5, if you need to render your scene after the picking was done on the previous frame.

Little catch for point 4: you really need to turn off everything that could alter the colour being rendered (since they represent a constant ID value, rather than a colour). That includes blending, lighting, fog, texture, dithering, etc.

Another quick'n'dirty method: if you don't need the alpha buffer, and don't have more than 255 objects to pick from, then you can simply use the alphabuffer as a 8bit ID buffer. The principle is the same as denoted above, but you can directly create the ID buffer while rendering your scene (saves the additional selection pass). Just make sure to feed the appropriate object ID as an alpha value to the renderer.

/ Yann

[edited by - Yann L on August 18, 2002 12:58:12 PM]

Share this post


Link to post
Share on other sites
selection is quite difficult to get working (your code must be 100% correct) (it does work 100% correctly though so keep trying (theres an example with glut + ive written an example also if u want the code mail me ) the thing with it is will return everything under the cursor (not just the closest) thus u have to decide which is the closest (which is usually a quite simple sort )
another method Yann mentioned (which ive done before + also works perfectly though requires a bit more work than selection remember to turn off dithering + run in 32bit colour mode also)

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
Thanks for the replies. I was thinking of creating a raycasting system, but then thought of the large number of polygons I'd potentially have to examine, and maths problem associated with it, and kind of put it on the back burner.

I also thought of a system similar to the one you describe, Yann, but using the stencil buffer. I'd render the scene into the stencil buffer, making the object's pixels equal to the object's number. Then I could read back the number of the pixel in the stencil buffer which the mouse was over, and that would tell me the number of the object. Could this work? I think the only problem I have with this system is how to read back the number of the pixel, but I could use glReadPixels...I'll try the colour picking system you suggest in the meantime

Also, I'm not too clear on step 3 in your post, Yann. I think I'll have to read up on how to project rays which are the result of the user clicking on an area of the screen which isn't the centre of the screen. I could project a ray from the centre of the screen (that's quite easy, just use the camera's position and orientation as the start point and direction), but calculating a ray which isn't from the centre is a bit more difficult. You have to figure out the offsets from the centre and everything. Oh well, down to the library to pick up some geometry books...

btw, zed, I will email you for that code, if you don't mind...


Movie Quote of the Week:

"The greatest trick the Devil ever pulled was convincing the
world he didn't exist."

- Roger "Verbal" Kint, The Usual Suspects.

Try http://uk.geocities.com/mentalmantle - DarkVertex Coming Soon!


[edited by - iNsAn1tY on August 19, 2002 5:36:19 AM]

Share this post


Link to post
Share on other sites