Jump to content
  • Advertisement
Sign in to follow this  

Ray picking

This topic is 3026 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hy, I'm trying to get the location where I clicked with the mouse to use it as a ray_to position in 3D space for ray picking objects with Bullet rayTest function. I wrote this code (don't mind that the code is not optimised): ray_to.x = tmp_v2f.x/( ( tan( 45.f*PI/180.f )/100.f )*800.f ); /// convert x coordinates ray_to.x -= ( 800.f/( ( tan( 45.f*PI/180.f )/100.f )*800.f ) )*0.5f; /// 0 is the center of the screen ray_to.y = tmp_v2f.y/( ( tan( 45.f*PI/180.f )/100.f )*600.f ); /// convert y coordinates ray_to.y = ( ( 600.f/( ( tan( 45.f*PI/180.f )/100.f )*600.f ) )*0.5f )-ray_to.y; /// 0 is the center of the screen ray_to.z = -100.f; ///set depth m4f.Translate( ray_to ); /// translate camera coords ray_to = m4f.Get_Pos(); /// get the new position tmp_v2f variable contains x and y mouse coordinates 100.f is the depth of the depth of the location where I'm sending ray to 800.f and 600.f are window widh and height 45.f is the camera angle degrees value m4f contains the camera matrix (the matrix 4x4 matrix from which I get ray_from coords) In the above code I'm trying to convert mouse coords to 3D space coords. Since I have the degrees and the depth I'm using the above code to get the horizontal/vertical length of a 90degree triangle. I don't know why I'm getting greater and greater offset (click outside the object to pick that object) the further I click from the center of the screen. Has anyone got an idea what I'm doing wrong here? I'm writing this code on Linux so the top left corner is 0,0 and bottom right is 800,600. For rendering I'm using OpenGL. I'm not very good at math so please give me a math for dummies answer. Thanks, Domen

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!