PyOpenGL はじめました:glRotate

PyOpenGL はじめました記事一覧
glRotate

《著》小粒ちゃん《監修》小泉ひよ子とタマゴ倶楽部
第1版♪2006/09/21 ● 第2版♪2009/04/07

■ 概要

glRotate:変換行列に回転を施します。

  • glRotate, glRotated, glRotatef
■ 関連記事
GL redbook bluebook Description
glRotate Chapter 3 - OpenGL Programming Guide
・Figure 3-6 : Rotating an Object
Chapter 5. OpenGL Reference Pages
glRotate
multiply the current matrix by a rotation matrix
□□□□□□

概要:glRotate

$ cd ../colorCube/
$ python2.5 -i colorCube.py -ss
['colorCube.py', '-ss']
>>> print glRotate.__doc__
glRotated( GLdouble(angle), GLdouble(x), GLdouble(y), GLdouble(z) ) -> None
>>> ^D
$ ./colorCube.py 

事例

回転軸を中心に右回転させます。 回転軸を中心に左回転させます。。
□□□□□□□□□□□□□□□□□□□□□□□□ □□□□□□□□□□□□□□□□□□□□□□□□
from OpenGL.GL   import *
from OpenGL.GLU  import *
from OpenGL.GLUT import *
from sys import argv

## ----------------------------------------
vertices = [
    -1,-1, 1,  -1,1, 1,  1,1, 1,  1,-1, 1,
    -1,-1,-1,  -1,1,-1,  1,1,-1,  1,-1,-1,
    ]
colors = [
    0, 0, 0,  1, 0, 0,  1, 1, 0,  0, 1, 0, 
    0, 0, 1,  1, 0, 1,  1, 1, 1,  0, 1, 1,
    ]
indices = [
    0, 3, 2, 1,  2, 3, 7, 6,  0, 4, 7, 3,
    1, 2, 6, 5,  4, 5, 6, 7,  0, 1, 5, 4,
    ]
angle = 0.0

## ----------------------------------------
def init():
    glClearColor (0, 0, 0, 0)
    glEnable(GL_DEPTH_TEST)

def display():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(-2, 2, -2, 2, -2, 2) 
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    glRotatef(angle, 1, 1, 1)
    glEnableClientState(GL_COLOR_ARRAY)
    glEnableClientState(GL_VERTEX_ARRAY)
    glColorPointer(3, GL_FLOAT, 0, colors)
    glVertexPointer(3, GL_FLOAT, 0, vertices)
    glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, indices)
    glDisableClientState(GL_COLOR_ARRAY)
    glDisableClientState(GL_VERTEX_ARRAY)
    glutSwapBuffers()

## ----------------------------------------
def ex_():
    glutInit(argv)
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH)
    glutInitWindowSize(250, 250)
    glutInitWindowPosition(100, 100)
    glutCreateWindow(title())
    init()
    glutDisplayFunc(display)
    glutKeyboardFunc(keyboard)
    glutMainLoop()

misc

def title():
    return argv[0][:-3]

def keyboard(*args):
    global angle
    key, x, y = args
    if key == '\x1b':   # escape
        exit()
    if key == '<':
        angle -= 10         ; print "<<< ",angle
        glutPostRedisplay()        
    if key == '>':
        angle += 10         ; print "<<< ",angle
        glutPostRedisplay()        
    
def ex_s(): print argv

EX = ""
if __name__ == '__main__':
    for e in argv:
        if e.startswith("-s"): EX = e[2:]
    eval("ex_%s()"%EX)

事例:コマンドライン引数

glRotatef の引数を、コマンドラインから指定します。
》作業中です《

$ ./colorCube.py -sp 0 0 1

http://d.hatena.ne.jp/kotsubu-chan/20051017

Tips

Last updated♪09/04/28