Jump to content
  • Advertisement

Archived

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

Electron

2d positions from 3d calculations?

This topic is 5507 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wonder if there is a way to retrieve 2d (screen) positions on a vertex after doing all transform and rotate calculations?

Share this post


Link to post
Share on other sites
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!