本文整理汇总了Python中vispy.util.transforms.perspective函数的典型用法代码示例。如果您正苦于以下问题:Python perspective函数的具体用法?Python perspective怎么用?Python perspective使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了perspective函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:Eric89GXL,项目名称:vispy,代码行数:30,代码来源:display_lines.py
示例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))
开发者ID:almarklein,项目名称:vispy,代码行数:26,代码来源:test_transforms.py
示例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))
开发者ID:tacyd,项目名称:volspy,代码行数:7,代码来源:viewer.py
示例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
开发者ID:jpanikulam,项目名称:visar,代码行数:30,代码来源:make_distortion.py
示例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()
开发者ID:rossant,项目名称:vispy,代码行数:35,代码来源:galaxy.py
示例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))
开发者ID:Eric89GXL,项目名称:vispy,代码行数:28,代码来源:test_transforms.py
示例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()
开发者ID:Calvarez20,项目名称:vispy,代码行数:32,代码来源:rotate_cube.py
示例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 = []
开发者ID:DSsoto,项目名称:Sub8,代码行数:28,代码来源:world.py
示例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()
开发者ID:vispy,项目名称:vispy,代码行数:30,代码来源:skybox.py
示例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()
开发者ID:Hanbusy,项目名称:point-visualizer,代码行数:8,代码来源:point_visualizer.py
示例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
开发者ID:fherwig,项目名称:physmath248_pilot,代码行数:8,代码来源:galaxy.py
示例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
开发者ID:boscoh,项目名称:pyball,代码行数:8,代码来源:pyball.py
示例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
开发者ID:rossant,项目名称:vispy,代码行数:8,代码来源:galaxy.py
示例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
开发者ID:arrow-,项目名称:simQuad,代码行数:8,代码来源:visual.py
示例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
开发者ID:neuroradiology,项目名称:vispy,代码行数:8,代码来源:primitive_mesh_viewer_qt.py
示例16: on_resize
def on_resize(self, event):
"""
We create a callback function called when the window is being resized.
Updating the OpenGL viewport lets us ensure that
Vispy uses the entire canvas.
"""
gloo.set_viewport(0, 0, *event.physical_size)
ratio = event.physical_size[0] / float(event.physical_size[1])
self.program['u_projection'] = perspective(45.0, ratio, 2.0, 10.0)
开发者ID:cawasthi,项目名称:vispy-tutorial,代码行数:9,代码来源:02-plot3d.py
示例17: __init__
def __init__(self):
app.Canvas.__init__(self, keys='interactive', size=(800, 600))
dirname = path.join(path.abspath(path.curdir),'data')
positions, faces, normals, texcoords = \
read_mesh(load_data_file('cube.obj', directory=dirname))
self.filled_buf = gloo.IndexBuffer(faces)
if False:
self.program = gloo.Program(VERT_TEX_CODE, FRAG_TEX_CODE)
self.program['a_position'] = gloo.VertexBuffer(positions)
self.program['a_texcoord'] = gloo.VertexBuffer(texcoords)
self.program['u_texture'] = gloo.Texture2D(load_crate())
else:
self.program = gloo.Program(VERT_COLOR_CODE, FRAG_COLOR_CODE)
self.program['a_position'] = gloo.VertexBuffer(positions)
self.program['u_color'] = 1, 0, 0, 1
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('gray')
gloo.set_state('opaque')
gloo.set_polygon_offset(1, 1)
self._timer = app.Timer('auto', connect=self.on_timer, start=True)
self.show()
开发者ID:jay3sh,项目名称:vispy,代码行数:41,代码来源:objloader.py
示例18: __init__
def __init__(self):
# setup initial width, height
app.Canvas.__init__(self, keys='interactive', size=(800, 600))
# 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 = transforms.translate((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
w, h = self.size
self.projection = perspective(45.0, w / float(h), 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
gloo.set_state(clear_color=(0.0, 0.0, 0.03, 1.0),
depth_test=False, blend=True,
blend_func=('src_alpha', 'one'))
self._timer = app.Timer('auto', connect=self.update, start=True)
开发者ID:fherwig,项目名称:physmath248_pilot,代码行数:41,代码来源:galaxy.py
示例19: get_projection
def get_projection(self, viewbox):
w, h = viewbox.resolution
fov = self._fov
aspect = 1.0
fx = fy = 1.0 # todo: hard-coded
# Calculate distance to center in order to have correct FoV and fy.
if fov == 0:
M = transforms.ortho(-0.5*fx, 0.5*fx, -0.5*fy, 0.5*fy, -10000, 10000)
self._d = 0
else:
d = fy / (2 * math.tan(math.radians(fov)/2))
val = math.sqrt(10000) # math.sqrt(getDepthValue())
znear, zfar = d/val, d*val
M = transforms.perspective(fov, aspect, znear, zfar)
# Translation and rotation is done by our 'transformation' parameter
return M
开发者ID:gabr1e11,项目名称:GLSL-Examples,代码行数:21,代码来源:cameras.py
示例20: __init__
def __init__(self, mesh, vertexShader, fragShader):
app.Canvas.__init__(self, keys='interactive', size=(1600,900))
self.mesh = mesh
self.data = mesh.buildBuffer()
self.program = gloo.Program(vertexShader, fragShader)
self.model = np.eye(4, dtype=np.float32)
self.projection = perspective(45.0, self.size[0] /
float(self.size[1]), 1.0, 1000.0)
gloo.set_viewport(0, 0, self.size[0], self.size[1])
self.camera = camera.Camera(np.array([0,0,-5], dtype = np.float32), np.array([0,0,0], dtype = np.float32), 45.0, self.size)
self.view = self.camera.view
self.program.bind(gloo.VertexBuffer(mesh.buildBuffer()))
self.program['u_model'] = self.model
self.program['u_view'] = self.view
self.program['u_projection'] = self.projection
self.program['u_lightPos'] = np.array([20, 20, -20], dtype = np.float32);
self.program['u_lightColor'] = np.array([1, 1, 1], dtype = np.float32);
gloo.set_depth_mask(True)
gloo.set_blend_func('src_alpha', 'one_minus_src_alpha')
gloo.set_blend_equation('func_add')
gloo.set_cull_face('back')
gloo.set_front_face('cw')
gloo.set_state(blend=True, depth_test=True, polygon_offset_fill=True)
self.show()
self.theta = 0
self.phi = 0
开发者ID:fesoliveira014,项目名称:proceduralpaper,代码行数:37,代码来源:renderer.py
注:本文中的vispy.util.transforms.perspective函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论