Jump to content
  • Advertisement


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


3d to 2d coordinates

This topic is 5160 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 have my viewport coordinates vx, vy and vz.. and i have object coordinates x, y, z. How would i get the objx, objy and objz needed by gluProject from these? Or is there another way I should go about transforming 3d coordinates into screen coords? Im trying to make a target reticle like the ones in spacesims.. Its a bounding box around other ships.. But how would i get the screen x and y from the shipx, shipy and shipz..

Share this post

Link to post
Share on other sites
Instead of having a square like most sims do, have a rectangular solid around the ship in your 3d space.
This is easily generated and easily rendered.
Its advantage is that it is novel and easy.
Disdvantage of course is that it is non-standard.

I do think there is a gluUnproject func.


Not what you need.
"The gluUnProject function maps window coordinates to object coordinates."



[edited by - Vlion on March 19, 2002 3:15:12 PM]

Share this post

Link to post
Share on other sites
if you know the position of the 3d object and want to know where on the screen (2D image output) it´s drawn; use gluProject(...);

if you want the 3D position of a known 2D position, use gluUnproject(...);

I guess you wanted the first one? =)
I used this to center text around my spaceships.

//this uses gluProject(), 2d coordinates are saved into the winx,winy,winz variables...

double winx,winy,winz;

double modelviewmatrix [16];
double projectionmatrix [16];
int viewport[4];
glGetIntegerv (GL_VIEWPORT, viewport);

glGetDoublev (GL_MODELVIEW_MATRIX, modelviewmatrix);
glGetDoublev (GL_PROJECTION_MATRIX, projectionmatrix);
bool result = gluProject ( Ships[i].posX,Ships[i].posY,Ships[i].posZ,(const double *)modelviewmatrix,(const double *)projectionmatrix,viewport,&winx,&winy,&winz);

to prevent the text/target system from wanking about on the screen, set some limits for the variables;
this ensures that if the targeted ship is behind you, the text will be on the side of the screen, so you know that it is still targeted - but out of your view! :)

if (winx > 1024) winx = 1024;
if (winx < 0) winx = 0;
if (winy > 768) winy = 768;
if (winy < 0) winy = 0;


i.e glPrint(winx,winy,"this text follows the ship above");

Hope it helps!!

Cheers mate!

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!