1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| # -*- coding: iso8859-1 -*-
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
import Image
from cam import *
c = camera()
def mousemotion(*args):
global c
c.mouse_motion(args[2], args[3])
c.mouse_button(args[0], args[1])
glutPostRedisplay()
def reshape(*args):
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60.0, float(args[0])/args[1], 1.0, 200.0)
def spec(*args):
if args[0] == GLUT_KEY_SPACE:
global c
c.keyboard()
glutPostRedisplay()
def display():
glClearColor(0, 0, 0, 0)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
# gluLookAt(200.0, 50.0, 50.0, 50.0, 50.0, 50.0, 0.0, 0.0, 1.0)
global c
c.look()
if c.hold:
# glMatrixMode(GL_MODELVIEW)
# glPushMatrix()
glTranslatef(50.0, 50.0, 50.0)
glutWireCube(100.0)
# glPopMatrix()
else:
glVertexPointer(3, GL_INT, 0, li)
glBegin(GL_POINTS)
for i in range(len(li)/3):
glArrayElement(i)
glEnd()
glutSwapBuffers()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowPosition(200, 200)
glutInitWindowSize(600, 600)
glutCreateWindow("plop")
glutDisplayFunc(display)
glutSpecialFunc(spec)
glutReshapeFunc(reshape)
glutMouseFunc(mousemotion)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60.0, float(600)/600, 1.0, 200.0)
glEnable(GL_DEPTH_TEST)
glEnableClientState(GL_VERTEX_ARRAY)
glutMainLoop()
im = Image.open("heightmapb.bmp")
im = im.transpose(Image.FLIP_LEFT_RIGHT)
im = im.transpose(Image.FLIP_TOP_BOTTOM)
res = im.getdata()
##Liste des index de l'image (greyscale)
li = []
##largeur de l'image (vu qu'on utilise un vecteur de pixel)
largeur_image = im.size[0]
longueur_image = im.size[1]
j = k = 0
for i in range(len(res)):
li.append(j)
li.append(k)
li.append(res[i][0]/4)
j+=1
if j == largeur_image:
j = 0
k+=1
res = []
im = 0
##Demarage de l'interface 3D (on a toutes nos données)
main() |