Thread: OpenGL GLuLookAt keep object on screen

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    2

    OpenGL GLuLookAt keep object on screen

    Greetings, I am using a function to render a health bar using quads. However I need to keep the quads on screen, right now it just floats in 3D space. Here is my current code:

    Code:
    void renderHealth(void)
    {
        glColor3f(1.0f, 0.0f, 0.0f);
        glBegin(GL_QUADS);
            glVertex3f(0.0f, 0.0f, 0.0);
            glVertex3f((float)getHealth() / 100, 0.0, 0.0);
            glVertex3f((float)getHealth() / 100, 0.3, 0.0);
            glVertex3f(0.0f, 0.3f, 0.0f);
        glEnd();
    }
    Right now I'm using the GluLookAt function but when I make any move the healthbar stays in place. Can someone make a suggestion on how to fix this?

    If you know of a good 2D graphics library that works with OpenGlut please let me know.
    Last edited by runedog48; 05-31-2013 at 06:43 AM. Reason: I'm a dumbass

  2. #2
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    GluLookAt surprisingly changes what you are looking at. It doesn't change where it is in space. i.e. it changes the DIRECTION you look in, not what is in that direction.

    If your view is already moving through space, then the health bar ALSO has to move in space.

    So all you need to do is draw the health bar JUST IN FRONT of wherever the position / view is currently focused. If you know how to draw any object in 3D space, you know how to do this. Just apply a transform to the points of the heatlhbar, to always put it into view.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    2
    Quote Originally Posted by ledow View Post
    GluLookAt surprisingly changes what you are looking at. It doesn't change where it is in space. i.e. it changes the DIRECTION you look in, not what is in that direction.

    If your view is already moving through space, then the health bar ALSO has to move in space.

    So all you need to do is draw the health bar JUST IN FRONT of wherever the position / view is currently focused. If you know how to draw any object in 3D space, you know how to do this. Just apply a transform to the points of the heatlhbar, to always put it into view.
    Thanks, any suggestions on the math? I'm unfortunately horrible at math.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 03-12-2011, 04:25 PM
  2. openGL: textures, gluLookAt, and undefined behavior
    By MK27 in forum Game Programming
    Replies: 7
    Last Post: 04-28-2009, 10:12 AM
  3. gluLookAt Problems.. (OpenGL)
    By JJFMJR in forum Game Programming
    Replies: 3
    Last Post: 07-09-2007, 07:53 AM
  4. trouble outputing string object to screen.
    By cmasri in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2007, 11:52 AM