I wanted to render a section of a sphere and then find the normals at every point on the shape. I want the radius of the sphere to be 10cm. Can anybody tell me how to do that in opengl?

Normal in (x, y, z) is the normalized radius direction. For point (x, y, z) e S it would be then

((x - x0), (y - y0), (z - z0))/R where

(x0, y0, z0) is the center of the sphere.

You should have post it in the beginners forum thought…

1.) There is no measurement like 10cm or 10" or 10 meteres in OpenGl…

2.) OpenGL won’t do this for you.You’ll have to write an own algorithm to calculate the vertexdata for the section of a sphere (not that hard.I did it some time ago) and then you’ll also have to calculate the normals on your own.

3.) I hate crossposting…

I think the following advice should be put in FAQ, when it is created (you know, the OpenGL site is being restructured) :

If you’d like to post offtopic/too-general/too-beginner question here and still get some useful help instead of only getting bashed/insulted/patronised, then do post using a nick suggesting that you are a female.

How funny

sorry. I posted on beginner too but i thought some people might not look at that list if theyre advanced… :S

thanks for all the suggestions.

You can always generate a sphere using spherical coordinates. If you understand this coordinate system, generating verticies for a sphere is very easy. Then next part is then creating the winding. After that is all said and done, generating a normal (for each triangle) is just a simple normalize( cross( V1 - V0, V2 - V0 ) ).

-SirKnight

[This message has been edited by SirKnight (edited 10-27-2003).]

Jessica, mmm, that’s a nice name.

Where you from Jessica?

What colour’s your hair?

Originally posted by knackered:

Jessica, mmm, that’s a nice name.

Where you from Jessica?

What colour’s your hair?

nerd

Originally posted by Jan2000:

nerd

Who isn’t on this board?

-SirKnight

I’m not.

Live long and prosper…

Originally posted by Jan2000:

nerd

I take it you missed the irony?

Thought so…

Don’t you think Jessica could have gotten the answer for her assignment from the dude sitting next to her without harrassments from you guys?

[This message has been edited by Coconut (edited 10-28-2003).]

Check out this thread

http://www.opengl.org/discussion_boards/ubb/F

orum2/HTML/014273.html

“excuse me ! who is Silvia , I did not get your point” <-- playing dumb

"Let me introduce you to Silvia: " <-- heating the room

"why did not I tell you the truth at the beginning " <-- gives up and admits

case closed!

Originally posted by knackered:

I take it you missed the irony?

Thought so…

How ironic he missed the irony.

Let see, a .26mm dot pitch monitor would make 10cm be … Knackered can figure this out.

I am so glad I contributed to this thread!

p.s, … err… forget it… I must be dead tired.

Thanks for the replies. I just am having trouble with the rendering… I know the equation of a sphere. But I dont know exactly how to set all the vertices … Does anyone have a pointer to an example?

Thanks again, and Im sorry for all the commotion i caused

For generating the vertices for a sphere, I think these equations will be more helpful. http://www.math.montana.edu/frankw/ccp/multiworld/multipleIVP/spherical/body.htm

-SirKnight

This may not be all you need or the best but this code snippet should get you started. It will generate the vertices for a sphere, but you still need to compute the winding and everything.

vec3_t GetVertex( float rho, float phi, float theta )

{

vec3_t v;`v[0] = rho * sin( phi ) * cos( theta ); v[1] = rho * sin( phi ) * sin( theta ); v[2] = rho * cos( phi ); return v;`

}

float rho = radius;

int i = 0;for( float theta = 0.0f; theta < 2*PI; theta += 0.01f ) // play with the 0.01 if it’s not good enough

{

for( float phi = 0.0f; phi < PI; phi += 0.01 )

{

SphereVerts[i++] = GetVertex( rho, phi, theta );

}

}

-SirKnight

thanks sir knight… just a question - what is sphereverts? and 3D array?

thanks

Ah geeze I forgot to define that, sorry. SphereVerts is just an array of vec3_t. And obviously vec3_t is just “typedef float vec3_t[3];” Now to determine the size of SphereVerts can be done in a few ways. One way is to figure out how many iterations each loop there makes and multiply those two numbers together. That number will be the size SphereVerts needs to be. So lets say that the outer loop makes 628 iterations and the inner loop makes 314 iterations. Then SphereVerts will be defined as "vec3_t SphereVerts[628*314];" I figured those numbers out by dividing 2*PI by 0.01 and dividing PI also by 0.01.

You could even put each vertex made in a linked list, then once that is done check the variable that holds the number of nodes in your linked list class and take that to allocate the SphereVerts array then copy all verts from the list to the array. I would probably not do this but it is one other solution.

Now of course there is still more work to be done than this. That code snippet just generates vertices but no information about winding or anything else is present. But at least the vertices are there to have something to work with.

-SirKnight

[This message has been edited by SirKnight (edited 10-30-2003).]