We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Mapping mouse coordinates to a sphere surface
Page Index Toggle Pages: 1
Mapping mouse coordinates to a sphere surface (Read 2114 times)
Mapping mouse coordinates to a sphere surface
Jun 22nd, 2009, 1:00pm
 
Hello,
I have a sphere and I move the camera around it using PEasyCam. I want to catch the coordinates of the mouse when clicked on the sphere surface. I would also like to convert those coordinates to spherical coordinates of the sphere. What do you think, where should I start it? Have you met this problem before?
Thank you,
zb.
Re: Mapping mouse coordinates to a sphere surface
Reply #1 - Jun 23rd, 2009, 7:13am
 
your magic word is arcball. google it up and you'll find plenty of example code how to implement it. Smiley
Re: Mapping mouse coordinates to a sphere surface
Reply #2 - Jun 23rd, 2009, 11:01am
 
This article and library might be useful

http://processing.org/hacks/hacks:arcball
Re: Mapping mouse coordinates to a sphere surface
Reply #3 - Jun 25th, 2009, 8:59am
 
I believe the poster stated that he already had the camera view working.

He's trying to get mouse picking to work, something that I've only messed with in the OPENGL renderer.

You could

1) Look up info on "picking" in OPENGL using the buffers

2) You can use screenX(0,0,0) and screenY(0,0,0) to get the screen coords of the current origin (you can move around with translate / rotate): So, make a big map of the screen coordinates of, say, 100 points on the sphere, and then whenever you get the mousepressed, choose the point that is closest. Careful though, because the "backside" of the sphere and the "frontside" points will both match.

Either way should work, both are tricky.
Re: Mapping mouse coordinates to a sphere surface
Reply #4 - Jun 26th, 2009, 1:53am
 
Hello ps, Quark,
thanks for your answer. Unfortunately the arcball isn't the right projection of a sphere to the screen and vice versa.

Dear Taifunbrowser,
thanks for your comment. I will try your ideas, too. I like the opengl buffer idea, however, I am still looking for a solution which costs less memory and cpu time.

Thank you again,
zb.
Re: Mapping mouse coordinates to a sphere surface
Reply #5 - Jul 19th, 2009, 6:32am
 
Hi Zaphod.

I'm working on a sketch that's trying to do something similar. Plot a hundred or so points on the surface of a sphere, and then tell which of the points the mouse is clicking. Please post back to this thread if you find a nice way of doing it, and I'll do the same.

-- omygawshkenas
Re: Mapping mouse coordinates to a sphere surface
Reply #6 - Jul 19th, 2009, 11:29am
 
Using the picking method detailed here is working really well for me (w/ Ruby-Processing):

http://processing.org/hacks/hacks:picking_color_buffer

The gist of it is: Make a buffer, draw all the points you're interested in into it with unique colors, and then get the color value of the pixel that you clicked on. Look up the corresponding point and you're done.

Re: Mapping mouse coordinates to a sphere surface
Reply #7 - Jul 20th, 2009, 5:29am
 
In my engine I use the following to convert the camera position from xyz to spherical and viceversa.
phi and theta are the spherical coordinates, radius is the sphere radius, and position interest and upvector are 3 vectors used for the camera rig.

Code:

void xyz_from_spherical_coords()
{
position.x = radius * cos( theta ) * sin( phi );
position.y = radius * cos( phi );
position.z = radius * sin( theta ) * sin( phi );
upvector.x = -cos( theta ) * cos( phi );
upvector.y = sin( phi );
upvector.z = -sin( theta ) * cos( phi );
position.add_in_place( interest );
}

void spherical_coords_from_xyz()
{
position.sub_in_place( interest );
radius = position.length();
theta = atan2( position.z, position.x );
phi = acos( position.y / radius );
position.add_in_place( interest );
}
Page Index Toggle Pages: 1