Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:15:38+00:00 2026-05-28T13:15:38+00:00

I want to be able to click the touch screen and use the point

  • 0

I want to be able to click the touch screen and use the point touched as the starting coordinate for a ray to be used for picking.

How do I convert the point returned from touching the screen into something I can use in the GL world coordinates?

A search brings up lots of confusing possibilities, including the use of gluUnProject with lots of reports about whether it is supported and how to port it.

Can someone lay it out straight for me please?

I’m using Objective C, Xcode and I’m compiling for iphone.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:15:38+00:00Added an answer on May 28, 2026 at 1:15 pm

    Step 0: Get gluUnproject:

    The reports of needing it are true. That function does all the heavy lifting for you. I know at one point the MESA project had an implementation the worked almost perfectly on iOS without modifications. I’m not sure if that’s still available. Barring that, you’ll just have to do some research on it and either roll your own or port someone else’s. It’s a bit heavy on the Linear Algebra, so good luck.

    Step 1: Convert from UIKit coordinates to OpenGL coordinates:

    This normally involves two things:

    1. Flip the Y-coordinate, because UIKit likes its origins in the top left, whereas OpenGL likes its origins in the bottom left.

      touchLocation.y = [[self view] bounds].size.height - touchLocation.y;
      
    2. Convert from “Screen Units” to pixels. This keeps things consistent across standard and retina display devices.

      CGFloat scale = [[UIScreen mainScreen] scale];
      touchLocation.y *= scale;
      touchLocation.y *= scale;
      

    Step 3: Use gluUnproject on your converted coordinate:

    gluUnproject() technically converts a 3D point in window space to a 3D point in world space. So, to get a ray, you’ll need to call it twice: once for the near clipping plane and once for the far clipping plane. That will give you two points, from which you can get a ray. To call gluUnproject(), you’ll need access to your 2D view coordinate, the current OpenGL viewport, the current OpenGL model view matrix, and the current OpenGL projection matrix. Pseudocode:

    Vector3 near, far;
    gluUnProject(touchLocation.x, touchLocation.y, 0, _modelview, _projection, _viewport, &near.x, &near.y, &near.z);
    gluUnProject(touchLocation.x, touchLocation.y, 1, _modelview, _projection, _viewport, &far.x, &far.y, &far.z);
    return MakeRay(near, Vector3Subtract(far, near));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to click a button and open a new form
I want to add a click able button to a MKAnnotation as seen in
My exe processes text documents and I want to be able to right click
Simple problem (I think): I want to be able to invoke a click method
I want to be able to open my website and use some kind of
I want to be able to use mklink to create symbolic links on my
I used to be able to double-click the work area of a dataset to
I want to be able to click on a part of a webpage and
I want to be able to click (or cmd+click on my Mac) on a
I want to be able to click on a widget and launch a dialog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.