Skip to main content
GameDev.net gamedev.net
🔒 Locked

Click-buffer?

Started by BeanDog Oct 20, 2000 at 2:54 PM 1 replies 250+ views
Original Post
BeanDog
BeanDog
Hey, on the subject of clicking on 3d objects and having it select them: I''m currently just finding the screen coordinates of the center of the object and checking which is closest on the screen to where they clicked. I was wondering if there was some way to assign each triangle an arbitrary number, and have that drawn to some surface offscreen somewhere. You see what I mean? This way, on a pixel-to-pixel basis, I would know what polygon was clicked on. Is that a stencil buffer?
JonnyQuest
JonnyQuest
Well, if you''re using Direct3D you''ll just need to use LVERTEXes and assign a unique colour to each polygon. Then you render this to the backbuffer and just don''t flip it but just lock the surface and check the colour of that pixel. Simple!

- JQ, PWC Software
"There are no pessimists, optimists and realists; just pessimists and optimists who think they're realists" -me
~phil
loco3d
loco3d
If you''re using OpenGL, you want to use the selection buffer. There''s basically 6 steps you''ll need to take (probably a lot easier to do this in DX).

1. Specify the array to be used for the returned hit records with glSelectBuffer().

2. Enter selection mode by specifying GL_SELECT as the parameter to glRenderMode().

3. Initialize the name stack using glInitNames() and glPushNames().

4. Define the viewing volume you want to use for selection. Usually, this is different from the viewing volume you originally used to draw the scene, so you probably want to save and then restore the current transformation state with glPushMatrix() and glPopMatrix().

5. Alternately issue primitive drawing commands and commands to manipulate the name stack so that each primitive of interest has an appropriate (unique) name assigned.

6. Exit selection mode and process the returned selection data (the hit records).

lata

-loco3d
------------------------------------------re·cur·sion n.: See Recursion. ------------------------------------------

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.