Exemple #1
0
    def __init__(_, ratio=1, cameratype='FREE'):
        super(Camera, _).__init__()

        _.ratio = ratio  # window proportionnal aspect
        _.position = [0, 0, 0]
        # for target mode
        _.lookAt = [0, 0, -1]
        _.up = [0, 1, 0]
        # for ortho mode

        _.near_clip = 0.1
        _.far_clip = 2000
        _.fov = 45
        _.roll = 0
        _.matrix = _m.identity()
        _.rotation = _q.quaternion()
        _.speed = 0.5

        _.V = _m.identity()  # kept for PV inner computation
        ''' need a state switcher over dict
        CameraType = Enum('CameraType','FREE TARGET ORTHOGRAPHIC')
        cameraState = State(['camera_type'])
        cameraState.states('camera_type',CameraType)
        '''
        _.types = {
            'FREE': _.camera_free,
            'ORTHOGRAPHIC': _.camera_ortho,
            'TARGET': _.camera_target
        }

        _.setMode(cameratype)
def draw_object():
    glVertexAttribPointer(locations[b"vertex"], 3, GL_FLOAT, False, record_len,
                          vertex_offset)
    glVertexAttribPointer(locations[b"tex_coord"], 3, GL_FLOAT, False,
                          record_len, tex_coord_offset)
    glVertexAttribPointer(locations[b"normal"], 3, GL_FLOAT, False, record_len,
                          normal_offset)
    glVertexAttribPointer(locations[b"color"], 3, GL_FLOAT, False, record_len,
                          color_offset)

    modelview = m.identity()
    modelview = m.mul(modelview, m.scale(scale, scale, scale))
    modelview = m.mul(modelview, q.matrix(rotation))
    glUniformMatrix4fv(locations[b"modelview_matrix"], 1, GL_FALSE,
                       c_matrix(modelview))

    normal = m.transpose(m.inverse(m.top_left(modelview)))
    glUniformMatrix3fv(locations[b"normal_matrix"], 1, GL_FALSE,
                       c_matrix(normal))

    offset = 0
    for size in sizes:
        glDrawElements(GL_TRIANGLE_STRIP, size, GL_UNSIGNED_INT,
                       c_void_p(offset))
        offset += size * uint_size
Exemple #3
0
 def __init__(_, mesh, tex_coords, name=''):
     _.mesh = mesh
     _.tex_coords = tex_coords
     _.name = name
     # todo
     _.matrix = _m.identity()
     _.rotation = _q.quaternion()
     _.position = 0, 0, 0
     _.createBuffers()
def animate_texture(fps=25, period=10):
    f, _ = modf(time() / period)

    texture = m.identity()
    texture = m.mul(texture, m.translate(f, f, f))
    texture = m.mul(texture, m.rotate(f * 360, 1, 1, 1))
    f = abs(f * 2 - 1)
    texture = m.mul(texture, m.scale(1 + f, 1 + f, 1 + f))
    glUniformMatrix4fv(locations[b"texture_matrix"], 1, GL_FALSE,
                       c_matrix(texture))

    glutPostRedisplay()
    if texturing:
        glutTimerFunc(int(1000 / fps), animate_texture, fps)
def reshape(width, height):
    """window reshape callback."""
    glViewport(0, 0, width, height)

    projection = m.identity()
    radius = .5 * min(width, height)
    w, h = width / radius, height / radius
    if perspective:
        projection = m.mul(projection, m.frustum(-w, w, -h, h, 8, 16))
        projection = m.mul(projection, m.translate(tz=-12))
        projection = m.mul(projection, m.scale(1.5, 1.5, 1.5))
    else:
        projection = m.mul(projection, m.ortho(-w, w, -h, h, -2, 2))

    glUniformMatrix4fv(locations[b"projection_matrix"], 1, GL_FALSE,
                       c_matrix(projection))