Cartesian coords on a sphere...

Hi Everyone!
My first post - very happy to be here :slight_smile:

Well, I’m getting myself into a mental pickle regarding how best to approach the following user story:

  1. I have a rotating sphere in front of me
  2. I want to spawn cubes on its surface in pre-determined locations (NOT random)
  3. In the best of all possible worlds, these cubes would spawn in X,Y,Z coords because I want to test their position against mouseclicks later on

My question is, what would the best approach be to generate the positions of these cubes?

Should I be pursuing:

  • gluProject and gluUnProject ?
  • converting Spherical coords to Cartesian coords

Or if you have a different workflow altogether that you’d like to suggest, please let me know.

I’m definitely not asking for a step by step. Just looking for a push in the right direction :slight_smile:

Thank you so much for your time.
And Happy Thanksgiving by the way!

Oh!, and my development environment is XCode 4.0.2 And I’m simply drawing to GLUT and employing C++.

-kropcke

Hi,
I would go with spherical coordinates to get my xyz position. Just refreshing them again for you. You will need to cycle theta and phi. Something along these lines will help.


for(int j=0;j<10;j++) {
   float theta = (j/10.0)*M_PI;
   for(int i=0;i<10;i++) {
      float phi = (i/10.0)*2*M_PI;
      float x = radius * sin(theta) * cos(phi);
      float y = radius * sin(theta) * sin(phi);
      float z = radius * cos(theta);	
      glPushMatrix();			
	  glTranslatef(x,y,z);
	      glutSolidCube(0.1);
      glPopMatrix();      
   } 
}

This will create a cube at each vertex of a 10x10 sphere. See if you can orient the cube to the vertex normal at the point on surface.

Thank you very much mobeen.

That’s exactly the advice I needed.
I look forward to spending more time here on the message boards.

Thank you again.
-kropcke