#### Archived

This topic is now archived and is closed to further replies.

# Finding which point´s being clicked on a sphere

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

## Recommended Posts

Hiya! I''m doing my part of game creation by doing a remake of the old UFO - Enemy Unknown and so far things are working out quite well. =) I now need a formula for getting the point in 3d space by clicking on a "2D disc shape". Let me explain: I''m using a fixed perspective which can be zoomed in and out, and the earth can be rotated along WorldX,WorldY. - Using fixed perspective, I could probably use some form of sin/cos and hypot(ClickedX-CenterofScreenX,ClickedY-CenterofScreenY) to get a point on the sphere''s surface? Problem is that I cannot really figure this out... what seemed like a easy solution now seem very daunting... :/ I don''t know if I''ve made myself clear about what I need help with, but any help I can get is greatly appreciated!! :D Cheers!

##### Share on other sites
I found a rather cheesy solution.. using opengl´s own Picking/selection system... and then assigning each triangle a nr that is used for identification.

now a "find a point inside a triangle" would be nice... =P

##### Share on other sites
You'll have to transform your 2d point with your projection matrix giving you a 3d line through your world space. Then intersect this line with your 3d sphere, returning you 2 points. The nearest point is one you want.

Transforming the 2d 'click' point to 3d is do-able, I just honestly don't know how :/ The intersections (both sphere/line and triangle/line) themselves should show up in basic ray-tracing tutorials.

Also, once you know what triangle is hit, you'll still probably need to project your 2d click-point into 3d somehow.

[edited by - PyroSA on June 3, 2004 3:29:57 PM]

##### Share on other sites
take a look at gluUnProject(). it should take your 2d point and turn it into a 3d point.

Make a ray from your camera, through the second point. Intersect the ray with the sphere/triangle object. (Google "sphere ray intersection if you aren''t familar with intersections) You should be able to determine what object with the gl picking stuff.

hope that helps.

Robbie

##### Share on other sites
Hi ya!

Thanks for answering, but I''ve already found which triangle is being hit using OpenGL selection.. =)
I would need to find out where inside the triangle the user clicks...

A      /\     /  \         x = clicked point.    /    \   /      \  /     x  \ /__________\B           CA,B,C are known variables. They are also a point in space with its own x,y,z values.

This should be an issue of standard math.. but I barely made it out of school alive so.. =)

##### Share on other sites
you mean, the cordinates of X(x, y, z)?

hundreds of ways

a way that''s hard to describe, but very efficient, is the barycentric coordinates, or the plucker coordinates. that also returns other useful info, like the ''texture coordinates'' withing that triangle.

if you are not bothered, you can just construct the triangle plane, and do a ray-plane intersection.

both are available here

http://www.realtimerendering.com/int/

##### Share on other sites
Cheers mate!

I´ll look into them right away!

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 9
• 15
• ### Forum Statistics

• Total Topics
633392
• Total Posts
3011638
• ### Who's Online (See full list)

There are no registered users currently online

×