Example #1
0
File: test.py Project: mcydy/python
# coding: utf-8
__author__ = 'ypw'

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

window = 0
sph = common.sphere(16,16,1)
camera = common.camera()
plane = common.plane(12,12,1.,1.)
def InitGL(width,height):
    glClearColor(0.1,0.1,0.5,0.1)
    glClearDepth(1.0)
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(45.0,float(width)/float(height),0.1,100.0)
    camera.move(0.0,3.0,-5)

def DrawGLScene():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glMatrixMode(GL_MODELVIEW)
    camera.setLookat()
    plane.draw()
    glTranslatef(-1.5,0.0,0.0)
    glBegin(GL_QUADS)
    glVertex3f(-1.0, 1.0, 0.0)
    glVertex3f(1.0, 1.0, 0.0)
Example #2
0
#print(user_path_list)
window = None

# 飞机数量
plane_num = 2
# 用户数量
people_num = 20
# 飞机高度
plane_height = 2.6
# 地图长宽
plane_size = 110

plane_list = []
people_list = []
for i in range(plane_num):
    plane_list.append(common.sphere(16, 16, 0.1, 0, 0))
for i in range(people_num):
    people_list.append(common.sphere(16, 16, 0.1, 0, 0))

camera = common.camera()
# 地形
plane = common.plane(plane_size, plane_size, 0.1, 0.1)
#the shaderall,colorMap,hightMap Should be placed after gl init,otherwise all 0
shaderall = None
tf = None
ps = None
colorMap = 0
hightMap = 0
x = 0
z = 0
Example #3
0
def main():
    global UAV_path_list
    planningUAV(user_path_list, UAV_path_list)
    #无人机初始位置
    for i in range(len(UAV_path_list)):
        plane_list.append(common.sphere(16, 16, 0.1, 0, 0))
    global window
    #glutInit(sys.argv)
    # 初始化
    glutInit([])
    # 设置图形显示模式
    # GLUT_RGBA建立RGBA模式的窗口
    # GLUT_DOUBLE使用双缓存,以避免把计算机作图的过程都表现出来,或者为了平滑地实现动画
    # GLUT_DEPTH使用深度缓存
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
    # 窗口大小设置
    glutInitWindowSize(1920, 1080)
    glutInitWindowPosition(0, 0)
    window = glutCreateWindow(b"opengl")

    # 为当前窗口设置显示回调函数
    glutDisplayFunc(DrawGLScene)
    # 设置空闲回调函数
    glutIdleFunc(DrawGLScene)
    # 指定当窗口的大小改变时调用的函数
    glutReshapeFunc(ReSizeGLScene)
    # 注册当前窗口的鼠标回调函数
    glutMouseFunc(mouseButton)
    # 设置移动回调函数
    glutMotionFunc(camera.mouse)
    # 定时器回调函数
    glutTimerFunc(1000, timerProc, 1)

    # gluLookAt(0, 15, 0, 0, 0, 0, 1.0, 0, 0.0)
    def keypress(key, x, y):
        if key == GLUT_KEY_UP:
            camera.move(0., 0., 1 * camera.offest)
        if key == GLUT_KEY_RIGHT:
            camera.move(-1 * camera.offest, 0., 0.)
        if key == GLUT_KEY_LEFT:
            camera.move(1 * camera.offest, 0., 0.)
        if key == GLUT_KEY_DOWN:
            camera.move(0., 0., -1 * camera.offest)
        if key == GLUT_KEY_F12:
            camera.change_overlook()

    # 注册当前窗口的键盘回调函数
    # glutKeyboardFunc(camera.keypress)
    # 设置当前窗口的特定键的回调函数
    # glutSpecialFunc(camera.keypress)

    # 注册当前窗口的键盘回调函数
    # glutKeyboardFunc(keypress2)
    # 设置当前窗口的特定键的回调函数
    glutSpecialFunc(keypress)
    # 背景颜色
    glClearColor(0.1, 0.1, 1, 0.1)
    # 设置深度缓存的清除值
    glClearDepth(1.0)
    # 开启GL_DEPTH_TEST,进行深度比较并更新深度缓冲区
    glEnable(GL_DEPTH_TEST)
    # GL_SMOOTH采用光滑着色,独立的处理图元中各个顶点的颜色
    glShadeModel(GL_SMOOTH)
    # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    camera.move(0.0, 1.3, 0)
    camera.setthree(True)
    camera.length = 5
    global shaderall
    shaderall = shaderProg.allshader()
    #global tf
    #tf = common.transformFeedback(shaderall.tfProgram)
    #global ps
    #ps = particle.particleSystem(1)
    global colorMap
    global hightMap
    colorMap = loadtexture.Texture.loadmap("ground2.bmp")
    # hight map for cpu to gpu
    hightMap = loadtexture.Texture.loadmap("hight.gif")
    # create terrain use cpu
    hightimage = loadtexture.Texture.loadterrain("hight.gif")
    # image = open("ground2.bmp").convert("RGBA")
    plane.setHeight(hightimage)

    glutMainLoop()
Example #4
0

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

import common
import sys

window = 0
sph = common.sphere(16,16,1)
camera = common.camera()
plane = common.plane(12,12,1.,1.)
def InitGL(width,height):
    glClearColor(0.1,0.1,0.5,0.1)
    glClearDepth(1.0)
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(45.0,float(width)/float(height),0.1,100.0)    
    camera.move(0.0,3.0,-5)    
    
def DrawGLScene():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glMatrixMode(GL_MODELVIEW)     
    camera.setLookat()
    plane.draw() 
    glTranslatef(-1.5,0.0,0.0)
    glBegin(GL_QUADS)                  
    glVertex3f(-1.0, 1.0, 0.0)          
    glVertex3f(1.0, 1.0, 0.0)           
    glVertex3f(1.0, -1.0, 0.0)          
Example #5
0
window = None

#UAV覆盖半径
UAVradius = 30
# 飞机高度
plane_height = 2.6
# 地图长宽
plane_size = 110

plane_list = []
people_list = []

#用户初始位置,从user_path_list中读取
for index, i in enumerate(user_path_list):
    people_list.append(
        common.sphere(16, 16, 0.1, i[0] / 120 - 5, i[1] / 120 - 5))

# 用户数量
people_num = len(user_path_list)

camera = common.camera()
# 地形
plane = common.plane(plane_size, plane_size, 0.1, 0.1)
#the shaderall,colorMap,hightMap Should be placed after gl init,otherwise all 0
shaderall = None
tf = None
ps = None
colorMap = 0
hightMap = 0
x = 0
z = 0