本文整理汇总了Python中vispy.util.transforms.perspective函数的典型用法代码示例。如果您正苦于以下问题:Python perspective函数的具体用法?Python perspective怎么用?Python perspective使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了perspective函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
app.Canvas.__init__(self, keys='interactive', size=(W, H))
self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
# Set uniform and attribute
self.program['a_id'] = gloo.VertexBuffer(a_id)
self.program['a_position'] = gloo.VertexBuffer(a_position)
self.translate = 5
self.view = translate((0, 0, -self.translate), dtype=np.float32)
self.model = np.eye(4, dtype=np.float32)
gloo.set_viewport(0, 0, self.physical_size[0], self.physical_size[1])
self.projection = perspective(45.0, self.size[0] /
float(self.size[1]), 1.0, 1000.0)
self.program['u_projection'] = self.projection
self.program['u_model'] = self.model
self.program['u_view'] = self.view
self.theta = 0
self.phi = 0
self.context.set_clear_color('white')
self.context.set_state('translucent')
self.timer = app.Timer('auto', connect=self.on_timer)
self.show()
示例2: test_transforms
def test_transforms():
"""Test basic transforms"""
xfm = np.random.randn(4, 4).astype(np.float32)
for rot in [xrotate, yrotate, zrotate]:
new_xfm = rot(rot(xfm, 90), -90)
assert_allclose(xfm, new_xfm)
new_xfm = rotate(rotate(xfm, 90, 1, 0, 0), 90, -1, 0, 0)
assert_allclose(xfm, new_xfm)
new_xfm = translate(translate(xfm, 1, -1), 1, -1, 1)
assert_allclose(xfm, new_xfm)
new_xfm = scale(scale(xfm, 1, 2, 3), 1, 1. / 2., 1. / 3.)
assert_allclose(xfm, new_xfm)
# These could be more complex...
xfm = ortho(-1, 1, -1, 1, -1, 1)
assert_equal(xfm.shape, (4, 4))
xfm = frustum(-1, 1, -1, 1, -1, 1)
assert_equal(xfm.shape, (4, 4))
xfm = perspective(1, 1, -1, 1)
assert_equal(xfm.shape, (4, 4))
示例3: toggle_projection
def toggle_projection(self, event=None):
"""Toggle between perspective and orthonormal projection modes."""
self.perspective = not self.perspective
if self.perspective:
self.volume_renderer.set_vol_projection(perspective(60, 1., 100, 0))
else:
self.volume_renderer.set_vol_projection(ortho(-1, 1, -1, 1, -1000, 1000))
示例4: __init__
def __init__(self, size=(1600, 900), no_distort=False):
'''Distorter object: Applies distortion to Contexts and drawables
- size (X, Y): Size of monitor
- distortion (Bool): Apply distortion or not?
'''
self.size = size
self.left_eye_tex = gloo.Texture2D(shape=(4096, 4096) + (3,))
self.right_eye_tex = gloo.Texture2D(shape=(4096, 4096) + (3,))
self.left_eye = gloo.FrameBuffer(self.left_eye_tex, gloo.RenderBuffer(self.size))
self.right_eye = gloo.FrameBuffer(self.right_eye_tex, gloo.RenderBuffer(self.size))
self.left_eye_program, self.left_eye_indices = Mesh.make_eye(self.left_eye_tex, 'left')
self.right_eye_program, self.right_eye_indices = Mesh.make_eye(self.right_eye_tex, 'right')
self.IPD = 0.0647 # Interpupilary distance in m
# Male: 64.7 mm
# Female: 62.3 mm
self.L_projection = parameters.projection_left.T
self.R_projection = parameters.projection_right.T
self.no_distort = no_distort
if self.no_distort:
self.projection = perspective(30.0, 1920 / float(1080), 2.0, 10.0)
self.draw = self.draw_no_distortion
else:
self.draw = self.draw_distortion
示例5: on_initialize
def on_initialize(self, event):
# create a new shader program
self.program = gloo.Program(VERT_SHADER, FRAG_SHADER,
count=len(galaxy))
# load the star texture
self.texture = gloo.Texture2D(load_galaxy_star_image(),
interpolation='linear')
self.program['u_texture'] = self.texture
# construct the model, view and projection matrices
self.view = np.eye(4, dtype=np.float32)
transforms.translate(self.view, 0, 0, -5)
self.program['u_view'] = self.view
self.model = np.eye(4, dtype=np.float32)
self.program['u_model'] = self.model
self.program['u_colormap'] = colors
self.projection = perspective(45.0, self.width / float(self.height),
1.0, 1000.0)
self.program['u_projection'] = self.projection
# start the galaxy to some decent point in the future
galaxy.update(100000)
data = self.__create_galaxy_vertex_data()
# setup the VBO once the galaxy vertex data has been setup
# bind the VBO for the first time
self.data_vbo = gloo.VertexBuffer(data)
self.program.bind(self.data_vbo)
# setup blending
self.__setup_blending_mode()
示例6: test_transforms
def test_transforms():
"""Test basic transforms"""
xfm = np.random.randn(4, 4).astype(np.float32)
# Do a series of rotations that should end up into the same orientation
# again, to ensure the order of computation is all correct
# i.e. if rotated would return the transposed matrix this would not work
# out (the translation part would be incorrect)
new_xfm = xfm.dot(rotate(180, (1, 0, 0)).dot(rotate(-90, (0, 1, 0))))
new_xfm = new_xfm.dot(rotate(90, (0, 0, 1)).dot(rotate(90, (0, 1, 0))))
new_xfm = new_xfm.dot(rotate(90, (1, 0, 0)))
assert_allclose(xfm, new_xfm)
new_xfm = translate((1, -1, 1)).dot(translate((-1, 1, -1))).dot(xfm)
assert_allclose(xfm, new_xfm)
new_xfm = scale((1, 2, 3)).dot(scale((1, 1. / 2., 1. / 3.))).dot(xfm)
assert_allclose(xfm, new_xfm)
# These could be more complex...
xfm = ortho(-1, 1, -1, 1, -1, 1)
assert_equal(xfm.shape, (4, 4))
xfm = frustum(-1, 1, -1, 1, -1, 1)
assert_equal(xfm.shape, (4, 4))
xfm = perspective(1, 1, -1, 1)
assert_equal(xfm.shape, (4, 4))
示例7: __init__
def __init__(self):
app.Canvas.__init__(self, keys='interactive', size=(800, 600))
self.vertices, self.filled, self.outline = cube()
self.filled_buf = gloo.IndexBuffer(self.filled)
self.outline_buf = gloo.IndexBuffer(self.outline)
self.program = gloo.Program(vert, frag)
self.program.bind(gloo.VertexBuffer(self.vertices))
self.view = translate((0, 0, -5))
self.model = np.eye(4, dtype=np.float32)
gloo.set_viewport(0, 0, self.physical_size[0], self.physical_size[1])
self.projection = perspective(45.0, self.size[0] /
float(self.size[1]), 2.0, 10.0)
self.program['u_projection'] = self.projection
self.program['u_model'] = self.model
self.program['u_view'] = self.view
self.theta = 0
self.phi = 0
gloo.set_clear_color('white')
gloo.set_state('opaque')
gloo.set_polygon_offset(1, 1)
self._timer = app.Timer('auto', connect=self.on_timer, start=True)
self.show()
示例8: __init__
def __init__(self, mesh, position=(0.0, 0.0, 0.0), orientation=None, color=(255., 0., 0., 255.0), faces=None,
shader_manager=None):
'''Orientation must be a 4x4 rotation matrix'''
self.position = np.array(position, dtype=np.float32)
if orientation is None:
self.orientation = np.eye(4)
else:
assert orientation.shape == (4, 4), "Orientation must be a 4x4 numpy array"
self.orientation = orientation
if len(color) == 3:
color = color + (255,)
self.color = np.array(color, dtype=np.float32) / 255. # Normalize to [0, 1]
self.program = gloo.Program(self._vertex_shader, self._fragment_shader)
self.program.bind(mesh)
self.faces = gloo.IndexBuffer(faces)
self.model = np.eye(4, dtype=np.float32)
self.model = self.model.dot(translate(self.position))
self.view = np.eye(4, dtype=np.float32)
self.projection = perspective(30.0, 800 / float(800), 2.0, 500.0)
self.program['u_model'] = self.model
self.program['u_view'] = self.view
self.program['u_projection'] = self.projection
self.program['u_color'] = self.color
self.children = []
示例9: __init__
def __init__(self):
app.Canvas.__init__(self, size=(1024, 1024), title='Skybox example',
keys='interactive')
self.cubeSize = 10
self.pressed = False
self.azimuth = pi / 2.0
self.elevation = pi / 2.0
self.distanceMin = 1
self.distanceMax = 50
self.distance = 30
self.sensitivity = 5.0
self.view = getView(self.azimuth, self.elevation, self.distance)
self.model = np.eye(4, dtype=np.float32)
self.projection = np.eye(4, dtype=np.float32)
self.program = gloo.Program(vertex_shader, fragment_shader, count=24)
self.program['a_position'] = faces*self.cubeSize
self.program['a_texcoord'] = faces
self.program['a_texture'] = gloo.TextureCube(texture, interpolation='linear')
self.program['u_model'] = self.model
self.program['u_view'] = self.view
gloo.set_viewport(0, 0, *self.physical_size)
self.projection = perspective(60.0, self.size[0] /
float(self.size[1]), 1.0, 100.0)
self.program['u_projection'] = self.projection
gl.glEnable(gl.GL_DEPTH_TEST)
gloo.set_clear_color('black')
self.show()
示例10: on_resize
def on_resize(self, event):
width, height = event.size
gloo.set_viewport(0, 0, width, height)
self.projection = perspective(45.0, width / float(height), 1.0, 1000.0)
self.program_data['u_projection'] = self.projection
self.program_axis['u_projection'] = self.projection
self.program_plane['u_projection'] = self.projection
self.update()
示例11: on_resize
def on_resize(self, event):
# setup the new viewport
gloo.set_viewport(0, 0, *event.physical_size)
# recompute the projection matrix
w, h = event.size
self.projection = perspective(45.0, w / float(h),
1.0, 1000.0)
self.program['u_projection'] = self.projection
示例12: recalc_projection
def recalc_projection(self):
self.projection = perspective(
25.0,
self.width / float(self.height),
1.0,
50.0+self.zoom)
self.fog_near = self.zoom
self.fog_far = 20.0 + self.zoom
示例13: on_resize
def on_resize(self, event):
self.width, self.height = event.size
# setup the new viewport
gloo.set_viewport(0, 0, self.width, self.height)
# recompute the projection matrix
self.projection = perspective(45.0, self.width / float(self.height),
1.0, 1000.0)
self.program['u_projection'] = self.projection
示例14: on_resize
def on_resize(self, event):
width, height = event.size
self.size = event.size
gloo.set_viewport(0, 0, width, height)
self.aspect = width / float(height)
self.projection = perspective(45.0, width / float(height), 2,
10.0)
self.program_quad['u_projection'] = self.projection
示例15: on_resize
def on_resize(self, event):
width, height = event.size
self.size = event.size
gloo.set_viewport(0, 0, width, height)
self.aspect = width / float(height)
self.projection = perspective(self.fovy, width / float(height), 1.0,
self.zfar)
self.program['u_projection'] = self.projection