pyglet_helper.util package¶
Submodules¶
pyglet_helper.util.color module¶
pyglet_helper.util.display_list module¶
-
class
pyglet_helper.util.display_list.
DisplayList
(built=False)¶ Bases:
object
A class for storing the OpenGl commands for rendering an object.
Parameters: built (bool) – If True, the commands have been executed -
compiled
¶ Returns whether the current list has beein completed.
-
gl_compile_begin
()¶ Generates the beginning of the list.
-
gl_compile_end
()¶ Generates the end of the list.
-
gl_render
()¶ Call all of the commands in the current list.
-
pyglet_helper.util.linear module¶
-
class
pyglet_helper.util.linear.
Tmatrix
(t=None, a=None, b=None)¶ Bases:
object
A 3D affine transformation matrix.
Parameters: - t (pyglet_helper.util.Tmatrix) – A tmatrix to copy to the current matrix
- a (array_like) – A matrix factor of the current matrix
- b (array_like) – A matrix factor of the current matrix
-
gl_color_get
()¶ Initialize the matrix with the contents of the OpenGL color matrix
Returns: the current matrix Return type: matrix
-
gl_load
()¶ Overwrites the currently active matrix in OpenGL with this one.
-
gl_modelview_get
()¶ Initialize the matrix with the contents of the OpenGL modelview
Returns: the current matrix Return type: matrix
-
gl_mult
()¶ Multiplies the active OpenGL by this one.
-
gl_projection_get
()¶ Initialize the matrix with the contents of the OpenGL projection matrix
Returns: the current matrix Return type: matrix
-
gl_texture_get
()¶ Initialize the matrix with the contents of the OpenGL texture matrix
Returns: the current matrix Return type: matrix
-
inverse
()¶
-
origin
()¶ Get the matrix’s origin as a vector
Returns: the origin Return type: pyglet_helper.util.Vector
-
project
(v)¶ Multply a vector or vertex by the current matrix to produce a new vertex
Parameters: v (Vertex or Vector) – the vertex or vector to be transformed Returns: The transformed vertex Return type: pyglet_helper.util.Vertex
-
scale
(v, w=None)¶ Scale the transformation matrix by a vector or vertex
Parameters: - v (Vertex or Vector) – The vector or vertex describing the scaling
- w (float) – The scaling factor for the normalization column. If undefined, the value will be taken from the vextex, or set to 1.0
-
times_inv
(v, w=None)¶ Multiply a vector or vertex v by the inverted transformation matrix
Parameters: - v (Vector or Vertex) – the vector to be transformed
- w – The vector’s normalization factor. If None, it will be taken from v or set to 1.0
:type w; float :rtype: Vector or Vertex :return: The transformed Vector or Vertex
-
times_v
(v)¶ Multiply a vector or vertex by the transformation matrix
Parameters: v (Vector or Vertex) – the vector or vertex to be transformed Returns: the transformed vector or vertex Return type: Vector or Vertex
-
translate
(v)¶ Translate the transformation by a 3D value described in v
Parameters: v (Vertex or Vector) – The vertex or vector describing the transformation
-
w_column
(v=None, x=None, y=None, z=None)¶ Sets the fourth column of the matrix
Parameters: - v (Vector or Vertex) – The vector to set the fourth column to
- x (float) – The value of the first row (if v is set, it will be ignored)
- y (float) – The value of the second row (if v is set, it will be ignored)
- z (float) – The value of the third row (if v is set, it will be ignored)
-
w_row
(x=0, y=0, z=0, w=1)¶ Set the bottom row of the matrix
Parameters: - x (float) – the value to set the first column to
- y (float) – the value to set the second column to
- z (float) – the value to set the third column to
- w (float) – the value to set the fourth column to
-
x_column
(v=None, x=None, y=None, z=None)¶ Sets the first column of the matrix
Parameters: - v (Vector or Vertex) – The vector to set the first column to
- x (float) – The value of the first row (if v is set, it will be ignored)
- y (float) – The value of the second row (if v is set, it will be ignored)
- z (float) – The value of the third row (if v is set, it will be ignored)
-
y_column
(v=None, x=None, y=None, z=None)¶ Sets the second column of the matrix
Parameters: - v (Vector or Vertex) – The vector to set the second column to
- x (float) – The value of the first row (if v is set, it will be ignored)
- y (float) – The value of the second row (if v is set, it will be ignored)
- z (float) – The value of the third row (if v is set, it will be ignored)
-
z_column
(v=None, x=None, y=None, z=None)¶ Sets the third column of the matrix
Parameters: - v (Vector or Vertex) – The vector to set the third column to
- x (float) – The value of the first row (if v is set, it will be ignored)
- y (float) – The value of the second row (if v is set, it will be ignored)
- z (float) – The value of the third row (if v is set, it will be ignored)
-
class
pyglet_helper.util.linear.
Vector
(a=0.0, b=0.0, c=0.0, v=None)¶ Bases:
object
A vector object used for math operations, and for storing 3D points
Parameters: - a (float, Vector, Vertex, or array_like) – Either the x component of the vector, a Vector, a Vertex, or an array_like
- b (float) – if a was a float, b is the y component of the vector
- c (float) – if a was a float, c is the z component of the vector
- v (array_like) – an array_like of length 3 defining the components of the vector (optional)
-
clear
()¶ Zero the state of the vector. :return:
-
comp
(v)¶ Scalar projection of this to v
Parameters: v (Vector or Vertex) – the vector or vertex the current vector will be compared to Return type: float Returns: the scaling factor between v and the current vector
-
cross
(v)¶ Return the cross product of this vector and another.
Parameters: v (Vertex or Vector) – The other vector to be crossed with the current vector Returns: The cross product of self and v Return type: pyglet_helper.util.Vector
-
diff_angle
(v)¶ Calculates the angular difference between two vectors, in radians, between 0 and pi.
Parameters: v (Vector) – The vector to be calculated against Returns: The angular difference between the current vector and v, in radians Return type: float
-
dot
(v)¶ Calculates the dot product of this vector and another.
Parameters: v (Vertex or Vector) – The other vector to be multiplied with the current vector Returns: The dot product Return type: float
-
fabs
()¶ Project the current vector into the positive quadrant :return: The vector in the positive quadrant :rtype: Vector
-
gl_normal
()¶ Add the current vector as an OpenGL Normal :return:
-
gl_render
()¶ Add the current vector as an OpenGL Vertex :return:
-
mag
()¶ Calculate the vector’s magnitude
Returns: the magnitude Return type: float
-
nonzero
()¶ Check to see if any component of the vector is non-zero
Return type: bool Returns: True if any component of the vector is nonzero, False otherwise
-
norm
()¶ Generate a vector of unit length from this vector
Return type: pyglet_helper.util.Vector Returns: unit vector
-
proj
(v)¶ Vector projection of this to v
Parameters: v (Vector) – the vector to project the current vector onto Returns: the projected vector Return type: Vector
-
rotate
(angle, axis=None)¶ Rotates the vector.
Parameters: - angle (float) – The angle to rotate by
- axis (Vector) – The axis to rotate around (optional, if not set, the axis will be the +z axis
Returns: rotated vector
Return type: pyglet_helper.util.Vector
-
scale
(v)¶ Scale this vector to another, by elementwise multiplication
Parameters: v (Vector or Vertex) – the Vector to scale by Returns: the scaled vector Return type: pyglet_helper.util.Vector
-
scale_inv
(v)¶ Scale this vector to another, by elementwise division
Parameters: v (Vector or Vertex) – the vector to scale by Returns: the scaled vector Return type: pyglet_helper.util.Vector
-
set_mag
(m)¶
-
sum
()¶ Sum the components of the vector :return:
-
x
¶
-
y
¶
-
z
¶
-
class
pyglet_helper.util.linear.
Vertex
(x=0, y=0, z=0, w=0, v=None)¶ Bases:
object
A homogeneous Vertex
Parameters: - x (float) – The x coordinate of the vertex
- y (float) – The y coordinate of the vertex
- z (float) – The z coordinate of the vertex
- w (float) – The normalization factor of the x,y, and z components
- v (list) – A list of values to copy into the vertex
-
gl_render
()¶ Send the vertex to OpenGl
-
project
()¶ Project the vector according to its normalization factor
Returns: A copy of the current vector scaled to w. Return type: pyglet_helper.util.Vector
-
w
¶
-
x
¶
-
y
¶
-
z
¶
-
pyglet_helper.util.linear.
rotation
(angle, axis, origin=None)¶ Returns a rotation matrix to perform rotations about an axis passing through the origin through an angle in the direction specified by the Right Hand Rule.
Parameters: - angle (float) – the angle of the rotation about the axis
- axis (Vector or Vertex) – the axis of rotation
- origin (Vector or Vertex) – the location of the rotation axis
Returns: the new transformation matrix
Return type: pyglet_helper.util.Tmatrix
pyglet_helper.util.quadric module¶
-
class
pyglet_helper.util.quadric.
DrawingStyle
(*keys, **kwargs)¶ Bases:
enum.Enum
An enumeration of the possible quadric drawing styles.
Create an enumeration instance.
-
FILL
= 3¶
-
LINE
= 2¶
-
POINT
= 1¶
-
SILHOUETTE
= 4¶
-
-
class
pyglet_helper.util.quadric.
NormalStyle
(*keys, **kwargs)¶ Bases:
enum.Enum
An enumeration of the possible options when generating a quadric’s normals.
Create an enumeration instance.
-
FLAT
= 2¶
-
NONE
= 1¶
-
SMOOTH
= 3¶
-
-
class
pyglet_helper.util.quadric.
Orientation
(*keys, **kwargs)¶ Bases:
enum.Enum
An enumeration of the possible winding styles when rendering a quadric.
Create an enumeration instance.
-
INSIDE
= 2¶
-
OUTSIDE
= 1¶
-
-
class
pyglet_helper.util.quadric.
Quadric
¶ Bases:
object
Generates a Quadric. Used for cylinders, spheres, and disks.
-
drawing_style
¶
-
normal_style
¶
-
orientation
¶
-
render_cylinder
(base_radius, height, slices, stacks, top_radius=None)¶ Generate the polygons for a cylinder
Parameters: - base_radius (float) – The radius of the bottom of the cylinder.
- height (float) – The cylinder’s height
- slices (int) – The number of longitudinal lines
- stacks (int) – The number of latitudinal lines
- top_radius (float) – The radius of the top of the cylinder. If undefined, the top radius will be the same as the base radius
-
render_disk
(radius, slices, rings, rotation)¶ Generate the polygons for a disk
Parameters: - radius (float) – The disk’s radius
- slices (float) – The number of longitudinal lines
- rings (int) – The number of concentric rings in the disk, for rendering
- rotation (float) – The rotation of the disk along the z-axis
-
render_sphere
(radius, slices, stacks)¶ Render a sphere.
Parameters: - radius (float) – The radius of the sphere
- slices (int) – The number of longitudinal lines
- stacks (int) – The number of latitudinal lines
-
pyglet_helper.util.rgba module¶
-
class
pyglet_helper.util.rgba.
Rgb
(red=1.0, green=1.0, blue=1.0, c=None)¶ Define an RGB color to be used by OpenGl
Parameters: - red (float) – The red value of the color, value between 0 and 1
- green (float) – The green value of the color, value between 0 and 1
- blue (float) – The blue value of the color, value between 0 and 1
- c (list) – A list of values to copy into a new color
-
desaturate
()¶ Convert the color to HSV space, reduce the saturation by a factor of 0.5, then convert back to RGB space
Return type: pyglet_helper.util.Rgb() Returns: the desaturated color.
-
gl_set
(opacity=1.0)¶ Set the current material to this color
Parameters: opacity (float) – the opacity value of the color
-
grayscale
()¶ Convert the color to grayscale
Returns: the color, projected onto grayscale. Return type: pyglet_helper.util.Rgb()
-
rgb
¶
-
class
pyglet_helper.util.rgba.
Rgba
(red=1.0, green=1.0, blue=1.0, opacity=1.0, c=None)¶ Bases:
object
Defines a color to be used by OpenGl, including RGB and opacity.
Parameters: - red (float) – The red value of the color, value between 0 and 1
- green (float) – The green value of the color, value between 0 and 1
- blue (float) – The blue value of the color, value between 0 and 1
- opacity (float) – The opacity value of the color, value between 0 and 1
- c (list) – A list of values to copy into a new color
-
desaturate
()¶ Return a desaturated version of the color
Return type: pyglet_helper.util.Rgba Returns: the desaturized color.
-
gl_set
()¶ Set this color to the current material in OpenGL.
-
grayscale
()¶ Return a version of the color projected onto a grayscale space
Returns: the color, projected onto grayscale. Return type: pyglet_helper.util.Rgba()
pyglet_helper.util.shader_program module¶
-
class
pyglet_helper.util.shader_program.
ShaderProgram
(source=None)¶ Bases:
object
-
compile
(v, shader_type)¶
-
get_section
(name)¶ - Extract section beginning with
- [name]
- and ending with
- [
- e.g. [vertex] void main() {} [fragment] void main() {}
-
gl_free
(program)¶
-
realize
(v)¶
-
source
¶
-
uniform_location
¶
-
uniform_matrix
(v, loc, _in)¶
-
pyglet_helper.util.texture module¶
-
class
pyglet_helper.util.texture.
Texture
(damaged=False, handle=0, have_opacity=False)¶ Bases:
object
A class to assist in managing OpenGL texture resources.
-
damage
()¶
-
gl_activate
(v)¶ - Make this texture active. This function constitutes use under the
- “initialize on first use” rule, and will incur a one-time speed and continuous graphics memory penalty. Precondition: an OpenGL context must be active.
-
gl_free
(_handle)¶ - Returns e.g. GL_TEXTURE_2D - the thing to be enabled to make this texture
- work with the fixed function pipeline.
-
have_opacity
¶
-