View Full Version : 3D objects and 2D hud

Andrea Doimo

11-13-2000, 04:16 AM

Hi, I have a 2D Hud (using glOrtho) over a 3D scene.

What I need is to obtain the 2D choords of an object displayed in the "3D" layer. (just the object origin: 0,0,0)

In other words, I need to know the on screen x,y coordinates of a point at x1,y1,z1 in the 3D world...

thanks

Andrea Doimo

Probably going to have to get both the model view and perspective matricies from GL, and apply them both to the untransformed location of your 3d object.

Just need a simple vector * matrix function, and use glGetFloatv() calls to get the matrix data.

A potentially easier way that I have never tried is to use glFeedbackBuffer(). I beleive you can get the exact 2d coordinates of rendered objects through it.

Jon

Actually, you have a function called gluProject that will do exactly that for you... It implements what jmX described except that it also takes the viewport into account (yes, you need it !).

So, if you want to use it:

GLdouble modelMatrix[16],projMatrix[16];

GLint viewport[4];

GLdouble winx,winy,winz; // Coordinates of the projected point on the screen //

glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);

glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);

glGetIntegerv(GL_VIEWPORT,viewport);

gluProject(x1,y1,z1,modelMatrix,projMatrix,viewpor t,&winx,&winy,&winz);

Where x1,y1,z1 are the coordinates of the point to project...

Best regards.

Eric

Andrea Doimo

11-13-2000, 05:48 AM

Actually, you have a function called gluProject that will do exactly that for you... It implements what jmX described except that it also takes the viewport into account (yes, you need it !).

Works! Thanks a LOT!

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

Moreover I haven't seen any speed drop (calculating just 5 points/frame)

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