Jump to content

  • Log In with Google      Sign In   
  • Create Account

Finding the object a user clicked on


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 metsfan   Members   -  Reputation: 654

Like
1Likes
Like

Posted 21 August 2012 - 08:39 AM

Hello all,

I am trying to devise an algorithm to which object in my 3D world the user clicked. If two targets are close to eachother, the one closer to the near plane will be chosen. Here is my thought process for how to build this algorithm, and I just want to make sure I'm on the right track before I get too deep into this

My near distance on my view frustum is 1.0

1) Determine the direction vector between the origin and the spot clicked on the screen. This is done by calculating the following values:
[source lang="cpp"]float rayX = (position.x / halfWidth) - 1;float rayY = -(position.y / halfHeight) - 1;float rayZ = 1.0f;[/source]

This produces a ray with values -1 <= x <= 1 and -1 <= y <= 1. The z-coordinate is equal to the distance to the view frustum near plane.

2) Transform the near plane by the inverse transpose of the (modelview * projection) matrix

3) Calculate the intersection point between this ray and the transformed near plane.

4) From this intersection point create a ray with the intersection point as the start point of the ray, and the vector (0, 0, 1) as the direction vector.

5) For each object that is clickable, test if the ray intersects the bounding volume of the mesh

5a) if more than 1 match is found, the intersection point with the closest z coordinate to the near plane is chosen.

Am I totally off here? Am I close but need some tweaking? Am I greatly overcomplicating this problem? Any help would be great.

Thanks in advance.

Sponsor:

#2 lride   Members   -  Reputation: 633

Like
1Likes
Like

Posted 22 August 2012 - 11:29 AM

if you are using opengl try this site
http://www.opengl.org/discussion_boards/showthread.php/175699-How-to-click-on-3D-objects-with-mouse
An invisible text.

#3 metsfan   Members   -  Reputation: 654

Like
0Likes
Like

Posted 22 August 2012 - 01:36 PM

Thank you, this post gave me the information I needed.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS