Finding which point´s being clicked on a sphere

Started by
5 comments, last by Rasmadrak 19 years, 10 months ago
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!
"Game Maker For Life, probably never professional thou." =)
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
"Game Maker For Life, probably never professional thou." =)
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]
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
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.. =)
"Game Maker For Life, probably never professional thou." =)
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/

Everything is better with Metal.

Cheers mate!

I´ll look into them right away!
"Game Maker For Life, probably never professional thou." =)

This topic is closed to new replies.

Advertisement