View Full Version : Retrieve the center of a sphere

remedios79

12-23-2002, 07:17 PM

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? http://www.opengl.org/discussion_boards/ubb/smile.gif

Let

glRotate(a, axX, axY, axZ)

glTranslat(x, y, z)

how can I calculate the center C?

Thank you everyone and Merry Christmas!

Remedios

V-man

12-24-2002, 06:25 AM

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

knackered

12-24-2002, 07:02 AM

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:- "http://www.flipcode.com/documents/matrfaq.html" 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.

zeckensack

12-24-2002, 10:55 AM

Merry thingagum to you http://www.opengl.org/discussion_boards/ubb/smile.gif

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 http://www.opengl.org/discussion_boards/ubb/smile.gif

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

SirKnight

12-24-2002, 03:23 PM

FESTIVUS FOR THE RESTOFUS!!

http://www.opengl.org/discussion_boards/ubb/biggrin.gif

-SirKnight

knackered

12-24-2002, 03:41 PM

Originally posted by zeckensack:

Ho, ho, ho http://www.opengl.org/discussion_boards/ubb/smile.gif

Ho ho ho indeed. How terribly efficient. http://www.opengl.org/discussion_boards/ubb/wink.gif

zeckensack

12-24-2002, 04:03 PM

Originally posted by knackered:

Ho ho ho indeed. How terribly efficient. http://www.opengl.org/discussion_boards/ubb/wink.gifHa!

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*

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.