Question

I am trying to generate a map which is given latitudes and longitudes as input.I am fairly new to OpenGL. I need to regenerate the map based on the points given, but to make it look decent it needs to be scaled proportionately to a size so that it can be viewed appropriately. The map looks very clustered. Any ideas on how to scale the map so that it may fit the window size. enter image description here

from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *

import math

def initFun():
    glClearColor(1.0,1.0,1.0,0.0)
    glColor3f(0.0,0.0, 0.0)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(0,700,0,700)

def displayFun():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(0.0,0.0,1.0)
    xpts=[]
    ypts=[]
    N=len(newlist)
    for i in range(0,N):
        xpts.append(float(newlist[i][4]))
        ypts.append(float(newlist[i][5]))

    glBegin(GL_POINTS)
    for j in range(0,N):        
        glVertex2f(xpts[j],ypts[j])

    glEnd()
    glFlush()

if __name__ == '__main__':
    glutInit()
    glutInitWindowSize(700,700)
    glutCreateWindow("My Display")
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
    glutDisplayFunc(displayFun)
    initFun()
    glutMainLoop()
Was it helpful?

Solution 2

I figured out it was some simple maths to do. Using a scaling matrix [4,0,0,0,4,0,0,0,1]*[x,y,1]. So after multiplying we get[4x,4y,1]. So if we multiply all points the image is scaled.Learnt this in school. Also the map was inverted. So my program finally looks like this

from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *

import math

def initFun():
    glClearColor(1.0,1.0,1.0,0.0)
    glColor3f(0.0,0.0, 0.0)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(0,700,0,700)

def displayFun():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(0.0,0.0,1.0)
    xpts=[]
    ypts=[]
    N=len(newlist)
    for i in range(0,N):
        xpts.append(700+100-float(newlist[i][4])*20)
        ypts.append(700+1300-float(newlist[i][5])*20)

    glBegin(GL_POINTS)
    for j in range(0,N):        
        glVertex2f(xpts[j],ypts[j])

    glEnd()
    glFlush()

if __name__ == '__main__':
    glutInit()
    glutInitWindowSize(700,700)
    glutCreateWindow("My Display")
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
    glutDisplayFunc(displayFun)
    initFun()
    glutMainLoop()

OTHER TIPS

You should change gluOrtho2D to be gluOrtho2D(minX,maxX,minY,maxY) which will position the camera better - based on the image I would try replacing 700 with 300

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top