current last drawn position to x,y,z

Hello,

I was wondering if some one could help me please as I new to openGL and still trying to figure my way around. I’m working on win98 with VC++ ver 6, what I done so far is to taken the example “Cube” (rotating 3d cube demo) and made some changes so I can draw an x,y,z axis, a cone and a shear.

Also from the mouse position returned as a “Point” I can calculate the selected view position using gluUnProject() so as to draw one of the above object shapes at the mouse location etc tec….

What I would like to do now is to draw a cone at the end of an axis line as it is rotated…

That is to say that after I have drawn a vertex line of the axis I need to find its position so I can start to draw the cone.

// Y line pair
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, -1.0f, 0.0f); …… Would like to draw at cone at this translated position…………

I have spent days trying to figure it out, and the closest I have come to a solution is to use gluUnProject() but know matter how I try I find I can get it to work right… See my code below

GLdouble d_win_x_y_z[3];
CPoint point;
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
GLint viewport[4];

glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
glGetIntegerv(GL_VIEWPORT, viewport);
CRect rect;
GetClientRect(&rect);
int y = rect.Height() - point.y;

glGetDoublev( GL_CURRENT_NORMAL , d_win_x_y_z );

gluUnProject( d_win_x_y_z[0] , d_win_x_y_z[1] , m_fRadius / 7 , modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

Any Ideas please.

Ian Knight

Hm… reading about how much of this super slow glu and glut stuff you are using my soul screams . How ever… well… it’s a bit hard to see, what you need exactly… if you could post some more source, so I can see, which model view matrix transformations you are doing exactly, this would be helpful.

Do you want to first draw something in 3D, then switching to Ortho and paint something in 2D at the position of the last vertex? Or do you just want to draw something in 3D at the position of the last vertex?

BlackJack

[This message has been edited by BlackJack (edited 07-01-2002).]

Originally posted by Ian Knight:

// Y line pair
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, -1.0f, 0.0f); …… Would like to draw at cone at this translated position…………

Well, if you insert the cone drawing code right here, then just drawing it at <0 -1 0> will make it show up at exactly that same location.

The other solution would be to ‘know’ the projection and modelview matrices at the time of drawing the axis and re-creating them by the time you want to draw the cone.

If the cone drawing routine always draws the cone in a fixed place with a fixed orientation, you will have to glTranslate and glRotate to the correct place and position before drawing the cone:
glPushMatrix()
glTranslate()
glRotate()
// draw cone
glPopMatrix()

HTH

Jean-Marc.

Hello,

And many thanks to all that have come back to me re the problem I was having, well more of a miss upstanding of how opengl works…

Jean-Marc.Your suggestion of why I can’t put it at 0,-1,0 (the end of the vertex I just plotted) was the key to me seeing through the forest and into the plain, so to speak… With respect to transformations, nesting of bigingl() and endgl() , glPushMatrix() and glPopMatrix()… What I did was to put each shape to be drawn into a procedure that contains bigingl() and endgl() , glPushMatrix() and glPopMatrix(), and then called the shape procedure from the procedure that require another shape to be drawn relative to itself. Thus discovering how to nest transformations, matrices and drawing stuff, major step forward into understanding how opengl works….

Again Many thanks Jean-Marc.For the enlightenment…