a math problem, how to find a point

Hi all
I have to find this point.

My main loop for render looks like this:

glLoadIdentity();/now we are in the world coord/
glPushMatrix();
glRotate(A,0,1,0);
glRotate(B,1,0,0);
glBegin(GL_POINT);//draw a point XZ
glVertex(x,0,z);
glEnd;
glPopMatrix();
Now i want to find out the world coord of the point XZ. It seems so difficult to me. I believe there are a lot of guys much more intelligent than me, if you could help me with this i shall be very happy and very grateful.
Liuya

Hi,

You could get the modelview matrix (with glGetFloatv) and multiply your point vector with it. That should do it.

-Ilkka

Originally posted by JustHanging:
[b]Hi,

You could get the modelview matrix (with glGetFloatv) and multiply your point vector with it. That should do it.

-Ilkka[/b]

HI Ilkka:

Thanks a lot. I understand your suggestion will bring it an easy solution instead of a lot of math. But as you know i am new at opengl I still have no idea of how to make your idea into the actual code. Could you show me the steps in more detail?
Many thanks again!
Liuya

Ok, this is how it goes. This is in Delphi (my second native language), but it’s easy to translate to c. First you get the modelview matrix by

glGetFloatv(GL_MODELVIEW_MATRIX, addr(m));

where m is array[0…3, 0…3] of glFloat,

then you set worldCoord:=transform4(pos, m). The transform4 function looks like following

function transform4(v : vector; mat : matrix4): vector;
var
temp : vector;
w : float;
begin
w:=v[0]*mat[0, 3]+v[1]*mat[1, 3]+v[2]*mat[2, 3]+mat[3, 3];

temp[0]:=(v[0]*mat[0, 0]+v[1]*mat[1, 0]+v[2]*mat[2, 0]+mat[3, 0])/w;
temp[1]:=(v[0]*mat[0, 1]+v[1]*mat[1, 1]+v[2]*mat[2, 1]+mat[3, 1])/w;
temp[2]:=(v[0]*mat[0, 2]+v[1]*mat[1, 2]+v[2]*mat[2, 2]+mat[3, 2])/w;
transform4:=temp;
end;

In c you will have to replace addr(m) with m, and let m be of type glFloat[15]. Then you replace m[i, j] by m[i*4+j]. I hope that was correct, c isn’t one of my strong points.

-Ilkka

Sorry, i made a mistake:

glLoadIdentity();/now we are in the world coord/
glPushMatrix();
glTranslate( to a point);//
glRotate(A,0,1,0);
glRotate(B,1,0,0);
glBegin(GL_POINT);//draw a point XY
glVertex(x,y,0);//this was X,Z********
glEnd;
glPopMatrix();
Now i want to find out the world coord of point XY.

Here i want to describer the background of my problem.
I need to draw a cylinder in any position (knowing coord of its base and top)in the space. There are some points(their coord are known if you call glCylinder without doing any transformation) on both planes of its base and top. I have to know the coord of these points after transformation for some other objects(e.g. lines) to reach to. This should be done during initialization to fill the data(this shouldn’t be a problem, i can do a try render, right?).

Ilkka, I read your last post, but i don’t understand it. Maybe the language is one obstacle, but i just couldn’t see how MY vector shall be calculated.

I need more help! Ilkka you again or anyone else?
Thanks

Ok, maybe I could write it open, assuming you have the modelview matrix (after the rotations) in a glFloat array,

w = xm[3]+ym[7]+m[15];

worldx = (xm[0]+ym[4]+m[12])/w;
worldy = (xm[1]+ym[5]+m[13])/w;
worldz = (xm[2]+ym[6]+m[14])/w;

Totally untested. Good luck!

-Ilkka

Originally posted by JustHanging:
[b]Ok, maybe I could write it open, assuming you have the modelview matrix (after the rotations) in a glFloat array,

w = xm[3]+ym[7]+m[15];

worldx = (xm[0]+ym[4]+m[12])/w;
worldy = (xm[1]+ym[5]+m[13])/w;
worldz = (xm[2]+ym[6]+m[14])/w;

Totally untested. Good luck!

-Ilkka[/b]

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!