Hi all and Ilkka:
I am having a big trouble to find out the world coord of a point which has been done by certain transformations.
I think i am hopeless if i can't get any help from you.
Please and thanks, liuya

below is somwhat of my main loop for render
int DrawGLScene(GLvoid)
{
glClearColor(0.0,0.0,0.0,0.0);

/*!!!!!!!!!!!!here i call a functoin to draw a cylinder*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/

drawcylinder(0.1,1,1,1,2,2,2);

/*/!!!!!now i want to know the location, in world coord,of those points on the base/top of the cylinder*/

}
//************************************************** ********************************************
void drawcylinder(float r,float x1,float y1,float z1,float x2,float y2,float z2)
{
//r=radius
//x1,y1,z1, the center of the base
//x2,y2,z2, the center of the top
//DTOR=3.1415/180.0f
float len, angleA,angleB;
len=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
angleA=atan((x2-x1)/(z2-z1));
angleB=asin((y2-y1)/len);
glPushMatrix();
glTranslatef(x1,y1,z1);
glRotatef(angleA/DTOR,0.0f,1.0f,0.0f);
glRotatef(-angleB/DTOR,1,0,0);
glColor3f(0.3,0.0,0.9);
gluCylinder(obj,r,r,len,8,1);
glColor3f(1,1,1);
glBegin(GL_LINES);
//below i make some points on the plane of both base and top and draw a line between them(the base and top)*/

There has been some help from Ilkka which can be found in my post "a math probelm, how to find a point". you can see it also as below. I just can't figure out where i should put glGetFloatv(i tried putting it everywhere, the ouptput never made any sense)
and what the XYZ is, are they the world coord of the point (which i want to find) before transformatoin?

quote:
--------------------------------------------------------------------------------
Originally posted by JustHanging:
Ok, maybe I could write it open, assuming you have the modelview matrix (after the rotations) in a glFloat array,
w = x*m[3]+y*m[7]+m[15];

Hi Ilkka:
Thanks a lot.
this formula seems to be specific to my question since there is no Z. What shall i read if i want to fully understand and handle it myself? now i know there is a lot to learn about opengl. well i will try it first!

These formulas mean multiplying a column vector (x, y, z, 1) with 4*4 matrix. The division by w is because of the homogenous coordinates used in OpenGL. The x, y and z coordinates you use in it should be the x, y and len coordinates you use to draw lines after the cylinder. The worldx, -y and -z coordinates are the world coordinates of these points, so they should appear in place if drawn after the glPopMatrix.

I think the reason this goes wrong is, that you have the viewer transform in the same matrix. I missed that before, sorry about that. To get it right, you should first call glLoadIdentity, then apply the cylinder's transformations, and then get the matrix.

-Ilkka

beginner620824

03-14-2003, 03:20 PM

HI Ilkka:

Thanks a lot, it works in a simple test. I believe this is the way to do it. i am so happy with it and so grateful to your great help. Internet is great and people like you in it are great!
But my actual code still has a long way to go, no doubt there will be more troubles which need help again and again.
Best regards, Liuya