PyOpenGL はじめました:gluLookAt
PyOpenGL はじめました《記事一覧》
gluLookAt
《著》小粒ちゃん《監修》小泉ひよ子とタマゴ倶楽部
第0版♪2006/09/21 ● 第1版♪2009/04/07
■ 概要
gluLookAt:図形を観察する位置を設定します。
■ 関連記事
GLU | redbook | Description |
---|---|---|
gluLookAt | Chapter 3 - OpenGL Programming Guide A Simple Example: Drawing a Cube |
define a viewing transformation 次の項目を設定します ・視点の位置(eyeX, eyeY, eyeZ) ・目標の位置(centerX, centerY, centerZ) ・法線ベクトル(upX, upY, upZ) |
概要:gluLookAt
$ cd ../redbook/Chapter3,Viewing/cube/
$ python2.5 -i cube.py -ss
['cube.py', '-ss']
>>> print gluLookAt.__doc__
gluLookAt(
GLdouble(eyeX), GLdouble(eyeY), GLdouble(eyeZ),
GLdouble(centerX), GLdouble(centerY), GLdouble(centerZ),
GLdouble(upX), GLdouble(upY), GLdouble(upZ)
) -> None
Example 3-1:Transformed Cube: cube.c
$ python2.5 cube.py
視点 (0,0,5) から目標 (0,0,0) を観察すると、ウィンドウの中心に立方体(原点)が位置します。Y 軸 (0,1,0) が上向きになります。 |
#! /usr/bin/python """ OpenGL Programming Guide Chapter 3 : Viewing A Simple Example: Drawing a Cube Example 3-1 : Transformed Cube: cube.c """ from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from sys import argv def init(): glClearColor(0.0, 0.0, 0.0, 0.0) glShadeModel(GL_FLAT) def display(): glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0, 1.0, 1.0) glLoadIdentity() # clear the matrix # viewing transformation gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) glScalef(1.0, 2.0, 1.0) # modeling transformation glutWireCube(1.0) glFlush() def reshape(w, h): glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0) glMatrixMode(GL_MODELVIEW) ## ---------------------------------------- def ex_(): glutInit(sys.argv) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(200, 100) glutInitWindowPosition(100, 100) glutCreateWindow(title()) # modify init() glutDisplayFunc(display) glutReshapeFunc(reshape) glutKeyboardFunc(keyboard) # append glutMainLoop()
misc
def title(): return argv[0][:-3] def keyboard(*args): print args key, x, y = args if key == '\x1b': # escape exit() def ex_s(): print argv EX = "" if __name__ == '__main__': for e in argv: if e.startswith("-s"): EX = e[2:] eval("ex_%s()"%EX)
事例:コマンドライン引数
gluLookAt の引数を、コマンドラインから指定します。
def ex_p(): glutInit(sys.argv) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(200, 200) glutInitWindowPosition(100, 100) glutCreateWindow(title()) init() glutDisplayFunc(display1) glutReshapeFunc(reshape) glutKeyboardFunc(keyboard) glutMainLoop() def display1(): glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0, 1.0, 1.0) glLoadIdentity() # clear the matrix # viewing transformation _gluLookAt() glScalef(1.0, 2.0, 1.0) # modeling transformation glutWireCube(1.0) glFlush() args = ([0]*9, argv[2:])[argv[1] == "-sp"] eyeX,eyeY,eyeZ, centerX,centerY,centerZ, upX,upY,upZ = args def _gluLookAt(): global eyeX,eyeY,eyeZ, centerX,centerY,centerZ, upX,upY,upZ print "eye(%s,%s,%s) center(%s,%s,%s) up(%s,%s,%s)"%( eyeX,eyeY,eyeZ, centerX,centerY,centerZ, upX,upY,upZ ) gluLookAt( float(eyeX), float(eyeY), float(eyeZ), float(centerX), float(centerY), float(centerZ), float(upX), float(upY), float(upZ), )
Tips
》作業中です《
Last updated♪09/04/21