简体   繁体   中英

How do I resize,scale or magnify the distances between points plotted in OpenGl

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. 在此处输入图片说明

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()

您应该将gluOrtho2D更改为gluOrtho2D(minX,maxX,minY,maxY) ,这样可以更好地定位相机-根据图像,我尝试将700替换为300

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM