Archived

This topic is now archived and is closed to further replies.

Electron

2d positions from 3d calculations?

Recommended Posts

you can use gluProject(...)

try this:

//[in] x,y,z are vertex coordinates
//[out] wx,wy,wz are the returned window coordinate (you can ignore wz)

void GetScreenCoord(double & x,double & y,double & z,
double & wx,double & wy, double & wz)
{
GLint viewport[4]; //array to hold viewport
GLdouble mvmatrix[16],projmatrix[16]; // model/projection matrix

glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);

gluProject(x,y,z,
mvmatrix,
projmatrix,
viewport,
&wx,&wy,&wz);

//now wx,wy have the screen coord.

}

hope that helps

Share this post


Link to post
Share on other sites
I tried using the above code, but it doesn''t seem to be working.

wx and wy are always the same after I do any translations

Share this post


Link to post
Share on other sites