Bonjour à tous,

J'essaye de développer un simple viewer de heightmap en python à l'aide d'opengl.

En gros tout fonctionne (je crois ^^) mais j'ai un petit problème:

J'utilise une caméra de type treackball, et comme ma structure de points est plutôt lourde, lors des déplacements, je voudrais afficher un cube simple plutôt que mes points.

Le problème est que la fenêtre ne se rafraichis pas quand on bouge la caméra.

Quand on maintient le clic, on a bien un cube à la place des points, mais l'image ne se rafraichis que quand on lâche le clic, ce qui n'est frachement pas pratique pour visualiser correctement.

Je vous met le code du programme principal et de ma classe camera:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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()
Et la caméra:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
# -*- coding: iso8859-1 -*-
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
 
class camera:
	sensibilite_mouvement = 0.3
	sensibilite_scroll = 1.0
	hold = False
	dist = 60.0
	theta_y = 0.0
	theta_z = 0.0
 
	def mouse_motion(self, x, y):
		if self.hold:
			self.theta_z = x * self.sensibilite_mouvement
			self.theta_y = y * self.sensibilite_mouvement
		if self.theta_y>90.0:
			self.theta_y = 90.0
		else:
			if self.theta_y < -90.0:
				self.theta_y = -90.0
	def mouse_button(self, bouton, etat):
		if bouton ==  GLUT_LEFT_BUTTON:
			if self.hold and etat == GLUT_UP:
				self.hold = False
			else:
				if not self.hold and etat == GLUT_DOWN:
					self.hold = True
		else:
			if bouton == GLUT_WHEEL_UP and etat == GLUT_DOWN:
				self.dist -= self.sensibilite_scroll
				if self.dist<10.0:
					self.dist = 10.0
			else:
				if bouton == GLUT_WHEEL_DOWN and etat == GLUT_DOWN:
					self.dist += self.sensibilite_scroll
 
	def keyboard(self):
		self.theta_y = self.theta_z = 0.0
		glutSwapBuffers()
 
	def look(self):
		gluLookAt(self.dist, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0)
		glRotated(self.theta_y, 0, 1, 0)
		glRotated(self.theta_z, 0, 0, 1)

Merci d'avance
Seeme