Draw gluDisks according to longitude and latitude

In OpenGL/C++ I have a map setting created where someone walks up on a path in this map. All works well but I’m trying to add a feature where little gluDisks are created at every position the person has been on the map (breadcrumbs). This part is a little challenging. I first took the screen position coordinate position of the person on this map and it did exactly as I wanted. The disks were being drawn at the correct positions on the map where the person has been but the problem is screen position coordinates are not reliable since I can zoom in or out of this map and the disks will be drawn at the wrong place. Therefore, I must resort to a coordinates system that uses longitude and latitude of the person’s position. I’ve managed to get these coordinates perfectly however when I try to apply them like I did for the screen positioning, I don’t get the right outcome. Any ideas why?

Here is the section where I used the screen position as coordinates. Like I said this worked fine.

      for(unsigned i = 0; i < screenPositionVector.size(); i++)
      {
           glLoadIdentity(); // Load a clean identity matrix.
           glTranslatef(screenPositionVector.at(i).x, screenPositionVector.at(i).y, 0);
           gluDisk(quad, 4, 8, 32, 1);
      }

Now when I try to use my lat/lon coordinates, the disk is always being drawn at the top left corner of the map (0,0) position the entire time.

   for(unsigned i = 0; i < latLonVector.size(); i++)
   {
         glLoadIdentity(); // Load a clean identity matrix.
         glTranslatef(latLonVector.at(i).lon, latLonVector.at(i).lat, 0);
         gluDisk(quad, 4, 8, 32, 1);
   }

The way I retrieve the latitude and longitude positions work 100% so there is no concerns there.

I really don’t know why the disks are drawn properly when using screen coordinates rather than lat/lon.

If there is any other details that I need to add, let me know.

Without any visual input, it’s a little hard to imagine your problem. In general, zooming in or out should not have any effect on the distance between the drawn objects, at least not if you treat them the same way. Maybe there’s something missing in the way you draw the disks, compared to how you draw the terrain?

Second question, is all this in 3D, or just some kind of 2D minimap? If its the former, your code above lacks the transformation. The -2.04 is far out of the drawing area, maybe that’s the cause?

I would advise you to switch to modern openGL, where you can take control of your transformations yourself (I could help you to get started with that, if you want). Partly because I’m not so certain with the old glTranslatef and glRotatef code where you can easily lose track of the matrices because of one push or pop at the wrong place. Mainly because shaders give you much more power over what you want to create and the way how you create it, and there are much fewer possibilities to get lost in the transformations (at least this was the case for me).

With one post, you can’t link images, but I think you can post them with [*img][/img] (without the *).

Thanks for the quick reply.

Yeah I completely understand how it may be hard to fully understand the program with just the information I provided above. The way the latLonVector and screenPositionVector store coordinates are not treated the same way by design. The way I was taking the screen positioning wasn’t the best way to get the person’s position.

“Maybe there’s something missing in the way you draw the disks, compared to how you draw the terrain?” I was thinking this wouldn’t be a problem since I loaded the identity matrix with glLoadIdentity(). The terrain should not be interfering with the disks from my knowledge but I am pretty new to OpengGL so I maybe missing something.

All this is a 2D map. No 3D objects are being drawn. What exactly do you mean “your code above lacks the transformation”? I’m guessing there is more I need to do than just glTranselatef?

I have also tested this scenario under Lon: 0.795716 and Lat: 0.504402. These coordinates are where the person starts and it updates as he walks. Rather than the disks being place around his location, they’re at the top left of the map (at the origin I am assuming). The person is no where near the origin on the map and I never had this problem with screen position coordinates. I thought that it may by due to when I load the identity matrix and that is why it is at the origin however I place the glTranslatef right after so in theory I shouldn’t have a problem however that is not the case.

Will switching to the modern OpenGL interfere any progress I’ve made so far? I assume as a result I may need to start my program from scratch.

There’s no need to start from scratch, only some changes in the drawing process, i.e. the transformation logics can be self-coded and the transformations themselves will be placed in the shader. As a consequence, glLoadIdentity, glRotateF, glTranslateF and even glBegin will be obsolete, which results in much cleaner code (in my opinion).

The “your code above lacks the transformation” was in case you did transformations in 3D because between the identity and the drawing process, there has to be a transformation. In 2D, this transformation is unnecessary.

Back to your problem, why don’t the disks appear? In general, the origin is at the center of the screen, the bottom left is (-1, -1) and the top right is (1, 1), so you can guess where (0.79, 0.5) should appear. The top left makes absolutely no sense, and honestly I don’t know what could be the case here. Could you provide code that shows the difference between your “screen position coordinates” and the lat/lon-values, along with some sample values? That might help in the analysis.

Hmm… that’s odd because when I place glLoadIdentity() and than glTranslatef(0,0,0), it draws the circle on the top left of the map and than when I do glTranslatef(1,1,0) and glTranslatef(-1,-1,0) it draws the circle on the top left of the map again so you’re right this makes no sense. However I did notice one thing while trying to diagnose the problem.

When I place my code in this order, the disk gets drawn at the top left of the map:

for(unsigned i = 0; i < latLonVector.size(); i++)
{
glLoadIdentity(); // Load a clean identity matrix.
glTranslatef(latLonVector.at(i).lon, latLonVector.at(i).lat, 0);
gluDisk(quad, 4, 8, 32, 1);
}

however when I place the code in this order it draws the first disk correctly at the proper position where the person is on the screen however this is just the first circle and after the next circle gets drawn right back at the top left:

for(unsigned i = 0; i < latLonVector.size(); i++)
{
glTranslatef(latLonVector.at(i).lon, latLonVector.at(i).lat, 0);
gluDisk(quad, 4, 8, 32, 1);
glLoadIdentity(); // Load a clean identity matrix.
}

This looks like the Lat/Lon coordinates do indeed work properly since the first disk was drawn at the correct position but it messes up after the glLoadIdentity() function is called. another thing I’ve noticed is rather than redrawing the disks for the previous positions of where the person was (breadcrumbs) it continues to draw the person’s current position plus the position at the top left rather than the current position and its previous positions of where it has been as well.