interactionMatrix.py :  » Game-2D-3D » PyOpenGL » PyOpenGL-Demo-3.0.1b1 » PyOpenGL-Demo » proesch » interactionMatrix » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » PyOpenGL 
PyOpenGL » PyOpenGL Demo 3.0.1b1 » PyOpenGL Demo » proesch » interactionMatrix » interactionMatrix.py
# helper class for interactive object motion 
# 
# Copyright (C) 2007  "Peter Roesch" <Peter.Roesch@fh-augsburg.de>
#
# This code is licensed under the PyOpenGL License.
# Details are given in the file license.txt included in this distribution.

import sys

try:
  from OpenGL.GLUT import *
  from OpenGL.GL import *
  from OpenGL.GLU import *
except:
  print ''' Error: PyOpenGL not installed properly !!'''
  sys.exit(  )

class InteractionMatrix ( object ):
  """Class holding a matrix representing a rigid transformation.

  The current OpenGL is read into an internal variable and
  updated using rotations and translations given by
  user interaction."""

  def __init__( self ):
    self.__currentMatrix = None
    self.reset( )

  def reset( self ):
    """Initialise internal matrix with identity"""
    glPushMatrix( )
    glLoadIdentity( )
    self.__currentMatrix = glGetFloatv( GL_MODELVIEW_MATRIX )
    glPopMatrix( )

  def addTranslation( self, tx, ty, tz ):
    """Concatenate the internal matrix with a translation matrix"""
    glPushMatrix( )
    glLoadIdentity( )
    glTranslatef(tx, ty, tz)
    glMultMatrixf( self.__currentMatrix )
    self.__currentMatrix = glGetFloatv( GL_MODELVIEW_MATRIX )
    glPopMatrix( )

  def addRotation( self, ang, rx, ry, rz ):
    """Concatenate the internal matrix with a translation matrix"""
    glPushMatrix( )
    glLoadIdentity( )
    glRotatef(ang, rx, ry, rz)
    glMultMatrixf( self.__currentMatrix )
    self.__currentMatrix = glGetFloatv( GL_MODELVIEW_MATRIX )
    glPopMatrix( )

  def getCurrentMatrix( self ):
    return self.__currentMatrix
  
if __name__ == '__main__' :
  glutInit( sys.argv )
  glutCreateWindow( sys.argv[0] )
  m=InteractionMatrix()
  print m.getCurrentMatrix( )
  m.addTranslation(1,2,3)
  print m.getCurrentMatrix( )
  m.addRotation(30,0,0,1)
  print m.getCurrentMatrix( )
  m.addTranslation(1,2,3)
  print m.getCurrentMatrix( )
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.