예제 #1
0
    def __init__(self, win, zoom=1.0, phi=0, theta=0, nv=0.2):
        self.win = win
        self.tbcam = TrackballCamera(20.0)
        self.offset_x = 0
        self.offset_y = 0
        self.offset_z = 0

        self.matrix = (c_double * 16)()
        self.pmatrix = (c_double * 16)()
        self.viewport = (c_int * 4)()
예제 #2
0
class Camera(object):

    def __init__(self, win, zoom=1.0, phi=0, theta=0, nv=0.2):
        self.win = win
        self.tbcam = TrackballCamera(20.0)
        self.offset_x = 0
        self.offset_y = 0
        self.offset_z = 0
        
        self.matrix = (c_double*16)()
        self.pmatrix = (c_double*16)()
        self.viewport = (c_int*4)()

    def __repr__(self):
        return "on"
        d = self.tbcam.__dict__.copy()
        return ", ".join('%s:%s' % (k,v) for k,v in d.items())

    def worldProjection(self):
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective( 
            40.0,                            # Field Of View
            float(self.win.width)/float(self.win.height),  # aspect ratio
            0.001,                             # z near
            100.0)                           # z far
        glTranslatef(self.offset_x, self.offset_y, self.offset_z)
        self.tbcam.update_modelview()
        glScalef(10.0, 10.0, 10.0)

        ## save for project/unproject
        glGetDoublev(GL_MODELVIEW_MATRIX, self.matrix)
        glGetDoublev(GL_PROJECTION_MATRIX, self.pmatrix)
        glGetIntegerv(GL_VIEWPORT, self.viewport)        

    def hudProjection(self):
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(0, self.win.width, 0, self.win.height)

    def project(self, c):
        x,y,z = c_double(),c_double(),c_double()
        gluProject(c[0], c[1], c[2],
                   self.matrix, self.pmatrix, self.viewport,
                   x, y, z)
        return (x.value, y.value)

    def get_zoom_factor(self):
        return self.tbcam.cam_eye[2]
예제 #3
0
class Camera(object):
    def __init__(self, win, zoom=1.0, phi=0, theta=0, nv=0.2):
        self.win = win
        self.tbcam = TrackballCamera(20.0)
        self.offset_x = 0
        self.offset_y = 0
        self.offset_z = 0

        self.matrix = (c_double * 16)()
        self.pmatrix = (c_double * 16)()
        self.viewport = (c_int * 4)()

    def __repr__(self):
        return "on"
        d = self.tbcam.__dict__.copy()
        return ", ".join('%s:%s' % (k, v) for k, v in d.items())

    def worldProjection(self):
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(
            40.0,  # Field Of View
            float(self.win.width) / float(self.win.height),  # aspect ratio
            0.001,  # z near
            100.0)  # z far
        glTranslatef(self.offset_x, self.offset_y, self.offset_z)
        self.tbcam.update_modelview()
        glScalef(10.0, 10.0, 10.0)

        ## save for project/unproject
        glGetDoublev(GL_MODELVIEW_MATRIX, self.matrix)
        glGetDoublev(GL_PROJECTION_MATRIX, self.pmatrix)
        glGetIntegerv(GL_VIEWPORT, self.viewport)

    def hudProjection(self):
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(0, self.win.width, 0, self.win.height)

    def project(self, c):
        x, y, z = c_double(), c_double(), c_double()
        gluProject(c[0], c[1], c[2], self.matrix, self.pmatrix, self.viewport,
                   x, y, z)
        return (x.value, y.value)

    def get_zoom_factor(self):
        return self.tbcam.cam_eye[2]
예제 #4
0
 def __init__(self, win, zoom=1.0, phi=0, theta=0, nv=0.2):
     self.win = win
     self.tbcam = TrackballCamera(20.0)
     self.offset_x = 0
     self.offset_y = 0
     self.offset_z = 0
     
     self.matrix = (c_double*16)()
     self.pmatrix = (c_double*16)()
     self.viewport = (c_int*4)()
예제 #5
0
    def __init__(self,width=defaults['width'],height=defaults['height']):
        self.width = width
        self.height = height
        self.config = Config(double_buffer=True, depth_size=24)
        self.win = window.Window(visible=True,resizable=True,
                                 config=self.config, caption='Sam')

        # set callbacks
        self.win.on_resize = self.on_resize
        self.win.on_draw = self.on_draw
        self.win.on_mouse_press = self.on_mouse_press
        self.win.on_mouse_drag = self.on_mouse_drag

        self.win.set_size(self.width,self.height)

        self.init_gl()
        
        self.tb = TrackballCamera(20.0)
        self.clnum = 1
        return
예제 #6
0
#!/usr/bin/env python
#
# a test of the trackball_camera class, showing basic usage in pyglet.
#
# by Roger Allen, July 2008
# [email protected]
#
from pyglet.gl import *
from pyglet import window
from trackball_camera import TrackballCamera

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
g_width = 800
g_height = 600
# >>>> INITIALIZE THE TRACKBALL CAMERA
g_tbcam = TrackballCamera(20.0)


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def to_glfloat_array(x):
    return (GLfloat * len(x))(*x)


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def init_gl():
    glEnable(GL_DEPTH_TEST)
    glDisable(GL_CULL_FACE)


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def on_resize(width, height):
예제 #7
0
class TBWindow:
    def __init__(self,width=defaults['width'],height=defaults['height']):
        self.width = width
        self.height = height
        self.config = Config(double_buffer=True, depth_size=24)
        self.win = window.Window(visible=True,resizable=True,
                                 config=self.config, caption='Sam')

        # set callbacks
        self.win.on_resize = self.on_resize
        self.win.on_draw = self.on_draw
        self.win.on_mouse_press = self.on_mouse_press
        self.win.on_mouse_drag = self.on_mouse_drag

        self.win.set_size(self.width,self.height)

        self.init_gl()
        
        self.tb = TrackballCamera(20.0)
        self.clnum = 1
        return

    def init_gl(self,**kwargs):
        swire_draw = kwargs.get('swire_draw',defaults['swire_draw'])
        mat_draw = kwargs.get('mat_draw',defaults['mat_draw'])
        glEnable(GL_DEPTH_TEST)
        glDisable(GL_CULL_FACE)
        if swire_draw:
            glEnable(GL_LINE_SMOOTH)
        elif mat_draw:
            glEnable(GL_LIGHTING)
            lightZeroPosition = glf([10.,4.,10.,1.])
            lightZeroColor = glf([0.8,1.0,0.8,1.0]) #green tinged
            glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
            glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
            glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1)
            glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05)
            glEnable(GL_LIGHT0)
        return

    def run(self): pyglet.app.run()

    def calllist(self, spheres=[], cyls=[], lines=[]):
        glNewList(self.clnum,GL_COMPILE)
        for sphere in spheres: draw_sphere(*sphere)
        for cyl in cyls: draw_cylinder(*cyl)
        for line in lines: draw_line(*line)
        glEndList()
        return

    def on_resize(self, width, height):
        self.width = width
        self.height = height
        glViewport(0,0,self.width,self.height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective( 
            40.0,                            # Field Of View
            float(self.width)/float(self.height),  # aspect ratio
            1.0,                             # z near
            100.0)                           # z far
        self.tb.update_modelview() # init modview matrix for trackball
        return

    def on_draw(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glCallList(self.clnum)
        return

    def on_mouse_press(self, x, y, button, modifiers):
        if button == window.mouse.LEFT:
            self.tb.mouse_roll(
                norm1(x, self.width),
                norm1(y,self.height),
                False)
        elif button == window.mouse.RIGHT:
            self.tb.mouse_zoom(
                norm1(x, self.width),
                norm1(y,self.height),
                False)
        return

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        if buttons & window.mouse.LEFT:
            self.tb.mouse_roll(
                norm1(x,self.width),
                norm1(y,self.height))
        elif buttons & window.mouse.RIGHT:
            self.tb.mouse_zoom(
                norm1(x,self.width),
                norm1(y,self.height))
        return