Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5973481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:48:22+00:00 2026-05-22T20:48:22+00:00

I have this code that doing this, but it don’t work at all! GLdouble

  • 0

I have this code that doing this, but it don’t work at all!

GLdouble *posv = Utils::worldToScreen(px, py, pz);
GLdouble x = posv[0];
GLdouble y = posv[1];
GLdouble z = posv[2];
GLdouble *sizev = Utils::worldToScreen(1.0f, 1.0f, 1.0f);
GLdouble sizex = sizev[0];
GLdouble sizey = sizev[1];
GLdouble sizez = sizev[2];

glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 0.0);
// FRONT
glVertex3f(x-sizex, y-sizey, z+sizez);
glVertex3f(x+sizex, y-sizey, z+sizez);
glVertex3f(x+sizex, y+sizey, z+sizez);
glVertex3f(x-sizex, y+sizey, z+sizez);
// BACK
glVertex3f(x-sizex, y-sizey, z-sizez);
glVertex3f(x-sizex, y+sizey, z-sizez);
glVertex3f(x+sizex, y+sizey, z-sizez);
glVertex3f(x+sizex, y-sizey, z-sizez);

glColor3f(0.0, 1.0, 0.0);
// LEFT
glVertex3f(x-sizex, y-sizey, z+sizez);
glVertex3f(x-sizex, y+sizey, z+sizez);
glVertex3f(x-sizex, y+sizey, z-sizez);
glVertex3f(x-sizex, y-sizey, z-sizez);
// RIGHT
glVertex3f(x+sizex, y-sizey, z-sizez);
glVertex3f(x+sizex, y+sizey, z-sizez);
glVertex3f(x+sizex, y+sizey, z+sizez);
glVertex3f(x+sizex, y-sizey, z+sizez);

glColor3f(0.0, 0.0, 1.0);
// TOP
glVertex3f(x-sizex, y+sizey, z+sizez);
glVertex3f(x+sizex, y+sizey, z+sizez);
glVertex3f(x+sizex, y+sizey, z-sizez);
glVertex3f(x-sizex, y+sizey, z-sizez);
// BOTTOM
glVertex3f(x-sizex, y-sizey, z+sizez);
glVertex3f(x-sizex, y-sizey, z-sizez);
glVertex3f(x+sizex, y-sizey, z-sizez);
glVertex3f(x+sizex, y-sizey, z+sizez);


GLdouble* Utils::worldToScreen(float objX, float objY, float objZ)  {

GLint realy;
GLdouble win_x, win_y, win_z;
int viewport[4];
double mvmatrix[16], projmatrix[16];

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


gluProject(static_cast<GLdouble>(objX), static_cast<GLdouble>(objY), static_cast<GLdouble>(objZ), mvmatrix, projmatrix, viewport, &win_x, &win_y, &win_z);

realy = viewport[3]-(GLint)win_y -1;

GLdouble *temp = new GLdouble[3];
temp[0] = win_x;
temp[1] = realy;
temp[2] = win_z;

cout << "objX:" << objX << endl;
cout << "objY:" << objY << endl;
cout << "objZ:" << objZ << endl;
cout << "temp[0]:" << temp[0] << endl;
cout << "temp[1]:" << temp[1] << endl;
cout << "temp[2]:" << temp[2] << endl;

return temp; }

Output is very strange!

objX:100
objY:100
objZ:0
temp[0]:6.95322e-310
temp[1]:-1
temp[2]:6.95322e-310

What’s wrong? Sorry for my stupidity!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:48:23+00:00Added an answer on May 22, 2026 at 8:48 pm

    Rather than drawing vertices at x+/-size, y+/-size, z+/-size, why don’t you just translate to x, y, z with glTranslatef() and then do your drawing?

    Try this as your draw function:

    void drawCube(float x, float y, float z)
    {
        const float sizex = 0.5f;
        const float sizey = 0.5f;
        const float sizez = 0.5f
    
        glTranslatef(-x, -y, -z);
    
        glBegin(GL_QUADS);
    
        glColor3f(1.0, 1.0, 0.0);
    
        // FRONT
        glVertex3f(-sizex, -sizey, sizez);
        glVertex3f(sizex, -sizey, sizez);
        glVertex3f(sizex, sizey, sizez);
        glVertex3f(-sizex, sizey, sizez);
    
        // BACK
        glVertex3f(-sizex, -sizey, -sizez);
        glVertex3f(-sizex, sizey, -sizez);
        glVertex3f(sizex, sizey, -sizez);
        glVertex3f(sizex, -sizey, -sizez);
    
        glColor3f(0.0, 1.0, 0.0);
    
        // LEFT
        glVertex3f(-sizex, -sizey, sizez);
        glVertex3f(-sizex, sizey, sizez);
        glVertex3f(-sizex, sizey, -sizez);
        glVertex3f(-sizex, -sizey, -sizez);
    
        // RIGHT
        glVertex3f(sizex, -sizey, -sizez);
        glVertex3f(sizex, sizey, -sizez);
        glVertex3f(sizex, sizey, sizez);
        glVertex3f(sizex, -sizey, sizez);
    
        glColor3f(0.0, 0.0, 1.0);
    
        // TOP
        glVertex3f(-sizex, sizey, sizez);
        glVertex3f(sizex, sizey, sizez);
        glVertex3f(sizex, sizey, -sizez);
        glVertex3f(-sizex, sizey, -sizez);
    
        // BOTTOM
        glVertex3f(-sizex, -sizey, sizez);
        glVertex3f(-sizex, -sizey, -sizez);
        glVertex3f(sizex, -sizey, -sizez);
        glVertex3f(sizex, -sizey, sizez);
    
        glEnd();
    
        glTranslatef(x, y, z);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that works in a unit test but doesn't work when
So, i have this code that seems to be doing the mechanical work correctly,
I have code that does a web-service request. While doing this request I need
I have this code that performs an ajax call and loads the results into
I have this code that I want to make point-free; (\k t -> chr
I have this code that fetches some text from a page using BeautifulSoup soup=
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
I have this code that has one button that let's me choose an entry
I have this code that saves a pdf file. FileStream fs = new FileStream(SaveLocation,
So I have this code that takes care of command acknowledgment from remote computers,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.