Who is responsible for scene picking?

Started by
2 comments, last by EJH 13 years, 7 months ago
Working in opengl, I am currently working on color picking with glReadPixels. And i have problems deciding who is responsible for calling the pick() function and who should decide what unique values to use for each entity in the scene.

What is the case usually?

-- MORE INFO --
I have a IGraphics interface which essentially is a wrapper for the underlying API i.e. opengl. IGraphics wraps stuff like glDrawElements, SwapBuffers, ReadPixels etc.

currently I have a Renderer::Render() which gets called in the idle loop:

Renderer::Render(){    // bunch of IGraphic calls.    for (each entity in Scene)    {      ...      _mIGraphics->DrawBuffers();    }    ...   _mIGraphics->SwapBuffers();}


Should I also let Renderer do the picking? Other candidates include the Scene object, but then I will have to share the IGraphics object which is currently contained in an inner-class inside Renderer... that is bad.
==============================================Rage - Really Amateurish Graphics EngineCollada Parser / Serializer
Advertisement
I think the question should be, what is the purpose of the picking, and which class cares most about that purpose? Are you doing it for some process the renderer manages? Or one the scene manages? All things being equal, any functionality should be located closest to the other functionality it's most closely related to. Simple naive test: which class accesses the data generated by picking the most.
It really depends on your overall architecture and how things would most naturally fit. From what you've described it sounds like Renderer makes the most sense for containing the picking logic, at least at a low level; you might consider wrapping that in a higher level interface as well for clean separation in case you want to rework your picking methodology later (e.g. if you decide to do picking via a physics library and a raycast, such as Bullet).

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

I guess if you are doing color picking it would be somewhere in the renderer. You will also need access to GUI elements, since you need pick those as well. Also, if you pick a GUI element during a frame, then you should not also simultaneously pick a world object that happens to be behind that GUI element.

This topic is closed to new replies.

Advertisement