Perspective¶
-
class
glumpy.transforms.
PVMProjection
(*args, **kwargs)¶ Bases:
glumpy.transforms.transform.Transform
Perspective projection is an approximate representation, on a flat surface of an image as it is seen by the eye. The two most characteristic features of perspective are that objects are smaller as their distance from the observer increases; and that they are subject to foreshortening, meaning that an object’s dimensions along the line of sight are shorter than its dimensions across the line of sight.
Parameters: - distance (float) – Distance of the camera to the origin. Default is 5.
- fovy (bool) – Field of view along y axis. Default is 40.
- znear (int) – Z near clipping place. Default is 2.
- zfar (int) – Z far clipping place. Default is 100.
The transform is connected to the following events:
on_attach
: Transform initializationon_resize
: Recompute projection matrix
Usage example
vertex = ''' attribute vec3 position; attribute vec4 color; void main() { v_color = color; gl_Position = <transform>; } ''' fragment = ''' varying vec4 v_color; void main() { gl_FragColor = v_color; } ''' window = app.Window() @window.event def on_draw(dt): global phi, theta window.clear() cube.draw(gl.GL_TRIANGLES, I) theta += 0.5 # degrees phi += 0.5 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['transform']['model'] = model V, I, O = colorcube() cube = gloo.Program(vertex, fragment) cube.bind(V) cube['transform'] = PVMProjection(Position("position")) window.attach(cube['transform']) phi, theta = 0, 0 app.run()
-
distance
¶ Distance of the camera to the origin
-
fovy
¶ Field of view along y axis
-
model
¶ Model matrix
-
projection
¶ Projection matrix
-
view
¶ View matrix
-
zfar
¶ Z far clipping place
-
znear
¶ Z near clipping place