• 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: Ian was here <email@hidden>
  • Date: Sat, 6 Oct 2007 11:07:47 -0700 (PDT)

Your technique works! I get world coordinates each
time I click on the mouse. Here's the code that I
implemented:


- (void)clickedAtPoint:(NSPoint)p
{
	GLdouble	model[16];
	GLfloat	proj[16];
	GLint		view[4];

	glGetDoublev( GL_MODELVIEW, model );
	glGetFloatv( GL_PROJECTION, proj );
	glGetIntegerv( GL_VIEWPORT, view );


	GLdouble	wx, wy, wz;

	if ( gluUnProject( (GLdouble)p.x, (GLdouble)p.y, 0.0,
model, proj, view, &wx, &wy, &wz ) == GL_TRUE )
	{
		NSLog(@"x: %f\ty: %f\t\twx: %f\twy: %f", p.x, p.y,
wx, wy );
	}
}


Please note that the passed-in point value (p) has
already been converted to view coordinates in the
-mouseDown: method.

NSPoint		p = [self convertPoint:[theEvent
locationInWindow] fromView:nil];


The only issue that I'm having is that I'm getting
some rather strange values. Such as...


This is clicking on the center of the view:
x: 377.000000	y: 270.000000		wx: 0.175438	wy:
-0.899123

Which seems OK.


This is the upper-left corner:
x: 41.000000	y: 582.000000 wx: -987407225.612816	wy:
942763954.976947


And this is near the lower-right corner:
x: 770.000000	y: 30.000000		wx: 0.000000	wy: -1.000000


There is one last step that I seem to be missing...





--- David Spooner <email@hidden> wrote:

> Here is some psuedo code which may help...
>
> // First convert the point p from the NSView's
> coordinate system into
> screen (viewport) coordinates...
> NSPoint q = p - [view visibleRect].origin;
>
> // Get the modelview and projection matrices and the
> viewport from
> OpenGL...
> double M[16], P[16];
> GLint V[4];
> glGetDoublev(GL_MODELVIEW, M);
> glGetFloatv(GL_PROJECTION, P);
> glGetIntegerv(GL_VIEWPORT, V);
>
> // Then inverse-project from screen coordinates to
> world coordinates...
> double wx, wy, wz;
> gluUnProject(q.x, q.y, 0, M, P, V, &wx, &wy, &wz);
>
>
> dave
>
>




____________________________________________________________________________________
Yahoo! oneSearch: Finally, mobile search
that gives answers, not web links.
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
_______________________________________________

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

  • Prev by Date: Re: NSTableView questions
  • Next by Date: Running Shell Script from Cocoa Application
  • Previous by thread: Re: make class cluster
  • Next by thread: Re: Convert NSOpenGLView pixel coordinates to OpenGL world coordinates
  • Index(es):
    • Date
    • Thread