beginner620824

03-14-2003, 03:26 AM

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);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //

glLoadIdentity();

//below some stuff for the viewer walking around the world, don' care it much*/ float xtrans = -xpos;

float ztrans = -zpos;

float ytrans = -0.25f-ypos;

float sceneroty =360.0f-yrot;

glRotatef(lookupdown,1.0f,0,0);

glRotatef(sceneroty,0,1.0f,0);

glTranslatef(xtrans, ytrans, ztrans);

/*!!!!!!!!!!!!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)*/

for(int i=0;i<10;i++)

{

float x=0.005*sin(DTOR*36*i);

float y=0.005*cos(DTOR*36*i);

glVertex3d(x,y,0);

glVertex3d(x,y,len);

}

glEnd();

glPopMatrix();

}

//**********************************

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];

worldx = (x*m[0]+y*m[4]+m[12])/w;

worldy = (x*m[1]+y*m[5]+m[13])/w;

worldz = (x*m[2]+y*m[6]+m[14])/w;

Totally untested. Good luck!

-Ilkka

--------------------------------------------------------------------------------

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!

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);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //

glLoadIdentity();

//below some stuff for the viewer walking around the world, don' care it much*/ float xtrans = -xpos;

float ztrans = -zpos;

float ytrans = -0.25f-ypos;

float sceneroty =360.0f-yrot;

glRotatef(lookupdown,1.0f,0,0);

glRotatef(sceneroty,0,1.0f,0);

glTranslatef(xtrans, ytrans, ztrans);

/*!!!!!!!!!!!!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)*/

for(int i=0;i<10;i++)

{

float x=0.005*sin(DTOR*36*i);

float y=0.005*cos(DTOR*36*i);

glVertex3d(x,y,0);

glVertex3d(x,y,len);

}

glEnd();

glPopMatrix();

}

//**********************************

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];

worldx = (x*m[0]+y*m[4]+m[12])/w;

worldy = (x*m[1]+y*m[5]+m[13])/w;

worldz = (x*m[2]+y*m[6]+m[14])/w;

Totally untested. Good luck!

-Ilkka

--------------------------------------------------------------------------------

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!