Statistics
| Revision:

root / PyOpenGL-Demo / proesch / interactionMatrix / interactionPot.py @ 1

History | View | Annotate | Download (2.2 kB)

1
#!/usr/bin/python2.4
2
# demo for interactive object motion
3
# 
4
# Copyright (C) 2007  "Peter Roesch" <Peter.Roesch@fh-augsburg.de>
5
#
6
# This code is licensed under the PyOpenGL License.
7
# Details are given in the file license.txt included in this distribution.
8

    
9
import sys
10
from mouseInteractor import MouseInteractor
11

    
12
try:
13
  from OpenGL.GLUT import *
14
  from OpenGL.GL import *
15
  from OpenGL.GLU import *
16
except:
17
  print ''' Fehler: PyOpenGL nicht intalliert !!'''
18
  sys.exit(  )
19

    
20

    
21
def display(  ):
22
        """Glut display function."""
23
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
24
        glMatrixMode( GL_PROJECTION )
25
        glLoadIdentity( )
26
        xSize, ySize = glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT )
27
        gluPerspective(60, float(xSize) / float(ySize), 0.1, 50)
28
        glMatrixMode( GL_MODELVIEW )
29
        glLoadIdentity( )
30
        glTranslatef( 0, 0, -4 )
31
        global mouseInteractor
32
        mouseInteractor.applyTransformation( )
33
        glCallList( tkList )
34
        glDisable( GL_LIGHTING )
35
        glColor3f( 1, 1, 0.3 )
36
        glRasterPos3f( 1.8, .5, 0 )
37
        for c in "tip":
38
                glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24, ord(c) )
39
        glEnable( GL_LIGHTING )
40
        glutSwapBuffers( )
41

    
42
def init(  ):
43
        """Glut init function."""
44
        glClearColor ( 0, 0, 0, 0 )
45
        glEnable( GL_DEPTH_TEST )
46
        glShadeModel( GL_SMOOTH )
47
        glEnable( GL_LIGHTING )
48
        glEnable( GL_LIGHT0 )
49
        glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, 0 )
50
        glLightfv( GL_LIGHT0, GL_POSITION, [4, 4, 4, 1] )
51
        lA = 0.8
52
        glLightfv( GL_LIGHT0, GL_AMBIENT, [lA, lA, lA, 1] )
53
        lD = 1
54
        glLightfv( GL_LIGHT0, GL_DIFFUSE, [lD, lD, lD, 1] )
55
        lS = 1
56
        glLightfv( GL_LIGHT0, GL_SPECULAR, [lS, lS, lS, 1] )
57
        glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, [0.0, 0.0, 0.2, 1] )
58
        glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, [0.0, 0.0, 0.7, 1] )
59
        glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, [0.5, 0.5, 0.5, 1] )
60
        glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 50 )
61
        global mouseInteractor
62
        mouseInteractor = MouseInteractor( .01, 1 )
63
        global tkList
64
        tkList = glGenLists( 1 )
65
        glNewList( tkList, GL_COMPILE )
66
        glutSolidTeapot( 1.0 )
67
        glEndList( )
68

    
69
glutInit( sys.argv )
70
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH )
71
glutInitWindowSize( 250, 250 )
72
glutInitWindowPosition( 100, 100 )
73
glutCreateWindow( sys.argv[0] )
74
init(  )
75
mouseInteractor.registerCallbacks( )
76
glutDisplayFunc( display )
77
glutMainLoop(  )