• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert NSOpenGLView pixel coordinates to OpenGL world coordinates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert NSOpenGLView pixel coordinates to OpenGL world coordinates


  • Subject: Re: Convert NSOpenGLView pixel coordinates to OpenGL world coordinates
  • From: Alastair Houghton <email@hidden>
  • Date: Thu, 4 Oct 2007 18:03:11 +0100

On 4 Oct 2007, at 17:36, Ian was here wrote:

I've googled this one and have found some interesting
info, but no clear-cut way to convert an
NSOpenGLView's X,Y coordinate to an OpenGL world's X,Y
coordinate (not too concerned with the Z coordinate).
I need to know if two dimensional objects are getting
mouse clicks.

Has anyone done this before or know of any sample
code? Thanks.

It depends on the GL projection matrix and viewport you've established. In our code, we set ours up so that there was a 1:1 mapping from GL co-ordinates to points (not pixels, mind...):


  NSRect bounds = [self bounds];

  // Update the viewport
  glViewport (0, 0, NSWidth (bounds), NSHeight (bounds));

  // Update the projection
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();
  gluOrtho2D (0.0, NSWidth (bounds), 0.0, NSHeight (bounds));

  glMatrixMode (GL_MODELVIEW);

If you do that, then you can just use the same co-ordinate system in both places. Without that, you'll have to transform either the mouse co-ordinates or the co-ordinates of the things you're testing against to get them into the same co-ordinate space.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

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


References: 
 >Convert NSOpenGLView pixel coordinates to OpenGL world coordinates (From: Ian was here <email@hidden>)

  • Prev by Date: Re: Question about NSURLRequest
  • Next by Date: Re: Z_OPT field in coredata sqlite database. What it is for?
  • Previous by thread: Convert NSOpenGLView pixel coordinates to OpenGL world coordinates
  • Next by thread: NSMutableArray to NSArray?
  • Index(es):
    • Date
    • Thread