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
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))
Beispiel #4
0
    def rotationIPV(_, view):
        ''' Inverse Projection Matrix
        in usage for a skybox cam
        since glFrustum isn't called here,
        compute PV from an other given mat,
        discard translation and inverse
        '''

        PV = _m.mul(_m.transpose(_.projmat), view)

        # PV[0][3]=PV[1][3]=PV[2][3]=0
        #PV[3] = [0,0,0,1]
        _.matrix = _m.inverse(PV)
Beispiel #5
0
 def compute(_):
     ''' OPTIMIZATION: factorize directly all computations in here'''
     #_.camera = _m.mul(_.camera, _m.translate(dx/100,dy/100,0))
     _.matrix = _m.mul(_m.translate(*_.position), _q.matrix(_.rotation))