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 565395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:52:04+00:00 2026-05-13T12:52:04+00:00

I have a renderer using directx and openGL, and a 3d scene. The viewport

  • 0

I have a renderer using directx and openGL, and a 3d scene. The viewport and the window are of the same dimensions.

How do I implement picking given mouse coordinates x and y in a platform independent way?

  • 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-13T12:52:04+00:00Added an answer on May 13, 2026 at 12:52 pm

    If you can, do the picking on the CPU by calculating a ray from the eye through the mouse pointer and intersect it with your models.

    If this isn’t an option I would go with some type of ID rendering. Assign each object you want to pick a unique color, render the objects with these colors and finally read out the color from the framebuffer under the mouse pointer.

    EDIT: If the question is how to construct the ray from the mouse coordinates you need the following: a projection matrix P and the camera transform C. If the coordinates of the mouse pointer is (x, y) and the size of the viewport is (width, height) one position in clip space along the ray is:

    mouse_clip = [
      float(x) * 2 / float(width) - 1,
      1 - float(y) * 2 / float(height),
      0,
      1]
    

    (Notice that I flipped the y-axis since often the origin of the mouse coordinates are in the upper left corner)

    The following is also true:

    mouse_clip = P * C * mouse_worldspace
    

    Which gives:

    mouse_worldspace = inverse(C) * inverse(P) * mouse_clip
    

    We now have:

    p = C.position(); //origin of camera in worldspace
    n = normalize(mouse_worldspace - p); //unit vector from p through mouse pos in worldspace
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using OpenGL ES on Android to draw some shapes, so I have some
I'm using SlimDX, targeting DirectX 11 with shader model 4. I have a pixel
I have a game using OpenGL. I've built off of the examples, for the
I have a custom cell renderer set in JTable and it works but instead
I have a component which writes/generates javascript from a server side renderer. This component
I have a data grid that has a checkbox item renderer in a cloumn
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I'm porting a DirectX application into WPF, using the Windows.Media.Media3D toolkit. Which is working
I would like to make an application in a one window using XAML. It

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.