Re: Convert NSOpenGLView pixel coordinates to OpenGL world coordinates
Re: Convert NSOpenGLView pixel coordinates to OpenGL world coordinates
- Subject: Re: Convert NSOpenGLView pixel coordinates to OpenGL world coordinates
- From: Ian was here <email@hidden>
- Date: Tue, 9 Oct 2007 23:19:42 -0700 (PDT)
It seems odd that rendering in selection mode would be
done only in software. You're calling all the same
rendering functions (excluding those which will not be
picked). For my simple use of this method, it's not
costing me any noticeable performance loss.
--- David Spooner <email@hidden> wrote:
> I have used selection mode in an application and it
> works well for
> the most part; I think it is elegant how one simply
> specifies a
> restricted viewing volume and then renders. There
> are a couple of
> things which you may want to consider, however.
> First is that (as
> far as I understand) all rendering in selection mode
> is performed in
> software, so you may see a performance hit if you
> are doing
> complicated rendering. Secondly, any geometric
> element which you
> want to be able to pick must be rendered as a
> separate primitive and
> with a corresponding namestack identifier; this can
> be quite
> complicated and inefficient if you're implementing a
> mesh editor, for
> example, where you wanted to interact with the
> individual faces and
> vertices.
>
> Anyway, I'm glad you've found a solution.
>
> dave
>
> On 7-Oct-07, at 7:08 PM, Ian was here wrote:
>
> > I think that I was unclear about my intentions. I
> have
> > a two dimensional grid of 3D objects (each object
> is
> > at the same Z coordinate). Sorry if I was
> misleading.
> > Picking actually turned out to be the solution. I
> > found the following code to work. It's not
> optimized,
> > but does the job of returning the selected object.
> >
> >
> > - (void)clickedPoint:(NSPoint)p
> > {
> > NSRect viewBounds = [myView bounds];
> > Scene *myScene = [myView clientScene];
> > NSArray *sceneObjects = [myScene sceneObjects];
> > GLsizei bufferSize = (GLsizei)[sceneObjects
> count];
> > GLint viewport[4];
> > GLuint nameBuffer[bufferSize];
> >
> >
> > glSelectBuffer( bufferSize, nameBuffer );
> > glRenderMode( GL_SELECT );
> >
> > glMatrixMode( GL_PROJECTION );
> >
> > glPushMatrix();
> > glLoadIdentity();
> >
> > glGetIntegerv( GL_VIEWPORT, viewport );
> > gluPickMatrix( (GLdouble)p.x, (GLdouble)p.y, 3.0,
> > 3.0, viewport );
> > gluPerspective( 70.0,
> > viewBounds.size.width/viewBounds.size.height, 0.2,
> > 100.0 );
> >
> > glMatrixMode( GL_MODELVIEW );
> > glInitNames();
> >
> > [myScene render]; // Draw all objects.
> >
> > // NOTE: each object should have a
> glPushName(
> > (GLuint)name or ID ); before it gets rendered and
> a
> > GLPopName(); after it gets rendered.
> >
> >
> > glMatrixMode( GL_PROJECTION );
> > gluPerspective( 70.0,
> > viewBounds.size.width/viewBounds.size.height, 0.2,
> > 100.0 );
> > glPopMatrix();
> >
> >
> > GLint numberOfHits = glRenderMode( GL_RENDER );
> > GLuint *ptr = (GLuint *)nameBuffer;
> > int i;
> >
> > for ( i = 0; i < numberOfHits; i++ )
> > {
> > NSLog( @"%d", *(ptr + 3) );
> >
> > ptr += 4; // Go to next record.
> > }
> > }
> >
> >
> > Thanks for all your help Dave.
> >
>
>
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden