Jump to content
  • Advertisement

Archived

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

Rasmadrak

Finding which point´s being clicked on a sphere

This topic is 5226 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 C

A,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 this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!