model 0.05 2002/05/23
Loads a simple model format and draws it with opengl.
allows rotations and whatnot based on simple cursor input
Written by Michael Urman (mu on irc.openprojects.net)
Uses Modules
Numeric math pygame sys types OpenGL.GL
Classes
ModelNode OGLSprite Quaternion
class ModelNode
Node base class for modeling system
Methods
__init__(self, *children)
__repr__(self)
add(self, *children)
add(self, children) -> None

Add all children under the current Node
draw(self, *args, **kvargs)
class OGLSprite
Implement the ugly details of "blitting" to OpenGL
Methods
__init__(self, surf, rect=None, mipmap=None)
OGLSprite(self, surf, rect=None) -> OGLSprite

Create a drawable texture out of a given surface.
blit_at(self, *rects)
blit_at(self, *rects) -> self

Draw the texture at the supplied position(s). If a tuple and width and height are not specified, the original size is used (just like you'd expect). Returns self so ogs.enter().blit().exit() works
enter(self)
enter(self) -> self

Set up OpenGL for drawing textures; do this once per batch of textures. Returns self so ogs.enter().blit().exit() works
exit(self)
exit(self) -> None

Return OpenGL to previous settings; do this once per batch.
get_height(self)
get_height(self) -> int
get_width(self)
get_width(self) -> int
update(self, surf, rect=None)
update(self, surf, rect=None) -> None

class Quaternion
Methods
__abs__(q)
abs(Quaternion) -> float

Returns the magnitue of the Quaternion = sqrt(x*x+y*y+z*z+w*w)
__imul__(q, o)
Quaternion *= Quaternion -> None Quaternion *= float -> None

Multiplies a Quaternion in place by a constant or by another Quaternion. Remember to do (b * a) for a Quaternion representation of a rotation by a then by b. Not Commutative!
__init__(q, quat=None)
Quaternion(q, quat=None) -> Quaternion

Creates a new "pure" quaternion (of no rotation). If a quaternion is passed in, it is copied. If a tuple of the format (degrees, (x, y, z)) or (x, y, z, w) is passed in, it is turned into a quaternion.
__mul__(q, o)
Quaternion *= Quaternion -> Quaternion Quaternion *= float -> Quaternion

Multiplies a Quaternion by a constant or by another Quaternion. Remember to do (b * a) for a Quaternion representation of a rotation by a then by b. Not Commutative!
__repr__(q)
repr(Quaternion) -> string

Return a string of the format '<w [x y z]>' (direct Quaternion values)
__str__(q)
str(Quaternion) -> string

Return a string of the format '<angle (x y z)>' (angle in degrees and normalized axis of rotation)
angle(q)
angle(q) -> float

Return the angle of rotation (in degrees) represented by q
axis(q)
axis(q) -> [x,y,z]

Returns a (Numeric) array of the axis of rotation represented by q. Normalizes the vector to have magnitude of 1.0
normalize(q)
normalize(q) -> q

Normalizes the Quaternion such that the magnitued is 1.0
rotate(self, angle, axis)
rotate(self, angle, axis) -> self

Rotate Quaternion self by angle (degrees) around axis (x, y, z) and return self for each chaining
class SMF(ModelNode)
Handles loading and drawing of a simple model format
Methods
__init__(self, filename=None, calcnormals=None)
SMF([filename]) optionally loads model stored in passed filename
__repr__(self) from ModelNode
add(self, *children) from ModelNode
build_display_list(self)
Try to optimize the draw routine by using a display list
draw(self, *args, **kvargs)
Draw the model to the waiting screen
class Transform(ModelNode)
Transformation nodes for hierarchical models
Methods
__init__(self, translate=None, rotate=None, scale=None)
__repr__(self) from ModelNode
add(self, *children) from ModelNode
draw(self, *args, **kvargs)
draw(self, *args, **kvargs) -> None

Applies transformations and calls children's draw() routine
rotate(self, angle, axis)
rotate(self, angle, axis) -> None

Rotate model by angle around the axis (x,y,z)
scale(self, factor)
scale(self, factor) -> None

Scale model by factor (x,y,z)
translate(self, delta)
translate(self, delta) -> None

Translate model by delta (x,y,z)
Functions
_cross main
_cross(a, b)
main()
loads and runs the model display
Global Data
GLU = None