pyglut – python opengl utilities

platform:Linux, Windows
synopsis:pyopengl programming helper classes and functions set.

pyglut datatypes

Datatype Color

class pyglut.Color(ub_v=False, f_v=False)

Class for the color management:

The color can be encoded either as unsigned bytes or as floats.

To interact with pyopengl color functions.

Parameters:ub_v – (unsigned bytes vector) [0-255] rgb(a) color representing sequence.

Initialize the Color with an unsigned bytes rgb(a) sequence.

Parameters:f_v – (floats vector) [0.0-1.0] rgb(a) color representing sequence.

Initalize the Color with an floats rgb(a) sequence.

Note

The sequence must be in the order (Red, Green,Blue (,Alpha)).

Color.get_float_v()

Color values getting method.

If the color is encoded as unsigned bytes it will be automaticly convert in floats.

Returns:The color representation as an sequence of floats.
Color.get_ubyte_v()

Color values getting method.

If the color is encoded as floats it will be automaticly convert in unsigned bytes.

Returns:The color representation as an sequence of unsigned byte.
Color.set_in_float_values()

Convert the color unsigned bytes encoded color in floats values.

Color.set_in_float_values()

Convert float encoded color in unsigned byte values.

Color.r

Contains the red value.

Color.g

Contains the green value.

Color.b

Contains the blue value.

Color.a

Contains the alpha value.

Color.encoding

Contains the current color encoding.

Datatype Vertex

class pyglut.Vertex(x=False, y=False, z=False, vertexv=False)

Vertices management datatype class.

Holding the coordinate part x, y and z of an vertice.

Parameters:x,y,z – Coordinate of the position from the vertice.

The coordinate can be given as an sequence with the parameter:

Parameters:vertexv – an sequence from the (x, y, z) values.
Vertex.get_vertex()
Returns:The coordinate as an sequence (x, y, z).

Datatype Vector

class pyglut.Vector(x=0, y=0, z=0)

Vector management class implementing the <type ‘Vector’> datatype.

Vector.from_vertices(vertex1, vertex2)

Initialize an vector from 2 vertices for representing an direction from an vertice to another.

Parameters:
  • vertex1 – Vector begin.
  • vertex2 – Vector End.
Vector.get_magnitude()

Return the length of the vector object.

Returns:The vector length.
Vector.normalize()

Normalize the current vector object and return the resulting unit vector.

So as his length is equal to 1.0.

Returns:The unit vector, from length 1.0, from the vector object.
Vector.add_vector(vector)

Add The Vector object to the given vector.

Returns:The direction vector from the vector object.
Vector.sub_vector(vector)

Substract the given vector from the current Vector object.

Returns:The direction vector (opposite direction) from the vector object.
Vector.mult_vector(mult, vector=False)

Multiply the vector object or the given vector with the given mult argument what:

Increment the vector length and if mult is negativ flip the vector direction.

Returns:If the vector argument is given, multiply it per the argument mult.

If the vector argument is not given, multiply the current Vector object per the argument mult.

Vector.div_vector(div, vector=False)

Divide the vector object or the given vector by the given div argument what:

Decrement the vector length and if div is negativ flip the vector direction.

Returns:If the vector argument is given, divide it per the argument div.

If the vector argument is not given, divide the current Vector object per the argument div.

Vector.negation()

Negate the current Vector object.

Vector.add_vertex(vertex, vector=False)

Add the given vertex with, if given, the vector argument, else the current Vector object and return the result as an Vertex object.

Returns:If the vector argument is given, add it to the argument vertex and return the result as an Vertex object.

If the vector argument is not given, add the current Vector object to the argument vertex and return the result as an Vertex object.

Vector.cross(vector1, vector2)

Compute the cross product from 2 vectors and return the result as an Vector object.

Returns:The cross product from vector1 and vector2.

Note

Operations placeholders:

The class Vector implement 5 operations signs placeholder:

  • Vector + vector
  • Vector - vector
  • Vector * multiplier
  • Vector \ divisor
  • -Vector (negation)

Datatype Localview

class pyglut.Localview(x=0.0, y=0.0, z=0.0)

Create an localview object with:

  • an position represented by an Vertex.
  • 3 free axes initialise as the X, Y, Z axes.
argument x,y,z:Coordinate of the position of the Localview.

An localview is an object representing either an

  • Camera view.
  • Local axes (X, Y, Z) of an 3D object.

An locaview is made from:

  • An localview position vertex, object from type Vertex.

    which is the position from:

    • The camera.
    • The center from the 3D object.

    referenced as an attribute named: Localview.pos

  • 3 axes, objects from type Vector Representing either:

    • The camera orientation.
    • The own axes from the 3D object.
Localview.mult_matrix(matrix)

Multiply the localview with an matrix, given as argument,

which settings change the localview.

Parameters:matrix – An object from type Matrix to change the position and | or the axes orientation of the Localview.
Localview.display(factor)

Display the axes in their current orientation

from the center to the greater values from the axes.

At the current Localview position.

Note:For debugging purpose.
Localview.pos

Object from type Vertex representing the current position from the localview.

Localview.right

Object from type Vector representing the X axe from the localview.

Localview.up

Object from type Vector representing the Y axe from the localview.

Localview.sight

Object from type Vector representing the Z axe from the localview.