Results 1 to 5 of 5

Thread: radar-like application

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Italy, Milan
    Posts
    8

    radar-like application

    Hi,
    I am trying to create a kind of "radar" application (black screen, red static points and text, and a green rotating line, with its fixed point in the center of the screen).
    The problem is that points are not static. They rotate, together with the line.
    This is the code I am using:
    Code :
    GLvoid Render(System::Void) {
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
       glPointSize(5.0f);
       glBegin(GL_POINTS);
       glColor3f(1.0f, 0.0f, 0.0f);
       glVertex2f(-350.0f, 0.0f);
       glEnd();
     
       glMatrixMode(GL_PROJECTION);
       glPushMatrix();
       glLoadIdentity();
       gluOrtho2D(0, wid, 0, hei);
       glScalef(1, -1, 1);
       glTranslatef(0, -hei, 0);
       glMatrixMode(GL_MODELVIEW);
       glPushMatrix();
       glLoadIdentity();
       glColor3f(1.0f, 0.0f, 0.0f);
       char* c = "point";
       glRasterPos2f(15.0f, 235.0f);
       for (; *c != '\0'; c++)
          glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *c);
       glPopMatrix();
       glMatrixMode(GL_PROJECTION);
       glPopMatrix();
       glMatrixMode(GL_MODELVIEW);
     
       //glPushMatrix();
       glRotatef(-1.0f, 0.0f, 0.0f, 1.0f);
       glLineWidth(3.0f);
       glBegin(GL_LINES);
       glColor3f(0.0f, 0.5f, 0.0f);
       glVertex2f(0.0f, 0.0f);
       glVertex2f(500.0f, 0.0f);
       glEnd();
       //glPopMatrix();
     
       SwapBuffers(m_hDC);
    }

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: radar-like application

    remove the pushmatrix/popmatrix. Totally useless, and making some of your code unused.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Italy, Milan
    Posts
    8

    Re: radar-like application

    Last push/pop are into a comment; if I remove also the previous push/pop, I do not see anything

    ps: I paste also my initgl function.. can be useful..
    Code :
    GLvoid InitGL(GLvoid) {
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
       glViewport(0, 0, this->wid, this->hei);
       gluOrtho2D(-(this->wid / 2), this->wid / 2, -(this->hei / 2), this->hei / 2);
       glShadeModel(GL_SMOOTH);
       glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
       glClearDepth(1.0f);
       glEnable(GL_DEPTH_TEST);
       glDepthFunc(GL_LEQUAL);
       glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    }

    Is also the initGL wrong?
    Thanks

  4. #4
    Senior Member Regular Contributor
    Join Date
    Aug 2007
    Location
    Adelaide, South Australia
    Posts
    208

    Re: radar-like application

    Just before you draw the line you do a glRotatef to rotate the modelview matrix, then when Render is called again you draw the points with this same matrix so they are rotated as well.

    To draw fixed points just move the point-drawing code after the
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    At this point you have pushed the rotated matrix onto the stack and loaded the Identity matrix (which is stationary) so when you draw the text it is stationary.

    The push/pop that you have commented out didn't work because its the wrong way around, you need to push the matrix used to draw the line to save its position while you draw the fixed objects.
    Currently the code i mentioned above does this.
    (It needs to be here rather than at end of function because otherwise the first pass would pop when it hadn't pushed anything yet)

    The rotation matrix is restored just before you rotate it in the following lines of code:
    glPopMatrix(); //This restores the rotation matrix
    glMatrixMode(GL_PROJECTION);
    glPopMatrix(); //This restores projection matrix defined in Init
    glMatrixMode(GL_MODELVIEW);

    I'm not sure why you are changing both the projection matrix and the modelview matrix.
    If you need to display the points with the same projection matrix as the rotating line then you need to rearrange the code to something like:
    // Save rotation matrix and set a fixed modelview
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    // Draw points
    glPointSize(5.0f);
    glBegin(GL_POINTS);
    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex2f(-350.0f, 0.0f);
    glEnd();
    // Change projection matrix to draw text
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0, wid, 0, hei);
    glScalef(1, -1, 1);
    glTranslatef(0, -hei, 0);


  5. #5
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Italy, Milan
    Posts
    8

    Re: radar-like application


    I was not able to find the right code disposition... I am sorry!!!
    The code I rearranged does not work. Can you paste the right render/init functions?
    Thanks for the patience

Similar Threads

  1. radar chart
    By elsanna in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-17-2014, 05:01 PM
  2. Radar Display
    By Krishna Murthy in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-09-2013, 11:03 PM
  3. Radar Display
    By Hiten in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-21-2009, 05:04 AM
  4. INTERFACING RADAR
    By Tom Clark in forum OpenGL: User Software
    Replies: 1
    Last Post: 03-04-2007, 02:06 PM
  5. 2d Radar bitmap
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-07-2005, 04:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean