예제 #1
0
def calculate_oblique_matrix(projection_mat: core.LMatrix4f,
                             clip_plane: core.Vec4):
    mat = core.LMatrix4f(projection_mat)
    mat_inv = core.LMatrix4f()
    mat_inv.invert_from(mat)
    #view_inv = core.LMatrix4f(view_mat)
    #view_inv.transpose_in_place()
    #clip_plane = view_inv.xform(clip_plane)

    #q = core.Vec4()
    #q.x = (sign(clip_plane.x) + mat[2][0]) / mat[0][0]
    #q.y = (sign(clip_plane.y) + mat[2][1]) / mat[1][1]
    #q.z = -1
    #q.w = (1 + mat[2][2]) / mat[3][2]

    q = mat.xform(core.Vec4(sign(clip_plane.x), sign(clip_plane.y), 1, 1))

    c = clip_plane * (2 / clip_plane.dot(q))

    mat[0][2] = c.x
    mat[1][2] = c.y
    mat[2][2] = c.z + 1
    mat[3][2] = c.w
    return mat