Retrieve the center of a sphere

Hi!

I apologize if this argument is not advanced…

I want to retrieve the center of a sphere after a rotation and a translation.

I know that if I use only a translation, the center is exactly the coordinate of the traslation, but if I rotate before then the local coordinate system of the sphere is not more aligned with the global coordinate system, and I don’t know how to retrieve the right coordinates.

I know, I have to study trigonometry… but in the meantime, anyone can helps me?

Let
glRotate(a, axX, axY, axZ)
glTranslat(x, y, z)
how can I calculate the center C?

Thank you everyone and Merry Christmas!

Remedios

Search for rotation matrix on the internet or better yet, general rotation matrix.

The Red Book shows you how transformation works.

It’s really not hard to find info like this on the internet.

V-man

Mmm, the thing is you’re going to have get hold of that matrix you’re manipulating. You can do this using glGetFloatv, or actually doing all this matrix maths on your own matrix in system memory, then uploading it to GL with glLoadMatrix (recommended approach)…or doing the maths twice by mirroring your gl calls with your own maths, but that’s insane).
If you do the matrix maths yourself (which is pretty easy, just go here:- “Matrix and Quaternion FAQ” and copy and paste, if you can’t be arsed understanding whats going on).
Eventually, you’ll want to transform your translation by the rotation matrix you create with your glRotate.

Merry thingagum to you

float matrix[16];
float center_of_sphere[4]={0.0f,0.0f,0.0f,1.0f};
glGetfv(GL_MODELVIEW_MATRIX,matrix);

float transformed_center_of_sphere[4];
//insert fancy matrix*vector calc here
mult_vector4_matrix(&transformed_center_of_sphere,center_of_sphere,matrix);

float oow=1/transformed_center_of_sphere[3];
transformed_center_of_sphere[0]*=oow;
transformed_center_of_sphere[1]*=oow;
transformed_center_of_sphere[2]*=oow;
transformed_center_of_sphere[3]=1.0f;

Ho, ho, ho

[This message has been edited by zeckensack (edited 12-24-2002).]

FESTIVUS FOR THE RESTOFUS!!

-SirKnight

Originally posted by zeckensack:
Ho, ho, ho

Ho ho ho indeed. How terribly efficient.

Originally posted by knackered:
Ho ho ho indeed. How terribly efficient.
Ha!
With the center always fixed at (0;0;0) I can even do better.

float matrix[16];
glGetfv(GL_MODELVIEW_MATRIX,matrix);

float transformed_center_of_sphere[3];
transformed_center_of_sphere[0]=matrix[12];
transformed_center_of_sphere[1]=matrix[13];
transformed_center_of_sphere[2]=matrix[14];

sheepish grin