예제 #1
0
        self.fovy = 30
        self.n = 1
        self.f = 10000

    def onResize(self, w=None, h=None):
        super(PerspectiveView, self).onResize(w, h)
        self.aspect = float(self.w) / float(self.h)

    def onMotion(self, x, y):
        self.head += (x - self.x)
        self.pitch += (y - self.y)
        self.x = x
        self.y = y
        return True

    def updateProjection(self):
        gluPerspective(self.fovy, self.aspect, self.n, self.f)

    def updateView(self):
        glTranslate(0, 0, -self.distance)
        glRotate(self.head, 0, 1, 0)
        glRotate(self.pitch, 1, 0, 0)


if __name__ == '__main__':
    import cube
    glut_ui.run(
        glbase.BaseController(
            PerspectiveView(80),
            cube.createCube(10)))
예제 #2
0
import triangle


class Translation(baseview.BaseView):
    def __init__(self):
        super(Translation, self).__init__()
        self.pos_x=0
        self.pos_y=0

    def onMotion(self, x, y):
        # マウスカーソルの座標を左右-1〜+1、上下-1〜+1の範囲に変換する
        self.pos_x=float(x)/self.w*2-1
        self.pos_y=-(float(y)/self.h*2-1)
        # 再描画したいのでTrueを返す
        return True

    def updateView(self):
        print("==> Identity")
        print(glGetFloatv(GL_MODELVIEW_MATRIX))

        glTranslate(self.pos_x, self.pos_y, 0)

        print("==> GL_MODELVIEW_MATRIX {0} {1}".format(self.pos_x, self.pos_y))
        print(glGetFloatv(GL_MODELVIEW_MATRIX))


if __name__=="__main__":
    glut_ui.run(glbase.BaseController(
        Translation(),
        triangle.Triangle()))
예제 #3
0
            3,  # triangle4の頂点index
            3,
            2,
            1,  # triangle5の頂点index
            0,
            4,
            7,  # triangle6の頂点index
            7,
            3,
            0,  # triangle7の頂点index
            3,
            7,
            6,  # triangle8の頂点index
            6,
            2,
            3,  # triangle9の頂点index
            0,
            1,
            5,  # triangle10の頂点index
            5,
            4,
            0,  # triangle11の頂点index
        ],
    )


if __name__ == "__main__":
    import rotation

    glut_ui.run(glbase.BaseController(rotation.Rotation(), createCube(0.4)))
예제 #4
0
        self.distance = distance

    def onMotion(self, x, y):
        self.head += (x - self.x)
        self.pitch += (y - self.y)
        self.x = x
        self.y = y
        # return True for redrawing
        return True

    def updateProjection(self):
        l = -self.w / 2
        r = -l
        b = -self.h / 2
        t = -b
        n = 0
        f = 1000
        glOrtho(l, r, b, t, n, f)

    def updateView(self):
        glTranslate(0, 0, -self.distance)
        glRotate(self.head, 0, 1, 0)
        glRotate(self.pitch, 1, 0, 0)


if __name__ == '__main__':
    import cube
    glut_ui.run(
        glbase.BaseController(
            OrthogonalView(200),
            cube.createCube(100)))
예제 #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# sample.py
# author: Kentaro Wada <*****@*****.**>

import glut_ui
import glbase
import baseview
import triangle

if __name__=="__main__":
    glut_ui.run(glbase.BaseController(
        baseview.BaseView(), 
        triangle.Triangle()))
예제 #6
0
import glbase
import baseview
import triangle


class Translation(baseview.BaseView):
    def __init__(self):
        super(Translation, self).__init__()
        self.pos_x = 0
        self.pos_y = 0

    def onMotion(self, x, y):
        # マウスカーソルの座標を左右-1〜+1、上下-1〜+1の範囲に変換する
        self.pos_x = float(x) / self.w * 2 - 1
        self.pos_y = -(float(y) / self.h * 2 - 1)
        # 再描画したいのでTrueを返す
        return True

    def updateView(self):
        print("==> Identity")
        print(glGetFloatv(GL_MODELVIEW_MATRIX))

        glTranslate(self.pos_x, self.pos_y, 0)

        print("==> GL_MODELVIEW_MATRIX {0} {1}".format(self.pos_x, self.pos_y))
        print(glGetFloatv(GL_MODELVIEW_MATRIX))


if __name__ == "__main__":
    glut_ui.run(glbase.BaseController(Translation(), triangle.Triangle()))
예제 #7
0
            1,
            0,
            3,  # triangle4の頂点index
            3,
            2,
            1,  # triangle5の頂点index
            0,
            4,
            7,  # triangle6の頂点index
            7,
            3,
            0,  # triangle7の頂点index
            3,
            7,
            6,  # triangle8の頂点index
            6,
            2,
            3,  # triangle9の頂点index
            0,
            1,
            5,  # triangle10の頂点index
            5,
            4,
            0,  # triangle11の頂点index
        ])


if __name__ == "__main__":
    import rotation
    glut_ui.run(glbase.BaseController(rotation.Rotation(), createCube(0.4)))
예제 #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# sample.py
# author: Kentaro Wada <*****@*****.**>

import glut_ui
import glbase
import baseview
import triangle

if __name__ == "__main__":
    glut_ui.run(glbase.BaseController(baseview.BaseView(),
                                      triangle.Triangle()))
예제 #9
0
        self.distance = distance
        self.aspect = 1
        self.fovy = 30
        self.n = 1
        self.f = 10000

    def onResize(self, w=None, h=None):
        super(PerspectiveView, self).onResize(w, h)
        self.aspect = float(self.w) / float(self.h)

    def onMotion(self, x, y):
        self.head += (x - self.x)
        self.pitch += (y - self.y)
        self.x = x
        self.y = y
        return True

    def updateProjection(self):
        gluPerspective(self.fovy, self.aspect, self.n, self.f)

    def updateView(self):
        glTranslate(0, 0, -self.distance)
        glRotate(self.head, 0, 1, 0)
        glRotate(self.pitch, 1, 0, 0)


if __name__ == '__main__':
    import cube
    glut_ui.run(glbase.BaseController(PerspectiveView(80),
                                      cube.createCube(10)))