optional layers? or you mean something else?
"""
new_rdpyg/build/lib/urdpyg/milk_skeleton.py 0000644 0001751 0001751 00000055705 10075765524 021402 0 ustar rene rene 0000000 0000000 """
Copyright (C) 2002 by Rene Dudfield.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
import string, sys, os
import time
import UserDict
import Numeric
N = Numeric
from urdpyg.converters import ms3d_ascii_importer
import bisect
"""
Data flow:
--------------
milkshape converter -> MilkshapeModelLoader
In the MilkshapeModelLoader it converts the data into its internal representation.
"""
class MilkshapeModelLoader:
""" responsible for loading a milkshape model.
"""
def __init__(self, file_name = ""):
self._debug_level = 0
self._is_tex = 0
if file_name:
self.Load(file_name)
def _debug(self, x, debug_level = 1):
"""
"""
if self._debug_level > debug_level:
print x
def IsTextured(self):
if self._is_tex:
return 1
else:
return 0
def Load(self, file_name):
"""
"""
t1 = time.time()
self.data = ms3d_ascii_importer.convert_milkshape( file_name )
t2 = time.time()
self._debug("load time of milk:%s:" % (t2 - t1), 2)
d = self.data["mesh_data"][0]
material_index = d["material_index"]
self._debug("material_index:%s" % material_index, 2)
self.texcoords= Numeric.asarray(d["texcoords"], 'f')
self.points = Numeric.asarray(d["points"], 'f')
self.normals = Numeric.asarray(d["normals"], 'f')
self.indices = Numeric.asarray(d["indices"], 'i')
if material_index != -1:
m = self.data["materials"][material_index]
self._debug("m.material_name:%s" % m.material_name, 2)
self._debug("m.diffuse_texture_name:%s" %m.diffuse_texture_name, 2)
self._debug("m.alpha_texture_name :%s" %m.alpha_texture_name, 2)
self.image_name = apply(os.path.join, os.path.split(m.diffuse_texture_name[2:]))
#NOTE: FIXME: materials don't need textures.
#NOTE: FIXME: there are different textures too.
self._is_tex = 1
#time.sleep(2)
else:
self._is_tex = 0
self.skeleton = MilkSkeleton(self.data)
class BoneHeirarchy:
""" Which bones are parents/children of which other bones.
- has bone names, and bone indices into AbsoluteBones/RelativeBones.
- GetChildren_names/indices - returns a list of names/indices.
BoneName2BoneNumber_Map - mapping of bone names to a number in the bone
index.
"""
def __init__(self, milk_bones):
"""Takes a milk_bones variable from the milkshape converter.
"""
# given the parents name get back a list of children.
self.bone_parents_dict= {}
# given the childs name get back a parent.
self.bone_children_dict= {}
# given a bone name you can get the idx of that bone in the bone list.
self.bone_name_to_idx = {}
self.Update(milk_bones)
def Update(self, milk_bones):
""" Takes a milk_bones variable from the milkshape converter.
"""
#NOTE: if we want to use 1000's bones it may be more efficient to use
# ints as the keys. and possibly lists to store them.
#
# This is an efficient storage for 1000's of skeletons with 1000's of
# bones. 1000 * 1000 * 20 == 20 megabytes.
# 1000 * 1000 * 4 == 4 megabytes for a list implementation.
self.bone_parents_dict= {}
self.bone_children_dict= {}
self.bone_name_to_idx = {}
# keyed by bone name, valued by milk_bones instances.
self.bone_dict = {}
for b in milk_bones:
if not self.bone_parents_dict.has_key(b.parent_name):
self.bone_parents_dict[b.parent_name] = [b.name]
else:
self.bone_parents_dict[b.parent_name].append(b.name)
if not self.bone_children_dict.has_key(b.name):
self.bone_children_dict[b.name] = [b.parent_name]
else:
self.bone_children_dict[b.name].append(b.parent_name)
#assert( not self.bone_dict.has_key(b.name) )
self.bone_dict[b.name] = b
self.bone_name_to_idx = self._make__bone_name_to_idx(milk_bones)
def _make__bone_name_to_idx(self, milk_bones):
""" returns a dict mapping bone name -> its idx within the list.
"""
bone_name_to_idx = {}
for idx, milk_bone in zip(range(len(milk_bones)), milk_bones):
if bone_name_to_idx.has_key(milk_bone.name):
raise ValueError("bone allready exists with name, %s" % milk_bone.name)
bone_name_to_idx[milk_bone.name] = idx
return bone_name_to_idx
def GetChildren_idx(self, bone_name):
""" returns a list of idx for the children of given bone name.
"""
children = self.GetChildren(bone_name)
idx_list = []
for child in children:
idx_list.append(self.bone_name_to_idx[child.name])
return idx_list
def GetChildren(self, bone_name):
""" Returns a list of children milk_bone instances."""
if not self.bone_parents_dict.has_key( bone_name ):
return []
return map(self.bone_dict.get, self.bone_parents_dict[ bone_name ])
#return self.bone_dict[ self.bone_parents[ bone_name ] ]
def GetParents(self, bone_name):
""" Returns a list of parents milk_bone instances."""
if not self.bone_children_dict.has_key( bone_name ):
return []
return map(self.bone_dict.get, self.bone_children_dict[ bone_name ])
#return self.bone_children[ bone_name ]
def GetRootName(self):
""" Returns the root bones name.
"""
return self.bone_parents_dict[""][0]
def __str__(self):
return self.PrintTree(details = 1)
def PrintTree(self, a_bone = "ROOT", indent_level = 0, details = 0):
""" Returns a string representation of bones tree.
a_bone - a milk_bone instance, or "ROOT".
if "ROOT" then we return from the root of the tree.
"""
if a_bone == "ROOT":
a_bone = self.bone_dict[self.GetRootName()]
return_text_list = []
indent_text = indent_level * " "
if details:
bone_text = str(a_bone)
bone_text.split("\n")
a = "".join(map(lambda x,y = indent_text: "".join((y,x,"\n")), bone_text.split("\n")))
return_text_list.append( a )
else:
return_text_list.append( indent_text + a_bone.name )
children = self.GetChildren(a_bone.name)
for bone in children:
child_text = self.PrintTree(bone, indent_level+2, details)
return_text_list.append(child_text)
return string.join( return_text_list, "\n")
class BoneName2BoneNumber_Map(UserDict.UserDict):
""" mapping of bone names to a number in the bone index.
"""
def __init__(self, milk_bones):
UserDict.UserDict.__init__(self)
self.Update(milk_bones)
def Update(self, milk_bones):
for b in zip( milk_bones, range(len(milk_bones)) ) :
self.data[b[0].name] = b[1]
class Bone2Vert_Map(UserDict.UserDict):
""" a list of indices for the verts that each bone should transform.
Should probably be a Numeric 3d array.
where self.data[0] == list of vert indices for the first bone.
Each index could be 4 bytes for four bones.
- this would be harder to access.
- would limit the total number of bones.
For now keep it simple.
"""
def __init__(self, milk_data):
self.Update(self, milk_data)
def Update(self, milk_data):
"""
"""
# note: milkshape can only have one bone per vert.
data = milk_data["mesh_data"]["bone_indices"]
#self.data = Numeric.reshape(data, (len(data), 1))
bone2vert_map = {}
for bone_idx, vert_idx in zip(data, len(data)):
#
if not bone2vert_map.has_key(bone_idx):
bone2vert_map[bone_idx] = [vert_idx]
else:
bone2vert_map[bone_idx].append(vert_idx)
#
class Vert2Bone_Map:
def __init__(self, ):
self.Update(self, milk_data)
def Update(self, milk_data):
"""
"""
# note: milkshape can only have one bone per vert.
data = Numeric.array(milk_data["mesh_data"]["bone_indices"], 'i')
self.data = Numeric.reshape(data, (len(data), 1))
class Time2Keyframe_Map:
"""
Each bone should be able to have it's own key frames.
time2keyframe_maps[bone_name] -> time2keyframe_map
time2keyframe_map[seconds_since_start_of_animation] -> keyframe index's.
Depending on whether we want the animation to loop or stop at the start
or the end, we return a keyframe on either side of the time specified.
TODO: we can loop at the start of the keyframes as well as at the end.
"""
def __init__(self, loop = 0):
""" loop - should we loop the animation back to the start once the last
keyframe has been reached?
"""
self.loop = loop
def UpdateFromBones(self, milk_bone):
""" milk_bone - used to get the different times for the keyframes.
"""
times = []
map(lambda x, t = times: t.append(x[0]), milk_bone.positions)
self.times = times
self.Update(times)
def Update(self, times):
""" times - a sequence of floats representing keyframes.
"""
self.times = times
# Should the internal format be a dict and a list?
# yes, as we need to find the next, and previous, as well as by a number.
# should we have seperate keyframes for rotations, translations,
# and scaling?
# Why not? We do not have support for it in any editor.
# not immediately useful.
# For now we will just use the times for rotations.
#TODO: incomplete.
#raise NotImplementedError
# the times should be sorted.
self.time_index = {}
# make an index of times.
for t, i in zip(times, range(len(times))):
self.time_index[t] = i
def GetIndicesEitherSideOfTime(self, time):
""" time - a float
Returns the two keyframe indices either side of the time given.
"""
# no looping.
# Find the smallest time which is greater than the time given.
# TODO: need to do better than a linear search.
# the code below is incomplete, needs fixing.
raise "incomplete"
largest_num = len(self.times) - 1
if time == self.times[smaller_index]:
greater_index = 0
smaller_index = bisect.bisect_left(self.times, time)
# if the position is greater than or equal to the largest index,
# then we return the largest num as both of them.
if smaller_index >= largest_num:
smaller_index = largest_num
greater_index = largest_num
else:
greater_index = smaller + 1
if greater_index > largest_num:
greater_index = largest_num
class AbsoluteBones:
"""
Stores the absolute transforms. There is a seperate one of these
for each keyframe.
- Need matrix, and quat+pos_vector versions
- The matrix versions would be used to transform verts.
- The quat_pos_vector versions will blend with other bones.
- The conversion to matrices will need to be cached.
- Use three arrays.
- rotation quats( an array of 'four elements' ).
- translation quats(array of 'four elements' ).
Maybe only need matrix version for absolute?
- No, need to slerp between two absolute bones.
Don't need a matrix representation?
- maybe not, if the these are only used to slerp up an intermediate
set of bones.
NOTE: for transforming the verts, it will be faster to transform them with
a 3x3 rotation matrix if there is no translation/scaling happening.
"""
class RelativeBones:
"""
Stores transforms relative to it's parent. There is a seperate set
of these for each of the keyframes.
- Need matrix, and quat+pos_vector versions
- The matrix versions would be used to transform verts.
- The quat_pos_vector versions will blend with other bones.
- The conversion to matrices will need to be cached.
- Use three arrays.
- rotation quats( an array of 'four elements' ).
- translation quats(array of 'four elements' ).
TODO: find if a quatRotation * quatTranslation is equal to a
matrixRotation * matrixTranslation.
"""
def Update(self, milk_bone):
""" From the milkshape data transform it into an internal representation.
milk_bone - a bone from the converter.
- Convert the Euler angle milkshape rotations into quaternions.
- Convert the milkshape positions into quaternions.
Q(Px, Py, Pz, w =0.0)
- rotation, position quaternions multiplied and stored.
"""
#
mb = milk_bone
mb.position
mb.position_keys
mb.rotation
mb.rotation_keys
class MilkSkeleton:
"""
----------------------------------------------------------------------
Data structures.
- '=' denotes data belongs to this parent.
Skeleton - this is where everything is put together.
- we may want to share some data between skeletons, so we may need a
higher level system.
- this higher level system would share the different parts of memory.
- Maybe it could even transform all of the data at once.
= BoneHeirachy DONE.
= Keyframes
= Bone2Vert_Map DONE.
= Time2Keyframe_Map
= KeyframeNumber2Time_Map
Keyframes - collects the different keyframe data for a skeleton.
= AbsoluteBones
= RelativeBones
= Time2Keyframe_Map
= KeyframeNumber2Time_Map
AbsoluteBones - bones represented in their absolute form.
- Need matrix, and quat+pos_vector versions
- The matrix versions would be used to transform verts.
- The quat_pos_vector versions will blend with other bones.
- The conversion to matrices will need to be cached.
- Use three arrays.
- rotation quats( an array of 'four elements' ).
- translation quats(array of 'four elements' ).
- transform matrices(array of '16 elements' ie 4x4 matrices).
RelativeBones - these bones will have all relative data. Eg each bone
will only be relative to the others.
Time2Keyframe_Map. - gets two keyframes on either side of a given time.
- this would be per bone? Not at the moment(it should be per skeleton).
KeyframeNumber2Time_Map. - given a keyframe number, give the time for it.
- this would be per bone? Not at the moment(it should be per skeleton).
DONE.
BoneHeirachy - which bones are parents/children of which other bones.
- has bone names, and bone indices into AbsoluteBones/RelativeBones.
- GetChildren_names/indices - returns a list of names/indices.
BoneName2BoneNumber_Map - mapping of bone names to a number in the bone
index.
DONE.
Bone2Vert_Map - a list of indices for the verts that each bone should
transform.
Vert2Bone_Map - vert to list of bones which effect them.
MilkBones - this is the data from the milk format. This contains
the positions, and rotations in euler format, and the keyframe times.
local2world_transform - a transform specifying where in the world the
skeleton is.
- This will likely change occasionally.
- from every frame to once every minute.
- is this specified by the root node?
- Could we add this as the new root node?
- would simplify the code if we did.
- Can be added as an after thought if needed. Pretty easy.
- Not really, as it possible this would change all the time.
- We may want to add this, as it will solve having to re-transform them.
- On the other hand this could be done in hardware with gf+ cards.
----------------------------------------------------------------------
---------------------------------------------------------------------
Order of the operations.
- Things that need to be done in order to get the model transformed.
Set up stuff. - things to do around load time.
From the milk bones set up:
- BoneHeirachy
- Set up the relative bones.
- Convert the Euler angle milkshape rotations into quaternions.
- Convert the milkshape positions into quaternions.
Q(Px, Py, Pz, w =0.0)
- rotation, position quaternions multiplied and stored.
- Time2Keyframe_Map
- KeyframeNumber2Time_Map
AbsoluteBones are made from RelativeBones.
For each keyframe.
Multiply the bones down the heirarchy.
child.absolute = parent.absolute * child.relative
Per frame stuff.
Get current time in animation.
From Time2Keyframe_Map grab two keyframes on either side of current time.
For every absolute quat:
Interpolate between two keyframes:
t1 = current_time_in_animation - kf_a.time
t2 = kf_b.time -kf_a.time
slerp = t1/t2
frame_now = quat_slerp(kf_a.absolute, kf_b.absolute, slerp)
Generate the matrices for each absolute quat.
Transform each absolute matrix by the local2world_transform.
Transform verts of the mesh:
For vertex which is affected by one bone:
For each absolute matrix transform its verts.
If the vert is only affected by one bone:
Multiply the vert by the absolute matrix.
else:
somehow interpolate the different bones.
- TODO: ^
- maybe this could be done in the slerp?
- storing some extra absolute quats for the verts affected
by multiple ones.
- this is where bone weights can fit in.
For now we will only support one bone per vertex.
Alternate way to transform the skin:
For each vertex:
look at the weight structure.
ulong32 boneIndices - 4 indices to bones.
ulong32 weights - 4 weights.
---------------------------------------------------------------------
Optimizations.
---------------------------------------------------------------------
When a key frame does not have any translations the transform of the
vertices can be optimized to only use a 3x3 rot, instead of a 4x4.
- There may be other optimizations depending on the bones state.
- Maybe we could store a BONE_STATE int which will allow us to
quickly identify a type of bone? This would allow us to quickly
see if the bone has no translation.
- We could group bones of similar nature together to make the
transforms quicker. Eg all bones with no translation part could
be stuck together.
- Remember that we need to apply a local2world transform to all of the
different absolute matrices.
We may be able to cache certain different transforms.
- I'm pretty sure there will be many repeated transforms.
A cheap way to interpolate between keyframes would be linear using the
mesh's verts.
This would involve calculating the mesh for each key frame, and then
interpolating between each vertex in meshes a, and b.
Perhaps this could be an optional thing. To be used for slow
computers, when a character is far away, or when the difference in
time or movement of the character is really small.
A downside to this is that you need to keep at least three sets of the
mesh around at any time.
An upside to this is that interpolation can be done on
lighting values too.
---------------------------------------------------------------------
---------------------------------------------------------------------
TODOS:
Future todos:
- have keyframe data for seperate parts of the skeleton.
- eg make the hand have it's own keyframes.
- This would complicate how to construct the absolute quats.
- You would recalculate down from the animation for that part.
- so if the arm was using some extra ones we'd go from there.
- Probably not so useful until the animation tool supports it.
- Incorporate bone weights into it.
- Milkshape doesn't support these, however others(characterfx) do.
- Look at the different ways to accelerate these with hardware.
- ati, and nvidia have things to do this from geforce up.
---------------------------------------------------------------------
---------------------------------------------------------------------
Dependencies
- a list of different dependencies that need to be considered.
- helps with caching different things.
---------------------------------------------------------------------
---------------------------------------------------------------------
OLD Order of the operations.
X Convert the axis angle milkshape rotations into quaternions.
X The translations should also be converted into quaternions,
X and multiplied by the rotation part. Q(Px, Py, Pz, w =0.0)
X Have an absolute quaternion, and a relative one for each bone.
X Quats should be seperate for the current frame that is to be rendered.
X - that is the final bones for the current frame should be in a single
X array.
X - this is so that they may be easily converted to matrices.
X Absolute matrices for the current frame should be made.
X - these matrices include
For each keyframe.
Multiply the bones down the heirarchy.
child.absolute = parent.absolute * child.relative
To interpolate between two keyframes we do:
t1 = current_time_in_animation - keyframe_a.time
t2 = keyframe_b.time -keyframe_a.time
slerp = t1/t2
frame_now = quat_slerp(keyframe_a.absolute, keyframe_b.absolute, slerp)
Any time a bones rotation changes we need to recalculate all of its
children.
To transform verts of the mesh:
We need the absolute matricies for each bone.
Do we support multiple bones per vertex?
If so will we use weighting?
Apply a local2world transform to all of the different absolute matrices.
- this should be added as a new root node.
"""
def __init__(self, milk_data):
""" the data attribute from the milkshape converter.
"""
milk_bones = milk_data['bones']
self.milk_bones = milk_bones
self.bone_heirarchy = BoneHeirarchy(milk_bones)
self.bone_name2bone_number_map = BoneName2BoneNumber_Map(milk_bones)
# for each bone we need:
# - rotations.
# - positions.
# - scales.
# - keyframe number -> time map.
# - Way to get the two keyframes on either side of a given time.
# these are 4 element quats.
#self.rotations = N.array()
# these are 3 element positions.
#self.positions = N.array()
def _convert_angles_to_quats(self):
""" This converts the different rotations of the bones into
quaternions.
"""
new_rdpyg/build/lib/urdpyg/__init__.py 0000644 0001751 0001751 00000000272 10075756270 020264 0 ustar rene rene 0000000 0000000 """
The unstable part of rdpyg.
Contains modules that are not very well designed, tested, or commented, and
which are not planned to be have the same api stick around for ages.
"""
new_rdpyg/build/lib/urdpyg/gl_images.py 0000644 0001751 0001751 00000006231 07752432402 020451 0 ustar rene rene 0000000 0000000 #file: images.py
#purpose: everything to do with image loading.
import pygame
import os
import time
from OpenGL.GL import *
try:
from mygl import *
except:
pass
def load_gl_textureRGB(name, flip = 1, internal_format = GL_RGB):
""" returns a texid for the loaded image.
"""
if type(name) == type(""):
im_surf = pygame.image.load(os.path.join("..", "data", "images", name))
else:
im_surf = name
image = pygame.image.tostring(im_surf, "RGB", flip)
image_width = im_surf.get_width()
image_height = im_surf.get_height()
#TODO: add check for pow2 size.
tex = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, tex)
##glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
##glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
#glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
#glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
#glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
#glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
#glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)
#glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)
#glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP)
#glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP)
#glEnable(GL_TEXTURE_GEN_S)
#glEnable(GL_TEXTURE_GEN_T)
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, image_width, image_height,
0, GL_RGB, GL_UNSIGNED_BYTE, image)
return tex
def load_gl_textureRGBA(name, flip = 1, internal_format = GL_RGBA):
if type(name) == type(""):
im_surf = pygame.image.load(os.path.join("..", "data", "images", name))
else:
im_surf = name
image = pygame.image.tostring(im_surf, "RGBA", flip)
#print t2 - t1
image_width = im_surf.get_width()
image_height = im_surf.get_height()
#TODO: add check for pow2 size.
tex = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, tex)
##glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
##glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
#glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
#glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
#glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
#glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
#glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)
#glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)
#glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP)
#glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP)
#glEnable(GL_TEXTURE_GEN_S)
#glEnable(GL_TEXTURE_GEN_T)
#glTexImage2D(GL_TEXTURE_2D, 0, 3, image_width, image_height,
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, image_width, image_height,
0, GL_RGBA, GL_UNSIGNED_BYTE, image)
return tex
new_rdpyg/build/lib/urdpyg/milkviewer4.py 0000644 0001751 0001751 00000004223 10076013353 020754 0 ustar rene rene 0000000 0000000
import pygame
from OpenGL.GL import *
from numeric_gl import *
from urdpyg.converters import ms3d_ascii_importer
from urdpyg.milk_skeleton import *
from urdpyg import gl_images
class MilkshapeModel(MilkshapeModelLoader):
""" Loads and displays a milk shape 3d model.
"""
def Load(self, file_name):
MilkshapeModelLoader.Load(self, file_name)
if self.IsTextured():
self.LoadImage(self.image_name)
def LoadImage(self, filename):
im_surf = pygame.image.load(filename)
self.tex = gl_images.load_gl_textureRGB(im_surf)
def ReloadTextures(self):
""" reloads any textures. Useful when a context change happens.
"""
# NOTE: Shouldn't delete the texture... I think.
if self.IsTextured():
self.LoadImage(self.image_name)
def Display(self):
""" Call this to draw.
"""
# set up the correct model matrix.
self._StartDisplay()
self._MiddleDisplay()
self._FinishDisplay()
def _MiddleDisplay(self):
glDrawElementsui(GL_TRIANGLES, self.indices)
def _StartDisplay(self):
""" This is all the stuff you call before drawing.
"""
# bind the correct texture/s
# enable the arrays for drawing.
# draw the arrays.
#print "points", self.points
#print "texcoords", self.texcoords
#print "indices", self.indices
if self.IsTextured():
glEnable(GL_TEXTURE_2D)
# Enables depth testing.
glEnable(GL_DEPTH_TEST)
# Enables smooth shading.
glShadeModel(GL_SMOOTH)
if self.IsTextured():
glBindTexture(GL_TEXTURE_2D, self.tex)
glEnableClientState(GL_VERTEX_ARRAY)
if self.IsTextured():
self._debug("is tex",4)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glVertexPointer(3, GL_FLOAT, 0, self.points)
if self.IsTextured():
glTexCoordPointer(2, GL_FLOAT, 0, self.texcoords)
def _FinishDisplay(self):
""" Call after drawing.
"""
glDisableClientState(GL_VERTEX_ARRAY)
if self.IsTextured():
glDisableClientState(GL_TEXTURE_COORD_ARRAY)
glDisable(GL_DEPTH_TEST)
if self.IsTextured():
glDisable(GL_TEXTURE_2D)
new_rdpyg/build/lib/urdpyg/music.py 0000644 0001751 0001751 00000012552 10076374352 017647 0 ustar rene rene 0000000 0000000 # file: music.py
# purpose: responsible for loading and playing music.
"""
"""
music_events = ["game over happy",
"game over sad",
"game start",
"using special",
"close to end of game",
]
# Different conditions for happy/sad music.
#
# 2 player, single computer.
# - game over happy.
# 2 player, networked, local loses.
# - game over sad.
# 2 player, networked, local wins.
# - game over happy.
# 1 player, human wins.
# - game over happy
# 1 player, human loses.
# - game over sad.
#
import os, glob
import pygame.mixer
import pygame.mixer_music
from rdpyg.util import cyclic_list
import config
import sound_config
from rdpyg.util import vtimer
class Music:
""" Useage:
m = Music()
m.Play("intro")
m.Play("bla")
Need a directory ../data/music/intro.ogg
"""
def __init__(self):
"""
"""
# for playing a track in 0.3 sec.
self.play_timer= vtimer.vtimer(0.2, self.music_play_callback)
self.fade_in_timer = vtimer.vtimer(0.2)
self.fade_out_timer = vtimer.vtimer(0.2)
# don't let it do a callback until finished.
self.play_timer.set_finished_no_callback()
self.fade_in_timer.set_finished_no_callback()
self.fade_out_timer.set_finished_no_callback()
self.fade_in = 0
self.fade_out = 0
self.GetFileNames()
vol = config.max_music_volume
self.SetMaxVol(vol)
pygame.mixer.music.set_volume(vol)
self.SetLoudVol(vol + 0.2)
def SetLoudVol(self, vol):
""" louder than max volume. this is for special occasions.
"""
if vol >= 1.0:
self.max_loud_volume = 1.0
else:
self.max_loud_volume = vol
def SetMaxVol(self, vol):
""" sets the maximum volume for the music.
"""
if vol >= 1.0:
self.max_volume = 1.0
else:
self.max_volume = vol
def Load(self, music_type):
""" music_type - one of the music types from the sound_config.
"""
if music_type == "intro":
snd = sound_config._get_random(sound_config.music_types[music_type])
else:
snd = sound_config._get_cyclic(sound_config.music_types[music_type])
pygame.mixer.music.load(self.sound_dict[snd])
def music_play_callback(self):
self.Load(self.music_type)
pygame.mixer.music.play(self.loop)
def GetFileNames(self, path = os.path.join("..", "data", "music")):
""" returns a dict of file names to be used as music. keyed by the file name
without path, and .ogg.
path - to the file names.
"""
#self.sound_list = map(lambda x:x[7:-4], glob.glob(os.path.join(path,"*.ogg")) )
self.sound_list = glob.glob(os.path.join(path,"*.ogg"))
#print self.sound_list, "sound list"
self.sound_dict = {}
for sound in self.sound_list:
file_name = os.path.split(sound)[-1]
file_start = os.path.splitext(file_name)[0]
self.sound_dict[file_start] = sound
return self.sound_dict
def Play(self, music_type, loop = -1):
""" Starts playing the music.
"""
self.music_type = music_type
self.loop = loop
if pygame.mixer.music.get_busy():
# fade out the playing track, then play ours.
#pygame.mixer.music.fadeout(1000)
self.fade_out_timer.reset()
self.fade_out = 1
# get ready to play the next song :)
self.play_timer.reset()
else:
self.Load(music_type)
pygame.mixer.music.play(self.loop)
def Update(self, elapsed_time):
""" To be called frequently.
"""
self.play_timer.Update(elapsed_time)
self.fade_out_timer.Update(elapsed_time)
self.fade_in_timer.Update(elapsed_time)
if self.fade_out:
vol = self.fade_out_timer.left_normalised()
vol *= self.max_volume
pygame.mixer.music.set_volume(vol)
if self.fade_out_timer:
# we have faded out.
self.fade_out = 0
self.fade_in_timer.reset()
self.fade_in = 1
if self.fade_in:
vol = (1. - self.fade_in_timer.left_normalised())
vol *= self.max_volume
pygame.mixer.music.set_volume(vol)
if self.fade_in_timer:
# we have faded in.
self.fade_in = 0
if 0:
if not (self.play_timer_100.just_finished or
self.play_timer_1000.just_finished):
if self.play_timer_1000 or self.play_timer_100:
# check to see if there is any music playing if not, play it.
if not pygame.mixer.music.get_busy():
self.Load(self.music_type)
pygame.mixer.music.play(2)
#if not pygame.mixer.music.get_busy():
# pygame.mixer.music.load(self.current)
# self.Play()
def Pause(self):
""" pauses the music.
"""
pygame.mixer.music.pause()
def UnPause(self):
pygame.mixer.music.unpause()
def Stop(self):
"""
"""
#pygame.mixer.music.stop()
pygame.mixer.music.fadeout(100)
new_rdpyg/build/lib/urdpyg/some_sound.py 0000644 0001751 0001751 00000006332 07713675013 020703 0 ustar rene rene 0000000 0000000 """
file: some_sound.py
purpose: to load all the sounds, and manage the playing of them.
Probably have different sets of sounds in here somehow.
"""
import pygame
import os
import glob
from pygame.locals import *
def get_sound_list():
"""
"""
# load a list of sounds without sound/ at the beginning and .wav at the end.
sound_list = map(lambda x:x[7:-4],
glob.glob(os.path.join("sounds","*.wav"))
)
ogg_sound_list = map(lambda x:x[7:-4],
glob.glob(os.path.join("sounds","*.ogg"))
)
sound_list.extend(ogg_sound_list)
return sound_list
class SoundManager:
""" Controls loading, mixing, and playing the sounds.
Having seperate classes allows different groups of sounds to be loaded,
and unloaded from memory easily.
"""
def __init__(self):
"""
"""
self.mixer = None
self.music = None
self.sounds = {}
self.chans = {}
self.initialized = 0
self._debug_level = 1
def _debug(self, x, debug_level = 0):
"""
"""
if self._debug_level > debug_level:
print x
def Initialize(self):
""" Initializes the mixer.
"""
global mixer, music
try:
import pygame.mixer
pygame.mixer.init(44000, 8, 0)
mixer = pygame.mixer
music = pygame.mixer.music
self.initialized = 1
return 1
except (ImportError, pygame.error):
self.initialized= 0
self._debug("Error initializing sound.")
return 0
def Load(self, names = sound_list):
"""Loads sounds."""
sounds = self.sounds
if not mixer:
for name in names:
sounds[name] = None
return
for name in names:
if not sounds.has_key(name):
fullname = os.path.join('sounds', name+'.wav')
try:
sound = mixer.Sound(fullname)
except:
sound = None
self._debug("Error loading sound")
sounds[name] = sound
def GetSound(self, name):
""" Returns a Sound object for the given name.
"""
if not self.sounds.has_key(name):
self.Load([name])
return self.sounds[name]
def Play(self, name, volume=[1.0, 1.0], wait = 1):
""" Plays the sound with the given name.
name - of the sound.
volume - left and right. Ranges 0.0 - 1.0
wait - if there is a sound of this type playing wait for it.
"""
vol_l, vol_r = volume
sound = self.GetSound(name)
if sound:
if self.chans.has_key(name):
c = 0
while self.chans[name].get_busy():
time.sleep(0.001)
c += 1
if c > 40:
break
self.chans[name] = sound.play()
if not self.chans[name]:
self.chans[name] = pygame.mixer.find_channel(1)
self.chans[name].play(sound)
if self.chans[name]:
self.chans[name].set_volume(vol_l, vol_r)
del self.chans[name]
def PlayMusic(self, musicname):
""" Plays a music track. Only one can be played at a time.
So if there is one playing, it will be stopped and the new one started.
"""
music = self.music
if not music: return
if music.get_busy():
#we really should fade out nicely and
#wait for the end music event, for now, CUT
music.stop()
fullname = os.path.join('sounds', musicname)
music.load(fullname)
music.play(-1)
music.set_volume(1.0)
new_rdpyg/build/lib/urdpyg/some_sprites.py 0000644 0001751 0001751 00000032666 07643510703 021251 0 ustar rene rene 0000000 0000000 """
file: some_sprites.py
purpose: animation, sprite playing.
"""
import os, os.path, glob, sys, bisect
import time
import pygame
#import pygame.transform
from pygame.locals import *
DEBUG = 0
SCREENRECT = Rect(0, 0, 640, 480)
try:
import use_gl
USE_GL = use_gl.USE_GL
print "ahasjdhasjkhkjhsfd"
except:
USE_GL = 0
print USE_GL
if USE_GL:
from spritegl import SpriteGL, GroupGL
pygame.sprite.Sprite = SpriteGL
pygame.sprite.Group = GroupGL
pygame.sprite.RenderPlain = GroupGL
pygame.sprite.RenderUpdates = GroupGL
#layer_order = ["walk_forwards",
# "walk_left",
# "walk_right",
# "red background",
# "transparent background"]
"""
layer_order = ["bam",
"yellow",
"red",
"orange"
]
"""
# animations are made out of different frames from the character anim.
# they have a list of frames, and a length of time for each frame.
#animations = {}
#a = animations
#a['walk'] = [("walk_forwards", 1.0 ),
# ("walk_right", 1.0),
# ("walk_forwards", 1.0),
# ("walk_left", 1.0),
# ("walk_forwards", 1.0),
# ]
"""
a['bam'] = [
("orange", 0.01 ),
("red", 0.01),
("yellow", 0.01),
("orange", 0.01 ),
("red", 0.01),
("yellow", 0.01),
("orange", 0.01 ),
("red", 0.01),
("yellow", 0.01),
("bam", 0.4),
]
"""
def get_background_names(base_dir):
""" TODO: needs fixing/testing.
"""
background_names = map(lambda x:x[len("background")+1:-4],
glob.glob(os.path.join(base_dir,
"background",
"*.png"))
)
background_names.extend( map(lambda x:x[len("background")+1:-4],
glob.glob(os.path.join(base_dir,
"background",
"*.jpg"))
)
)
return background_names
class Timer:
def __init__(self, length):
""" a = Timer(10)
# if the timer is finished.
if a:
print "asdf"
"""
self.Start(length)
def Start(self, length):
""" length is the amount of time that this timer should go for.
"""
self.end_time = time.time() + length
def __nonzero__(self):
if time.time() > self.end_time:
return 1
else:
return 0
def animation_factory(anim_data, loop = 1):
""" Returns a dict keyed by anim_name valued by Animation instances.
anim_data - keyed by anim name, valued by a list of tuples(frame_name, length).
loop - passed through to Animation class.
"""
anims = {}
for anim_name in anim_data.keys():
anims[anim_name] = Animation(anim_data[anim_name], anim_name, loop)
return anims
class Animation:
""" For telling which of the frames should be drawn.
Howto use:
a = Animation(...)
a.Start()
if a.StillGoing():
new_frame_to_draw = a.NewFrame()
if new_frame_to_draw:
draw(new_frame_to_draw)
else:
# old frame to be rendered.
pass
else:
# figure out what to do at end of anim.
pass
"""
def __init__(self, animation_data, name, loop = 1):
""" animation_data - a list of tuples (frame_name, time).
The time part says for how long in the animation that the
frame should be shown.
Must have at least one element.
loop - should the animation loop.
If 0 the animation will return the last frame when it gets to the end.
If -1 the animation will loop for ever.
If non zero the animation will loop that many times.
"""
assert(len(animation_data) > 0)
self.animation_data = animation_data
self.loop = loop
self.name = name
self.Start()
self.SetUpAnimationData(animation_data)
self.last_frame = ""
def Start(self, loop = 1):
""" Starts the animation at the beginning.
"""
self.loop = loop
self.start_time = time.time()
self.last_frame = ""
def GetName(self):
return self.name
def NewFrame(self):
""" Returns the frame name if there is a new frame needed for the animation.
Otherwise returns 0.
"""
frame_name = self.StillGoing()
if frame_name == self.last_frame:
return 0
else:
return frame_name
def StillGoing(self):
""" returns the frame name if still going else, returns 0 if finished.
"""
# Add up the total length of the anim.
cur_time = time.time()
since_beginning = cur_time - self.start_time
# do the infinity loop.
if self.loop == -1:
time_in_anim = since_beginning % self.GetLengthOfAnim()
# no looping of anim.
elif self.loop == 0:
if since_beginning > self.GetLengthOfAnim():
# we are finished, so we return 0.
return 0
else:
time_in_anim = since_beginning
# we are set to play a specific number of times.
else:
if since_beginning > self.loop * self.GetLengthOfAnim():
# we are finished, so we return 0.
return 0
# find out where we are in the animation.
time_in_anim = since_beginning % self.GetLengthOfAnim()
# figure out which frame we are at.
frame_name = self._GetFrameGivenTimeInAnim(time_in_anim)
return frame_name
def SetUpAnimationData(self, animation_data):
""" Sets up the animation data ready for processing.
"""
self.anim_length_once = reduce(lambda x,y: x+y, map(lambda x:x[1],self.animation_data ))
# set up the animation data for easy bisecting.
# make a list of the animation data that holds the time that the frame starts.
self.absolute_anim_data = []
total_time = 0.
for frame_name, frame_length in self.animation_data:
total_time += frame_length
self.absolute_anim_data.append( total_time )
def _GetFrameGivenTimeInAnim(self, time_in_anim):
""" Returns the frame name we should be rendering given a time in the anim.
"""
where_in = bisect.bisect(self.absolute_anim_data, time_in_anim)
if where_in < 0:
return self.animation_data[0][0]
return self.animation_data[where_in][0]
def GetLengthOfAnim(self):
return self.anim_length_once
def GetNumTimesPlayed(self):
""" Returns the number of times the animation has been played.
"""
cur_time = time.time()
return int( divmod(cur_time - self.start_time, self.anim_length_once)[0] )
def A__nonzero__(self):
""" Used to see if the animation is still going.
"""
raise "Not implemented"
def get_character_frame_names(the_layer_order, base_dir = ".."):
""" returns a dict keyed by character name, valued by a
dict(keyed by meaningful name, valued by image path name).
"""
global DEBUG
character_names = filter(lambda x: os.path.isdir(os.path.join(base_dir, "characters",x)) , os.listdir(os.path.join(base_dir, 'characters')))
#print character_names
character_frame_names = {}
for character_name in character_names:
t = glob.glob(os.path.join(base_dir,
"characters",
character_name,
"*.gif"))
t.extend( glob.glob(os.path.join(base_dir,
"characters",
character_name,
"*.png")) )
# sort them so that they are in numerical order.
# the naming scheme of gimp allows this with the normal sort func.
t.sort()
t.reverse()
# now map the gimp file names with the meaningful names.
if len(t) != len(the_layer_order):
if DEBUG:
print "don't have the correct number of frames for character:%s" % (character_name)
print t
print the_layer_order
r = {}
for meaning, img_path in zip(the_layer_order, t):
r[meaning] = img_path
character_frame_names[character_name] = r
return character_frame_names
def read_anim_data(character_name, base_dir = ".."):
""" Reads the animation data from the characters anim.py file.
"""
d = {}
e = {}
file_name = os.path.join(base_dir, "characters",character_name , "anim.py")
contents = open(file_name).read()
a = compile(contents, file_name, "exec")
eval(a, e, e)
return [e['animations'],
e['layer_order']]
image_cache = {}
def load_image(name, colorkey=None, convert_alpha = 0):
global image_cache
if image_cache.has_key(name):
return [image_cache[name][0], pygame.Rect(image_cache[name][1])]
try:
image = pygame.image.load(name)
except pygame.error, message:
print 'Cannot load image:', name
raise SystemExit, message
if convert_alpha:
image = image.convert_alpha()
else:
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
image_cache[name] = (image, image.get_rect())
return image_cache[name]
class A(pygame.sprite.Sprite):
def __init__(self, im_name):
pygame.sprite.Sprite.__init__(self) #call Sprite initializer
self.image, self.rect = load_image(im_name, -1)
class ImageAnimation(pygame.sprite.Sprite):
def __init__(self, animation_set_name, initial_animation):
""" animation_name - name of the animation set to use.
"""
pygame.sprite.Sprite.__init__(self) #call Sprite initializer
self.animation_set_name = animation_set_name
self.current_animation = initial_animation
self.position = (0,0)
# make self.layer_order, and self.animations
self.LoadAnimationData()
#character_image_dict - this is a dict keyed by
# meaningful name, valued by image path name.
self.character_image_dict = get_character_frame_names(self.layer_order)[animation_set_name]
# load the images.
self.images = {}
self.LoadImages()
# Make a whole heap of animation classes.
self.anims = animation_factory(self.animations, loop = -1)
self.StartAnim(self.current_animation)
# modified_images is a dict keyed by modified type valued by
# a dict of images of the frames.
self.modified_images = {}
self.modified_images['originals'] = self.images
def StartAnim(self, anim_name, loop = 1):
self.current_animation = anim_name
self.anims[self.current_animation].Start(loop)
new_frame_to_draw = self.anims[self.current_animation].NewFrame()
if not new_frame_to_draw:
raise "should be a frame here"
self.image, self.rect = self.images[new_frame_to_draw]
self.rect[0] = self.position[0]
self.rect[1] = self.position[1]
self.current_frame_name = new_frame_to_draw
def SetPosition(self, position):
self.position = position
self.rect[0] = position[0]
self.rect[1] = position[1]
#print self.rect
def MakeScaledVersion(self, key_name, size):
""" keyname - what the scaled version should be called.
eg ('really small', (0,0))
size - x,y tuple.
"""
self.modified_images[key_name] = {}
mi = self.modified_images[key_name]
for frame_name, image_rect in self.modified_images['originals'].items():
image = pygame.transform.scale(image_rect[0], size)
#TODO: probably need to change the size of the rect here.
r = (image_rect[1][0], image_rect[1][1], size[0], size[1])
new_rect = pygame.Rect(r)
mi[frame_name] = [image, new_rect]
def LoadImages(self, image_dict = {}):
""" image_dict - should be a dictionary which is keyed by the frame name,
and valued by an image for that frame. If the dict is {}
then the images are loaded from disk.
"""
if image_dict == {}:
for x in self.character_image_dict.keys():
self.images[x] = load_image(self.character_image_dict[x], -1, 1)
else:
self.images = image_dict
def LoadAnimationData(self):
"""
"""
#get_animations, get_layer_order = read_anim_data(self.animation_name)
animations, layer_order = read_anim_data(self.animation_set_name)
self.animations = animations
self.layer_order = layer_order
def move(self, direction):
self.position += direction
self.rect.move_ip(direction, 0)
#self.rect = self.rect.clamp(SCREENRECT)
def ResetImageRect(self):
""" After changing the self.images dict this should be called.
"""
self.image, self.rect = self.images[self.current_frame_name]
self.rect[0] = self.position[0]
self.rect[1] = self.position[1]
def SetLogicalImages(self, x_y):
""" Sets the appropriate images for the place on the logical grid.
"""
self.images = self.modified_images[("scaled", x_y)]
self.ResetImageRect()
def update(self, frame_name =None, percent_trans = None):
#def update(self ):
""" frame_name - this is the name of the frame to draw.
percent_trans - is the alpha value for which to draw
If frame_name, and percent_trans are None then they are worked out
for themselves.
"""
if frame_name != None and percent_trans != None:
pass
if self.anims[self.current_animation].StillGoing():
new_frame_to_draw = self.anims[self.current_animation].NewFrame()
if new_frame_to_draw:
self.current_frame_name = new_frame_to_draw
self.image, self.rect = self.images[new_frame_to_draw]
self.rect[0] = self.position[0]
self.rect[1] = self.position[1]
self.anims[self.current_animation].last_frame = new_frame_to_draw
else:
# old frame to be rendered.
pass
else:
# figure out what to do at end of anim.
pass
new_rdpyg/build/lib/urdpyg/sounds.py 0000644 0001751 0001751 00000012571 10075765413 020044 0 ustar rene rene 0000000 0000000 """
file: sounds.py
purpose: to load all the sounds, and manage the playing of them.
Probably have different sets of sounds in here somehow.
NOTE: not using pygames channel queueing as it only allows one sound to be
queued. Also the sound can only be queued on a certain channel.
"""
import pygame
import os
import glob
import time
from pygame.locals import *
SOUND_PATH = os.path.join("..", "data", "sounds")
def get_sound_list(path = SOUND_PATH):
""" gets a list of sound names without thier path, or extension.
"""
# load a list of sounds without path at the beginning and .ogg at the end.
sound_list = map(lambda x:x[len(path)+1:-4],
glob.glob(os.path.join(path,"*.ogg"))
)
return sound_list
SOUND_LIST = get_sound_list()
class SoundManager:
""" Controls loading, mixing, and playing the sounds.
Having seperate classes allows different groups of sounds to be
loaded, and unloaded from memory easily.
Useage:
sm = SoundManager()
sm.Load()
"""
def __init__(self, sound_list = SOUND_LIST, sound_path = SOUND_PATH):
"""
"""
self.mixer = None
self.music = None
self.sounds = {}
self.chans = {}
self._debug_level = 0
self.sound_list = sound_list
self.sound_path = sound_path
# sounds which are queued to play.
self.queued_sounds = []
def _debug(self, x, debug_level = 0):
"""
"""
if self._debug_level > debug_level:
print x
def Load(self, sound_list = [], sound_path = "."):
"""Loads sounds."""
sounds = self.sounds
if not pygame.mixer:
for name in sound_list:
sounds[name] = None
return
for name in sound_list:
if not sounds.has_key(name):
fullname = os.path.join(sound_path, name+'.ogg')
try:
sound = pygame.mixer.Sound(fullname)
except:
sound = None
self._debug("Error loading sound", fullname)
sounds[name] = sound
def GetSound(self, name):
""" Returns a Sound object for the given name.
"""
if not self.sounds.has_key(name):
self.Load([name])
return self.sounds[name]
def Stop(self, name):
if self.chans.has_key(name):
if self.chans[name]:
if self.chans[name].get_busy():
self.chans[name].stop()
def StopAll(self):
""" stops all sounds.
"""
for name in self.chans.keys():
self.Stop(name)
def Play(self, name,
volume=[1.0, 1.0],
wait = 0,
loop = 0):
""" Plays the sound with the given name.
name - of the sound.
volume - left and right. Ranges 0.0 - 1.0
wait - used to control what happens if sound is allready playing:
0 - will not wait if sound playing. play anyway.
1 - if there is a sound of this type playing wait for it.
2 - if there is a sound of this type playing do not play again.
loop - number of times to loop. -1 means forever.
"""
vol_l, vol_r = volume
sound = self.GetSound(name)
if sound:
if wait in [1,2]:
if self.chans.has_key(name) and self.chans[name].get_busy():
if wait == 1:
# sound is allready playing we wait for it to finish.
self.queued_sounds.append((name, volume, wait))
return
elif wait == 2:
# not going to play sound if playing.
return
self.chans[name] = sound.play(loop)
if not self.chans[name]:
if loop == 1:
# forces a channel to return. we fade that out,
# and enqueue our one.
self.chans[name] = pygame.mixer.find_channel(1)
#TODO: does this fadeout block?
self.chans[name].fadeout(100)
self.chans[name].queue(sound)
else:
# the pygame api doesn't allow you to queue a sound and
# tell it to loop. So we hope for the best, and queue
# the sound.
self.queued_sounds.append((name, volume, wait))
# delete the None channel here.
del self.chans[name]
elif self.chans[name]:
self.chans[name].set_volume(vol_l, vol_r)
def Update(self, elapsed_time):
"""
"""
for name in self.chans.keys():
if not self.chans[name]:
# it may be a NoneType I think.
del self.chans[name]
elif not self.chans[name].get_busy():
del self.chans[name]
old_queued = self.queued_sounds
self.queued_sounds = []
for snd_info in old_queued:
self.Play(*snd_info)
def PlayMusic(self, musicname):
""" Plays a music track. Only one can be played at a time.
So if there is one playing, it will be stopped and the new
one started.
"""
music = self.music
if not music: return
if music.get_busy():
#we really should fade out nicely and
#wait for the end music event, for now, CUT
music.stop()
fullname = os.path.join('sounds', musicname)
music.load(fullname)
music.play(-1)
music.set_volume(1.0)
new_rdpyg/docs/ 0000755 0001751 0001751 00000000000 10160167715 013716 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/ 0000755 0001751 0001751 00000000000 10160166530 015035 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/ 0000755 0001751 0001751 00000000000 10160167334 016165 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/app/ 0000755 0001751 0001751 00000000000 10160166530 016742 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/app/the_app/ 0000755 0001751 0001751 00000000000 10160166530 020362 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/app/the_app/TheApp.html 0000644 0001751 0001751 00000040175 10160167714 022445 0 ustar rene rene 0000000 0000000
Class: TheApp
Table of Contents
| Class: TheApp
|
rdpyg/app/the_app.py
|
|
An application class to handle lots of common things within games, and
game like applications, using pygame. A lot of the methods are meant to be overrided. However they all come
with sane default implementations.
Useage:
a = TheApp()
Start()
a.Loop()
a.Stop()
|
Methods
|
|
|
|
|
|
Display
|
Display ( self )
This is called before the display is flipped(or updated).
Your drawing code should go in here.
|
|
|
DoAfterFlip
|
DoAfterFlip ( self )
Called after flip is done.
|
|
|
DoBeforeDisplay
|
DoBeforeDisplay ( self )
Stuff done before Display() is called.
|
|
|
DoBeforeHandlingEvents
|
DoBeforeHandlingEvents ( self )
Stuff done before we handle the events.
Should return 0 to quit.
|
|
|
GetFps
|
GetFps ( self )
Returns the frames per second since the timing has begun.
|
|
|
HandleEvents
|
HandleEvents ( self, event_list )
should handle the events every game tic.
|
|
|
InitDisplay
|
InitDisplay (
self,
width,
height,
first_time=0,
)
A default InitDisplay.
first_time - useful for working around some buggy systems.
make it true if this is the first time calling it.
|
Exceptions
|
|
ValueError( "error initializing display, can not get mode" )
|
|
|
|
Load
|
Load ( self )
For loading stuff.
|
|
|
Loop
|
Loop ( self )
Starts the game looping. Will eventually return.
|
|
|
LoopInit
|
LoopInit ( self )
Should put use loop initialisation stuff here.
|
|
|
OneTic
|
OneTic ( self )
Does one game tic worth of stuff.
Should return 1 if not wanting to quit.
If wanting to quit return 0.
|
|
|
SetupTiming
|
SetupTiming ( self )
Sets up some timing code.
|
|
|
Start
|
Start ( self )
Do the game loading.
|
|
|
Stop
|
Stop ( self )
Called when we want to stop.
|
|
|
TicTiming
|
TicTiming ( self )
Call this once per tic to update the timing.
|
|
|
Update
|
Update ( self, elapsed_time )
update any game state.
|
|
|
__init__
|
__init__ ( self, debug_level=0 )
|
|
|
_debug
|
_debug (
self,
x,
debug_level=0,
)
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/app/the_app_gl/ 0000755 0001751 0001751 00000000000 10160166530 021044 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/app/the_app_gl/TheAppGL.html 0000644 0001751 0001751 00000016076 10160167714 023355 0 ustar rene rene 0000000 0000000
Class: TheAppGL
Table of Contents
| Class: TheAppGL
|
rdpyg/app/the_app_gl.py
|
|
Methods
|
|
Display
GetWorldCoords
InitDisplay
SetupProjection
Start
|
|
|
Display
|
Display ( self )
A default display. Which clears the color buffer and depth buffer.
|
|
|
GetWorldCoords
|
GetWorldCoords (
self,
x,
y,
camera_z,
)
returns (x,y,z) given x,y pygame screen coords.
NOTE: try and get the model view matrix back to the camera
position when using.
|
|
|
InitDisplay
|
InitDisplay (
self,
width,
height,
first_time=0,
)
A default InitDisplay.
|
Exceptions
|
|
ValueError( "error initializing display, can not get mode" )
|
|
|
|
SetupProjection
|
SetupProjection (
self,
width=640,
height=480,
zNear=5.,
zFar=300.,
)
Sets up the projection matrix for opengl.
|
|
|
Start
|
Start ( self )
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/app/__init__.html 0000644 0001751 0001751 00000002446 10160167714 021402 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
rdpyg/app/__init__.py
|
|
Common functionality for applications.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/app/index.html 0000644 0001751 0001751 00000004717 10160167714 020755 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: rdpyg.app
Table of Contents
| HappyDoc Generated Documentation: rdpyg.app
|
|
|
Common functionality for applications.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/app/the_app.html 0000644 0001751 0001751 00000011355 10160167714 021262 0 ustar rene rene 0000000 0000000
Module: the_app
Table of Contents
| Module: the_app
|
rdpyg/app/the_app.py
|
|
TheApp is a class for making a game like application, implementing
functionality common in many games. The idea is to make constructing games
and demos quick, with minimal code.
TODO: a way to chose between display flip and update. without overriding the
whole method.
There are a number of different methods with default implementations to save
work. Most of these can be overridden if you need to specialise any parts.
= How the main loop works. =
TheApp class has a couple of different ways which it handles the main loop internally. It can use a while loop or the twisted reactor.
However by using the methods provided you should not have to modify this.
It can be instructional to have at a look at the source for different methods, so that overriding them can be easy.
This is the 2d pygame version of the class. There is an opengl version named
rdpyg.app.the_app_gl.TheAppGL
= Commonly overridden methods =
Display
Your drawing code.
Update
Updating your game logic, game play, and game ai.
HandleEvents
Code to handle user input, operating system interaction, and other events.
Load
* Code to load your game data. Like images, sounds etc.
= Order of operation =
The order in which the different methods get called is to update your game
objects, handle user input, do your display changes.
Start()
InitDislpay()
Load()
Loop()
Before loops starts looping:
LoopInit()
SetupTiming()
Every tic or frame of loop:
Update()
HandleEvents()
DoBeforeDisplay()
Display()
DoAfterFlip()
|
Imported modules
|
|
import pygame
from pygame.locals import DOUBLEBUF, OPENGL, FULLSCREEN, QUIT, KEYDOWN, K_ESCAPE
import sys
import time
import traceback
|
|
Classes
|
|
TheApp |
An application class to handle lots of common things within games, and
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/app/the_app_gl.html 0000644 0001751 0001751 00000006114 10160167714 021741 0 ustar rene rene 0000000 0000000
Module: the_app_gl
Table of Contents
| Module: the_app_gl
|
rdpyg/app/the_app_gl.py
|
|
Imported modules
|
|
from OpenGL.GL import glMatrixMode, GL_PROJECTION, glLoadIdentity, glClearColor, glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, glGetFloatv, GL_PROJECTION_MATRIX, GL_MODELVIEW, glViewport, glGetDoublev, GL_MODELVIEW_MATRIX
from OpenGL.GLU import gluPerspective, gluUnProject
import pygame
from pygame.locals import DOUBLEBUF, OPENGL, FULLSCREEN, QUIT, KEYDOWN, K_ESCAPE
import the_app
|
|
Classes
|
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/ 0000755 0001751 0001751 00000000000 10160166530 017117 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/draw/pygame/ 0000755 0001751 0001751 00000000000 10160166530 020401 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/draw/pygame/__init__.html 0000644 0001751 0001751 00000002405 10160167714 023034 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
rdpyg/draw/pygame/__init__.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/pygame/index.html 0000644 0001751 0001751 00000004111 10160167714 022400 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: rdpyg.draw.pygame
Table of Contents
| HappyDoc Generated Documentation: rdpyg.draw.pygame
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/pyopengl/ 0000755 0001751 0001751 00000000000 10160166530 020754 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/draw/pyopengl/particles/ 0000755 0001751 0001751 00000000000 10160166530 022742 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/draw/pyopengl/particles/cached_random.html 0000644 0001751 0001751 00000007707 10160167714 026417 0 ustar rene rene 0000000 0000000
Class: cached_random
Table of Contents
| Class: cached_random
|
rdpyg/draw/pyopengl/particles.py
|
|
def __init__(self, size_of_cache = 500):
self.size_of_cache = size_of_cache
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/pyopengl/particles/Particle.html 0000644 0001751 0001751 00000004764 10160167714 025413 0 ustar rene rene 0000000 0000000
Class: Particle
Table of Contents
| Class: Particle
|
rdpyg/draw/pyopengl/particles.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/pyopengl/particles/Particles.html 0000644 0001751 0001751 00000022032 10160167714 025562 0 ustar rene rene 0000000 0000000
Class: Particles
Table of Contents
| Class: Particles
|
rdpyg/draw/pyopengl/particles.py
|
|
This is a set of particles baby.
|
Methods
|
|
|
|
|
|
Display
|
Display ( self )
A default display. Which clears the color buffer and depth buffer.
|
|
|
DisplayStateBegin
|
DisplayStateBegin ( self )
|
|
|
DisplayStateEnd
|
DisplayStateEnd ( self )
|
|
|
InitParticles
|
InitParticles ( self )
|
|
|
Load
|
Load (
self,
with_tex=None,
file_name=None,
)
with_tex can be an opengl texture.
|
|
|
LoadImagePng
|
LoadImagePng ( self, filename )
|
|
|
MakeTexture
|
MakeTexture ( self )
return
|
|
|
Update
|
Update ( self, elapsed_time )
TODO:
|
|
|
__init__
|
__init__ ( self, num_particles )
|
|
|
_debug
|
_debug (
self,
s,
x,
)
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/pyopengl/__init__.html 0000644 0001751 0001751 00000002407 10160167714 023411 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
rdpyg/draw/pyopengl/__init__.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/pyopengl/index.html 0000644 0001751 0001751 00000004503 10160167714 022760 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: rdpyg.draw.pyopengl
Table of Contents
| HappyDoc Generated Documentation: rdpyg.draw.pyopengl
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/pyopengl/particles.html 0000644 0001751 0001751 00000006615 10160167714 023645 0 ustar rene rene 0000000 0000000
Module: particles
Table of Contents
| Module: particles
|
rdpyg/draw/pyopengl/particles.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/pyopengl/paths.html 0000644 0001751 0001751 00000010236 10160167714 022770 0 ustar rene rene 0000000 0000000
Module: paths
Table of Contents
| Module: paths
|
rdpyg/draw/pyopengl/paths.py
|
|
Imported modules
|
|
from OpenGL.GL import glBegin, GL_LINES, glVertex3f, glEnd, glPushAttrib, GL_ALL_ATTRIB_BITS, glMatrixMode, GL_MODELVIEW, glLoadIdentity, glScale, glTranslatef, glPopAttrib
from OpenGL.GLUT import glutSolidTeapot
|
|
Functions
|
|
draw_path
draw_path_with_traveler
|
|
|
draw_path
|
draw_path ( a_path )
draws a path with opengl lines.
|
|
|
draw_path_with_traveler
|
draw_path_with_traveler ( a_path )
draws a box where the position of the traveler is on the path.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/__init__.html 0000644 0001751 0001751 00000002370 10160167714 021553 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
rdpyg/draw/__init__.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/draw/index.html 0000644 0001751 0001751 00000004652 10160167714 021130 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: rdpyg.draw
Table of Contents
| HappyDoc Generated Documentation: rdpyg.draw
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/ifconfig_networking/ 0000755 0001751 0001751 00000000000 10160166531 022216 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/ifconfig_networking/IfConfigFreeBSD.html 0000644 0001751 0001751 00000007543 10160167034 025733 0 ustar rene rene 0000000 0000000
Class: IfConfigFreeBSD
Table of Contents
| Class: IfConfigFreeBSD
|
rdpyg/net/ifconfig_networking.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:08:26 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/ifconfig_networking/IfConfigLinux.html 0000644 0001751 0001751 00000007557 10160167034 025625 0 ustar rene rene 0000000 0000000
Class: IfConfigLinux
Table of Contents
| Class: IfConfigLinux
|
rdpyg/net/ifconfig_networking.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:08:26 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/ifconfig_networking/IfConfigWindows.html 0000644 0001751 0001751 00000012473 10160167034 026151 0 ustar rene rene 0000000 0000000
Class: IfConfigWindows
Table of Contents
| Class: IfConfigWindows
|
rdpyg/net/ifconfig_networking.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:08:26 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/map/ 0000755 0001751 0001751 00000000000 10160166530 016737 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/map/__init__.html 0000644 0001751 0001751 00000002367 10160167334 021377 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
rdpyg/map/__init__.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:11:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/map/index.html 0000644 0001751 0001751 00000004273 10160167334 020745 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: rdpyg.map
Table of Contents
| HappyDoc Generated Documentation: rdpyg.map
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:11:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/map/map.html 0000644 0001751 0001751 00000016057 10160167334 020416 0 ustar rene rene 0000000 0000000
Module: map
Table of Contents
| Module: map
|
rdpyg/map/map.py
|
|
= Features wanted =
When not moving it can take only update parts of the screen.
update(dirty_rects) can be used to speed up drawing.
by only updating areas which are dirty.
if the map is not moving we can make it lots speedier.
Offscreen buffer. Blit all smaller tiles to an offscreen buffer then blit
one big image to the screen. This can be faster on some screens/computers.
Different tile sizes.
different sizes on the same map.
Join maps together easily.
Different drawable sizes. Ie different camera views.
Be able to be used with pygame or pyopengl.
Different camera modes:
jump scrolling,
jump the map in blocks. Like ten pixels at a time.
smooth scrolling,
every pixel the camera moves the tiles move.
smooth-jump scrolling.
Mostly the screen stays still. When the character nears the edge
everything stops moving while the maps scrolls over a little way.
centered camera.
Can center the camera on
Looping Map Edges
Paralax scrolling.
Moving layers at different speeds.
Multiple views of the map.
* miniview of the map. Perhaps using a scaled version or one pixel per tile.
minimize overdraw.
using dirty rectangles.
for alpha images precalculate full rects.
That is like a bounding box in the middle where the area is full.
think about using a coverage buffer.
* animated tiles will probably always need to be redrawn(unless it's the same frame).
Overlapping tiles.
As well as overlapping whole maps. For joining maps together.
Layers/Z ordering.
draw characters by descending y value on same layer.
for certain types of games: see for explanation:
* http://www.gamedev.net/reference/programming/features/gpgenesis9/page7.asp
line of sight tests between tiles and pixels/rects.
collision detection between tiles and pixels/rects.
some tiles may be pass through.
* tiles on different layers may be collidable, others not.
fog of war.
* darkening/lightening of areas.
Rotatable tiles.
* scalable tiles? Other transforms needed?
Easy layer toggling.
* So eg when you go inside a building the roof comes off and you can see inside.
= Implementation ideas =
Use pygame sprites and sprite groups.
could then reuse lots of code... optimize in one place. Speed development.
think of camera movement as simply moving a sprite group in a certain way.
Use a quad tree for the collision detection.
* Could use it for moving, and non moving.
Left to right, or top to bottom scrollers can be optimized in different ways.
= Some map editors =
The tile combie(or engine if you want) should have most of the features that these map editors contain.
http://tilestudio.sourceforge.net/
http://www.tilemap.co.uk/
= A discussion about features =
<geoffh> background tiling, layers, collision detection between layers and stuff (rect and pixel)
<geoffh> paralax scrolling
<geoffh> animation of background/sprites
<geoffh> line of sight tests between tiles and pixels
<geoffh> based on layer compositions and such
<illumeh> eek, that's a lot of stuff
<illumeh> good stuff :)
<geoffh> separate environmental and UI layer systems
<illumeh> what do you mean?
<geoffh> so you can draw your UI without worrying how height your environments layers are
<geoffh> the UI layers are alwayrs on top
<illumeh> ah, cool
<geoffh> basically, just 2 lists for heights
<geoffh> auto-shadowing for sprites is good
<illumeh> indeed, that'd be cool
<geoffh> doing like angled skews on the images, and drawing them on the ground layer
<geoffh> so you dont have to have separate shadow images for them
<illumeh> nice
<geoffh> or just auto positioning the same image, but based on heigth of the sprite
<geoffh> so like a flying ship has its shadow in the real place, and its in its height-adjusted place, like zaxxon
<geoffh> which basically just means you have a transformation for height built in, and use a sort of worrld coords and translated drawing coords
<illumeh> aah
<geoffh> which makes sense
<geoffh> so you should have parameters to what your viewing perspective is, so they can adjust it based on how their art is rendered
<geoffh> like: 1.5:1.0 or something
<geoffh> you could also have layer toggling like i did in VT, where if you go into a building, it switches what the background tiles are. and if you change floors, it also does that
<illumeh> ah, that sounds nice too
<geoffh> but that may be a bit specific. though, you could make the design so its possible to rotate through BG tile maps specifically, like theyre layered and do a fall through if the current selected one doesnt exist
<geoffh> to the default background map, which has all its spaces mapped
<geoffh> sorta an "optional current level background"
<geoffh> good for things where people take stairs, and you still want the ground of things outside buildings and such
<geoffh> im running out of stuff ive thought about for tiling engines
<illumeh> hehe. that's all stuff I didn't think about :)
<geoffh> i want to retire
<geoffh> im pretty happy doing fuck all all the time now
<geoffh> heh
<illumeh> having layers greyed out would be good
<illumeh> hehe. mostly I'm happy doing fuck all too :)
<geoffh> optional layers? or you mean something else?
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:11:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/net/ 0000755 0001751 0001751 00000000000 10160167334 016753 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/net/ifconfig_networking/ 0000755 0001751 0001751 00000000000 10160167334 023006 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/net/ifconfig_networking/IfConfigFreeBSD.html 0000644 0001751 0001751 00000007551 10160167714 026525 0 ustar rene rene 0000000 0000000
Class: IfConfigFreeBSD
Table of Contents
| Class: IfConfigFreeBSD
|
rdpyg/net/ifconfig_networking.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/net/ifconfig_networking/IfConfigLinux.html 0000644 0001751 0001751 00000007565 10160167714 026417 0 ustar rene rene 0000000 0000000
Class: IfConfigLinux
Table of Contents
| Class: IfConfigLinux
|
rdpyg/net/ifconfig_networking.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/net/ifconfig_networking/IfConfigWindows.html 0000644 0001751 0001751 00000012501 10160167714 026734 0 ustar rene rene 0000000 0000000
Class: IfConfigWindows
Table of Contents
| Class: IfConfigWindows
|
rdpyg/net/ifconfig_networking.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/net/ifconfig_networking.html 0000644 0001751 0001751 00000011034 10160167714 023675 0 ustar rene rene 0000000 0000000
Module: ifconfig_networking
Table of Contents
| Module: ifconfig_networking
|
rdpyg/net/ifconfig_networking.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/net/__init__.html 0000644 0001751 0001751 00000002431 10160167714 021402 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
rdpyg/net/__init__.py
|
|
networking related stuff.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/net/index.html 0000644 0001751 0001751 00000004403 10160167714 020753 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: rdpyg.net
Table of Contents
| HappyDoc Generated Documentation: rdpyg.net
|
|
|
networking related stuff.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/sprites/ 0000755 0001751 0001751 00000000000 10160166530 017653 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/sprites/spritegl/ 0000755 0001751 0001751 00000000000 10160166530 021504 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/sprites/spritegl/ScreenGL.html 0000644 0001751 0001751 00000017234 10160167715 024051 0 ustar rene rene 0000000 0000000
Class: ScreenGL
Table of Contents
| Class: ScreenGL
|
rdpyg/sprites/spritegl.py
|
|
TODO:
- Fill in missing functions.
- Work correctly when screen size changes.
- only update the texture when blitting.
- An optimization might be to not update the texture until the
screen has been flipped, or updated.
- This could work quite nicely with RenderUpdates :)
|
Methods
|
|
__init__
blit
fill
get_clip
get_flags
get_rect
get_size
set_clip
|
|
|
__init__
|
__init__ ( self, screen )
|
|
|
blit
|
blit ( self, *args )
meant as a replacement for screen.blit
You really should consider making your background a seperate Sprite,
and Group.
useage:
gl_screen_blit
|
|
|
fill
|
fill ( self, *args )
|
|
|
get_clip
|
get_clip ( self, *args )
|
|
|
get_flags
|
get_flags ( self, *args )
|
|
|
get_rect
|
get_rect ( self, *args )
|
|
|
get_size
|
get_size ( self, *args )
|
|
|
set_clip
|
set_clip ( self, *args )
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/sprites/spritegl/GroupGL.html 0000644 0001751 0001751 00000021003 10160167714 023712 0 ustar rene rene 0000000 0000000
Class: GroupGL
Table of Contents
| Class: GroupGL
|
rdpyg/sprites/spritegl.py
|
|
Methods
|
|
FitSpritesOnTextures
MakeTextures
draw
draw_gl
load_2d_projection
set_up_2d_projection
setup_draw_texture
un_setup_draw_texture
|
|
|
FitSpritesOnTextures
|
FitSpritesOnTextures ( self )
|
|
|
MakeTextures
|
MakeTextures ( self )
For all of the sprites in this group we will make textures for
them.
|
|
|
draw
|
draw ( self, surface )
supposed to draw to the given surface.
Problem is it is an opengl screen.
so we get the size of it, and draw to the screen.
|
|
|
draw_gl
|
draw_gl ( self, spr )
Assumes glMatrixMode( GL_MODELVIEW )
|
|
|
load_2d_projection
|
load_2d_projection ( self )
|
|
|
set_up_2d_projection
|
set_up_2d_projection ( self, a_rect )
a_rect - the area to set up the projection for.
|
|
|
setup_draw_texture
|
setup_draw_texture ( self, screen_rect )
Sets up opengl for drawing the textures.
|
|
|
un_setup_draw_texture
|
un_setup_draw_texture ( self )
resets the opengl state to what it was before drawing.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/sprites/spritegl/SpriteGL.html 0000644 0001751 0001751 00000015165 10160167715 024101 0 ustar rene rene 0000000 0000000
Class: SpriteGL
Table of Contents
| Class: SpriteGL
|
rdpyg/sprites/spritegl.py
|
|
A sprite class which uses opengl.
Should be able to use it in the place of the pygame sprite class.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/sprites/spritegl/SurfaceGL.html 0000644 0001751 0001751 00000015242 10160167715 024217 0 ustar rene rene 0000000 0000000
Class: SurfaceGL
Table of Contents
| Class: SurfaceGL
|
rdpyg/sprites/spritegl.py
|
|
This is useful for tracking changes in a surface.
It takes a surface as a keyword initializer:
eg s = SurfaceGL(initialize_with_this = a_surf)
Or you can initialize it like a normal surface. Once the pixel data is changed, either is_dirty will be true,
or changed_rects will not be empty.
If is_dirty is true:
then the whole image needs to be updated.
Else:
if changed_rects is not empty:
update the rects which have been changed.
class SurfaceGL(pygame.old_Surface):
|
Methods
|
|
__getattr__
__init__
__setattr__
blit
fill
|
|
|
__getattr__
|
__getattr__ ( self, name )
|
|
|
__init__
|
__init__ (
self,
*args,
*kwargs,
)
|
|
|
__setattr__
|
__setattr__ (
self,
name,
value,
)
|
|
|
blit
|
blit ( self, *args )
TODO: needs to keep track of which parts have been changed.
For now marking the whole image as dirty.
|
|
|
fill
|
fill ( self, *args )
like a normal surface fill, but marks the thing as dirty.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/sprites/__init__.html 0000644 0001751 0001751 00000002373 10160167714 022312 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
rdpyg/sprites/__init__.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/sprites/index.html 0000644 0001751 0001751 00000004415 10160167715 021662 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: rdpyg.sprites
Table of Contents
| HappyDoc Generated Documentation: rdpyg.sprites
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/sprites/spritegl.html 0000644 0001751 0001751 00000027635 10160167715 022415 0 ustar rene rene 0000000 0000000
Module: spritegl
Table of Contents
| Module: spritegl
|
rdpyg/sprites/spritegl.py
|
|
Opengl drawing of pygame.sprite objects. With hopefully minimal/no changes
to programs, and big speed increases.
Rene Dudfield.
illumen@yahoo.com
TODO:
First compatibilty, optimization, then next gen.
NOTE: there are some more TODO's sprinkled througout the code
Compatibilty.
- need to implement all of screens methods.
test on more games.
- chimp(works).
pyddr(doesn't work).
- I think it has to do with the different format images.
- I think a conversion may not be working properly.
bleten(works).
- works, but is kinda slow when lots of images change.
- need to work on a scaling method which uses opengl.
- need to not use tostring() for making textures(slow).
- work on caching some more, so that there is a texture cache as well.
- so that images don't need to be uploaded to the card all the time.
yass(don't know).
a better way to detect when an images contents have changed.
- probably a wrapper around surface, and surfarray which marks the image as dirty.
- split sprites larger than 256x256 into multiple smaller textures.
- for some older 3d cards.
- should figure out how to detect max texture size.
support 8 and 16 bit and color keyed textures.
- Make sure textures are cleaned up correctly in all cases.
- Beta test on a wide number of machines.
Make it work correctly when the screen size changes.
Optimization.
Put multiple sprites onto the same texture,
and use uv coords for drawing particular sprites. This is a big optimization.
- especially for animation.
move all texture management into the group, so as to optimize texture drawing more
easily.
Have a set max number of textures to use in a texture cache.
- Cache textures
optimize the screen.blit function, and some others:
- with blit, only update a certain part of the texture which was actually blitted.
- screen.fill
Group drawing by the same texture(less texture binds).
- Try display lists to see if better performing.
- try vertex buffers for better performance.
- Make 1000+ sprite test case, and optimize for this case.
- Update texture instead of replacing it when:
- some pixels change in an image.
- when the image changes and the old one isn't to be used anymore.
- How to know this?
Next gen.
- Add scaling, rotation, other effects to a sprite class.
- use caching of images for sdl, and straight opengl calls(eg glRotate etc).
- shadows from sprites onto the background.
- Make classes/optimize existing classes for drawing:
- scrollers, tile maps, height maps,
- 3d animated characters (http://www.py3d.org/py3d_zwiki/milkshape3d_animation)
- doomIII clone ;)
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/ 0000755 0001751 0001751 00000000000 10160166531 017140 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/util/cyclic_list/ 0000755 0001751 0001751 00000000000 10160166530 021440 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/util/cyclic_list/cyclic_list.html 0000644 0001751 0001751 00000013760 10160167715 024644 0 ustar rene rene 0000000 0000000
Class: cyclic_list
Table of Contents
| Class: cyclic_list
|
rdpyg/util/cyclic_list.py
|
|
Methods
|
|
__init__
cur
next
prev
set_cur
|
|
|
__init__
|
__init__ (
self,
*args,
*kwargs,
)
|
|
|
cur
|
cur ( self )
returns the element at the current cursor.
|
|
|
next
|
next ( self )
increments the cursor, and returns the new current idx.
|
|
|
prev
|
prev ( self )
decrements the cursor, and returns the new current idx.
|
|
|
set_cur
|
set_cur ( self, idx )
Sets the current cursor to the given idx.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/pack_textures/ 0000755 0001751 0001751 00000000000 10160166531 022021 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/util/pack_textures/Texture.html 0000644 0001751 0001751 00000023512 10160167715 024357 0 ustar rene rene 0000000 0000000
Class: Texture
Table of Contents
| Class: Texture
|
rdpyg/util/pack_textures.py
|
One texture which holds multiple smaller ones packed in.
x,y bottom left is 0,0. Which is like opengl, and not like sdl.
|
Methods
|
|
|
|
|
|
__init__
|
__init__ (
self,
x,
y,
height,
width,
)
|
|
|
__repr__
|
__repr__ ( self )
|
|
|
_bottom_left_first
|
_bottom_left_first ( self, o )
do a search from bottom left.
Return True if successful, else false.
o - other texture.
|
|
|
_brute_force
|
_brute_force ( self, o )
do a brute force search from bottom left to top right.
Return True if successful, else false.
o - other texture.
|
|
|
clear
|
clear ( self )
clears all the textures in this one.
|
|
|
collide
|
collide ( self, other_texture )
checks this texture only to see if it collides.
Returns True if it does collide.
|
|
|
could_fit
|
could_fit ( self, other_texture )
checks this texture only to see if it fits.
Does not care about any textures inside.
|
|
|
search_for_fit
|
search_for_fit ( self, o )
do a search for a place to put the texture, and place it.
Return True if successful, else false.
o - other texture.
|
|
|
try_fit
|
try_fit ( self, other_texture )
Tries to fit the texture into itself. Returns true if successful.
|
|
|
try_fit_batch
|
try_fit_batch ( self, other_textures )
Tries to fit the textures into itself.
Returns true if successful???. Or returns the unfitted ones?
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/paths/ 0000755 0001751 0001751 00000000000 10160166531 020257 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/util/paths/Path.html 0000644 0001751 0001751 00000036466 10160167715 022065 0 ustar rene rene 0000000 0000000
Class: Path
Table of Contents
| Class: Path
|
rdpyg/util/paths.py
|
|
Used for storing the path from one point to another.
For working out where an object following that path at a certain
speed would be. p = Path()
p.SetPoints([[0., 0., 0.],
[0., 1., 0.],
[1., 1., 0.],
[2., 2., 0.],
[3., 3., 0.]])
This creates a path of straight lines.
Now whatever is traveling along the path can use:
point_along_path = p.Travel(speed=0.5, elapsed_time=5)
Which will travel along the path 0.5 * 5 units, and give you the point
where it is up to.
|
Methods
|
|
|
|
|
|
GetBackwardsPoint
|
GetBackwardsPoint ( self, distance )
GetBackwardsPoint(distance) -> position
Returns a point backwards from the current direction along the path.
distance - backwards along the path.
|
|
|
GetHeadingToPoint
|
GetHeadingToPoint ( self )
GetHeadingToPoint() -> position
Returns the point which the traveler is heading to.
|
|
|
GotoNextLine
|
GotoNextLine ( self )
GotoNextLine() -> None
Starts heading to the next line in path.
|
|
|
SetLoopType
|
SetLoopType ( self, loop_type )
SetLoopType("stop") -> None
Can be set to one of LOOP_TYPES, ["stop", "loop", "backwards"]
|
|
|
SetNewPoint
|
SetNewPoint ( self, point )
SetNewPoint([x,y,z]) -> None
Sets the current point that the traveller is on.
|
|
|
SetPoints
|
SetPoints ( self, point_list )
SetPoints(point_list) -> None
Sets the points along the path.
point_list - eg [[1., 1., 1.], [2., 2., 2.]] With each sublist
being a point (x,y,z) in 3d space.
|
|
|
ShouldStop
|
ShouldStop ( self )
ShouldStop() -> Bool
Are we at the end and is the loop_type "stop"
|
|
|
Travel
|
Travel (
self,
speed,
elapsed_time,
)
Travel(float, float) -> position
Returns the point along the path that the traveler is at.
speed - units per second. Average since the last call to this.
elapsed_time - since the last call to this.
|
Exceptions
|
|
RuntimeError( "too many iterations trying to find new place on path" )
|
|
|
|
Where
|
Where ( self )
Where() -> position.
Returns the current position of the traveler.
|
|
|
__eq__
|
__eq__ ( self, other )
print self.points == other.points
print self.elapsed_time == other.elapsed_time
print self.loop_type == other.loop_type
print self.current_point == other.current_point
print self.current_heading_to_idx == other.current_heading_to_idx
print self.current_idx == other.current_idx
|
|
|
__init__
|
__init__ (
self,
points=[],
loop_type="stop",
)
points - defaults to []. should be like [[0.,0.,0.],[0.,1.,0.]]
|
|
|
__ne__
|
__ne__ ( self, other )
|
|
|
__str__
|
__str__ ( self )
|
|
|
length
|
length ( self )
length() -> length of the path.
TODO: why isn't this __len__() ?
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/quaternion/ 0000755 0001751 0001751 00000000000 10160166531 021325 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/util/quaternion/Quaternion.html 0000644 0001751 0001751 00000024352 10160167715 024353 0 ustar rene rene 0000000 0000000
Class: Quaternion
Table of Contents
| Class: Quaternion
|
rdpyg/util/quaternion.py
|
|
Quaternion object implementing those methods required
to be useful for OpenGL rendering (and not many others)
|
Methods
|
|
|
|
|
|
AXYZ
|
AXYZ ( self )
returns the angle, and x,y,z as a vector. as used by glRotate.
|
|
|
XYZR
|
XYZR ( self )
Get a VRML-style axis plus rotation form of the rotation.
Note that this is in radians, not degrees, and that the angle
is the last, not the first item... (x,y,z,radians)
|
|
|
__getitem__
|
__getitem__ ( self, x )
|
|
|
__init__
|
__init__ ( self, elements=[ 1, 0, 0, 0 ] )
The initializer is a four-element array,
- w, x,y,z
- all elements should be doubles/floats
the default values are those for a unit multiplication
quaternion.
|
|
|
__len__
|
__len__ ( self )
|
|
|
__mul__
|
__mul__ ( self, other )
Multiply this quaternion by another quaternion,
generating a new quaternion which is the combination of the
rotations represented by the two source quaternions. Other is interpreted as taking place within the coordinate
space defined by this quaternion.
Alternately, if "other" is a matrix, return the dot-product
of that matrix with our matrix (i.e. rotate the coordinate)
|
|
|
__neg__
|
__neg__ ( self )
|
|
|
__repr__
|
__repr__ ( self )
Return a human-friendly representation of the quaternion
Currently this representation is as an axis plus rotation (in radians)
|
|
|
delta
|
delta ( self, other )
Return the angle in radians between this quaternion and another.
Return value is a positive angle in the range 0-pi representing
the minimum angle between the two quaternion rotations.
From code by Halldor Fannar on the 3D game development algos list
|
|
|
matrix
|
matrix ( self )
Get a rotation matrix representing this rotation
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/vtimer/ 0000755 0001751 0001751 00000000000 10160166531 020446 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/rdpyg/rdpyg/util/vtimer/vtimer.html 0000644 0001751 0001751 00000024546 10160167715 022662 0 ustar rene rene 0000000 0000000
Class: vtimer
Table of Contents
| Class: vtimer
|
rdpyg/util/vtimer.py
|
times something. when it is done it is equal to 1, else equal to 0.
Useage:
v = VirtTimer(5.)
if v:
dosomething()
v.Update(elapsed_time) OR with a callback.
v = VirtTimer(5., dosomething)
v.Update(elapsed_time)
Call Update on each game tick. Passing in elapsed time in seconds
allows you to have timers running on different time. So pausing,
and things like bullet time are easy.
Also has some other features.
You can be notified on the "edge" of time. That is when a timer
is just_started or just_finished. if v.just_finished:
do_some_other_thing()
You can find how much time is left. As well as get a normalised
amount of time left(between 0. and 1.).
eg. time_before_powerup_runs_out = powerup_timer.left()
|
Methods
|
|
|
|
|
|
Update
|
Update ( self, elapsed_time )
Update(1.0) -> None
To be called on every game tic.
elapsed_time - since last update.
|
|
|
__eq__
|
__eq__ ( self, other )
|
|
|
__init__
|
__init__ (
self,
length,
callback=None,
)
length - of time to run for.
callback - optional callback function to call.
|
|
|
__ne__
|
__ne__ ( self, other )
|
|
|
__nonzero__
|
__nonzero__ ( self )
|
|
|
left
|
left ( self )
left() -> time left until finished.
|
|
|
left_normalised
|
left_normalised ( self )
left_normalised() -> the time left normalized to 0. - 1.
|
|
|
not_used
|
not_used ( self )
not_used -> None
For if the timer is not being used. This is useful for one time,
timers.
|
|
|
reset
|
reset ( self )
reset() -> None
Resets the timer to the beginning.
|
|
|
set_finished_no_callback
|
set_finished_no_callback ( self )
set_finished_no_callback() -> None
Sets it to finished, without calling callback. not just finished.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/pack_textures.html 0000644 0001751 0001751 00000015611 10160167715 022720 0 ustar rene rene 0000000 0000000
Module: pack_textures
Table of Contents
| Module: pack_textures
|
rdpyg/util/pack_textures.py
|
|
TODO: need to return UV coordinates and pixel coordinates for the
packing/cutting functions for where the images are located on the textures.
Code to pack multiple textures into larger ones.
As well as to cut up bigger textures into smaller ones.
This is useful for eg opengl where there are textures size limits. Also
it can speed up rendering as you need to do less texture binding calls,
and you can reduce geometry calls too.
Power of 2 textures can be a waste of memory if you have non power of
2 sized images. The more video memory saved the faster a game can go.
To make this code more useful it will work with rectangles. So that it can
be used to update texture memory as well as to update images.
There will also need to be possibly multiple big output textures. So that
you can specify a maximum size output texture.
|
Functions
|
|
pack_images_into_multiple
split_big_image
|
|
|
pack_images_into_multiple
|
pack_images_into_multiple (
small_list,
max_size,
use_pow2=1,
)
returns a list of Texture objects with the textures from the small_list
packed into them.
small_list - list of Texture objects
max_size - of the output Textures.
use_pow2 - if 0 then we do not have to limit ourselves to power of 2.
|
|
|
split_big_image
|
split_big_image (
big_image,
max_size,
use_pow2=1,
)
returns a list of Textures which the big_image is split into.
big_image - a Texture object. TODO: how to determine where the small bits are placed?
|
|
Classes
|
|
Texture |
One texture which holds multiple smaller ones packed in.
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/__init__.html 0000644 0001751 0001751 00000002370 10160167715 021574 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
rdpyg/util/__init__.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/cyclic_list.html 0000644 0001751 0001751 00000005317 10160167715 022342 0 ustar rene rene 0000000 0000000
Module: cyclic_list
Table of Contents
| Module: cyclic_list
|
rdpyg/util/cyclic_list.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/index.html 0000644 0001751 0001751 00000005503 10160167715 021145 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: rdpyg.util
Table of Contents
| HappyDoc Generated Documentation: rdpyg.util
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/quaternion.html 0000644 0001751 0001751 00000043014 10160167715 022222 0 ustar rene rene 0000000 0000000
Module: quaternion
Table of Contents
| Module: quaternion
|
rdpyg/util/quaternion.py
|
|
Simple module providing a quaternion class for manipulating rotations easily.
NOTE: unittest in quaternion_test.py
NOTE: a lot of this code is taken from various places, including OpenglContext.
Note: all angles are assumed to be specified in radians.
Note: this is an entirely separate implementation from the PyOpenGL
quaternion class. This implementation assumes that Numeric python
will be available, and provides only those methods and helpers
commonly needed for manipulating rotations.
TODO:
Make all functions use an array instead of a quat class.
Make a quat class which uses the functions.
Make a c version of for the python functions.
- based off amd lib, gamasutra article, and CS quats.
|
Imported modules
|
|
import Matrix
import Numeric
import math
|
|
Functions
|
|
|
|
|
|
angle_to_radians
|
angle_to_radians ( angle )
|
|
|
euler_to_quats
|
euler_to_quats ( rotations )
Returns a sequence of quats.
It is an array where each quat is four floats.
w,x,y,z is the order.
rotations- an array of rotations.
where each rotation is three floats.
|
|
|
fromAXYZ
|
fromAXYZ (
a,
x,
y,
z,
)
|
|
|
fromEuler
|
fromEuler (
x=0,
y=0,
z=0,
)
Create a new quaternion from a 3-element euler-angle
rotation about x, then y, then z
|
|
|
fromEuler_angle
|
fromEuler_angle (
x=0,
y=0,
z=0,
)
From x,y,z angles in degrees create a quat.
|
|
|
fromMatrix
|
fromMatrix ( matrix )
from a 4x4 matrix return a quaternion.
These are the orders of the matrix:
[00,01,02,03]
[10,11,12,13]
[20,21,22,23]
[30,31,32,33] [0 , 1, 2, 3]
[4 , 5, 6, 7]
[8 , 9,10,11]
[12,13,14,15]
Which is the opengl order.
|
|
|
fromXYZR
|
fromXYZR (
x,
y,
z,
r,
)
Create a new quaternion from a VRML-style rotation
x,y,z are the axis of rotation
r is the rotation in radians.
|
|
|
from_euler_list
|
from_euler_list ( l )
|
|
|
get_angles_from_two_points
|
get_angles_from_two_points ( a, b )
returns the angles along the x,y,z axis. this is direction of the
two points.
|
Exceptions
|
|
ValueError("shouldn't get here x:%s: y :%s: " %( x, y ) )
|
|
|
|
length_quat
|
length_quat ( quat )
|
|
|
magnitude_vectors
|
magnitude_vectors ( vectors )
Calculate the magnitudes of the given vectors
- vectors
- sequence object with 1 or more
3-item vector values.
returns a double array with x elements,
where x is the number of 3-element vectors
|
|
|
normalise_vector
|
normalise_vector ( vector )
Given a 3 or 4-item vector, return a 3-item unit vector
|
|
|
normalise_vectors
|
normalise_vectors ( vectors )
Get normalised versions of the vectors.
- vectors
- sequence object with 1 or more
3-item vector values.
returns a double array with x 3-element vectors,
where x is the number of 3-element vectors in "vectors"
Will raise ZeroDivisionError if there are 0-magnitude
vectors in the set.
|
|
|
radians_to_angle
|
radians_to_angle ( radians )
|
|
|
slerp_quat
|
slerp_quat (
quat_a,
quat_b,
slerp,
)
Returns a quaternion spherically interpolated between quat_a, quat_b.
quat_a, quat_b - quaternions to interpolate between.
slerp - interp factor (0.0 = quat_a, 1.0 = quat_b)
|
|
Classes
|
|
Quaternion |
Quaternion object implementing those methods required
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/paths.html 0000644 0001751 0001751 00000030425 10160167715 021156 0 ustar rene rene 0000000 0000000
Module: paths
Table of Contents
| Module: paths
|
rdpyg/util/paths.py
|
|
Imported modules
|
|
import math
|
|
Functions
|
|
backwards
distance_between_points
forwards
forwards_from_next
interpolate_line
length_line
point_within
travel_line
within
|
|
|
backwards
|
backwards (
cur_point,
next_point,
distance,
)
backwards(point, point, num) -> point
Returns the point backwards along the given line.
|
|
|
distance_between_points
|
distance_between_points ( p1, p2 )
distance_between_points(point, point) -> num
Returns the distance between two points.
|
|
|
forwards
|
forwards (
cur_point,
next_point,
distance,
)
forwards(point, point, num) -> point
Returns the point forwards the distance along the given line.
From the current point!
|
|
|
forwards_from_next
|
forwards_from_next (
cur_point,
next_point,
distance,
)
forwards(point, point, num) -> point
Returns the point forwards the distance along the given line.
From the next point!
|
|
|
interpolate_line
|
interpolate_line (
start_point,
end_point,
t,
)
interpolate_line(point, point, num) -> point
returns the new point along the line given.
start_point - of the line.
end_point - of the line.
t - ratio between 0. - 1. along the line.
|
|
|
length_line
|
length_line ( points )
length([point]) -> num
returns the length of the line represented by the points.
|
|
|
point_within
|
point_within ( point, a_rect )
point_within([x,y], rectstyle) -> true if a point is within the rect.
|
|
|
travel_line
|
travel_line (
start_point,
end_point,
speed,
elapsed_time,
)
travel_lines(point, point, num, num) -> (time_left, new_point)
Travels along the line given at a given speed, for a given time.
|
|
|
within
|
within (
a,
b,
error_range,
)
within(num, num, num) -> bool
check if a is with error_range of b.
|
|
Classes
|
|
Path |
Used for storing the path from one point to another.
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/util/vtimer.html 0000644 0001751 0001751 00000004100 10160167715 021334 0 ustar rene rene 0000000 0000000
Module: vtimer
Table of Contents
| Module: vtimer
|
rdpyg/util/vtimer.py
|
|
Classes
|
|
vtimer |
times something. when it is done it is equal to 1, else equal to 0.
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/ifconfig_networking.html 0000644 0001751 0001751 00000011026 10160167034 023103 0 ustar rene rene 0000000 0000000
Module: ifconfig_networking
Table of Contents
| Module: ifconfig_networking
|
rdpyg/net/ifconfig_networking.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:08:26 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/__init__.html 0000644 0001751 0001751 00000002355 10160167715 020622 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
rdpyg/__init__.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/rdpyg/index.html 0000644 0001751 0001751 00000005566 10160167715 020201 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: rdpyg
Table of Contents
| HappyDoc Generated Documentation: rdpyg
|
|
|
Modules and Packages
|
|
rdpyg/
rdpyg | |
app |
Common functionality for applications.
|
draw |
HappyDoc Generated Documentation: rdpyg.draw
|
net |
networking related stuff.
|
sprites |
HappyDoc Generated Documentation: rdpyg.sprites
|
util |
HappyDoc Generated Documentation: rdpyg.util
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/rdpyg/index.html 0000644 0001751 0001751 00000004070 10160167715 017041 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation
Table of Contents
| HappyDoc Generated Documentation
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:39 2004 by
HappyDoc version
2.1
new_rdpyg/docs/tests/ 0000755 0001751 0001751 00000000000 10160166524 015055 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/tests/run_all_tests.py.html 0000644 0001751 0001751 00000004474 10160167712 021261 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
"""Regression testing framework
This module will search for scripts in the same directory named
test*.py. Each such script should be a test suite that tests a
module through PyUnit. (As of Python 2.1, PyUnit is included in
the standard library as "unittest".) This script will aggregate all
found test suites into one big test suite and run them all at once.
"""
import sys, os, re, unittest, glob
def regressionTest():
files = glob.glob("test*.py")
if not files:
os.chdir("tests")
files = glob.glob("test*.py")
filenameToModuleName = lambda f: os.path.splitext(f)[0]
moduleNames = map(filenameToModuleName, files)
modules = map(__import__, moduleNames)
load = unittest.defaultTestLoader.loadTestsFromModule
return unittest.TestSuite(map(load, modules))
if __name__ == "__main__":
unittest.main(defaultTest="regressionTest")
new_rdpyg/docs/tests/chimpgl.py.html 0000644 0001751 0001751 00000027206 10160167712 020024 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
"""
This simple example is used for the line-by-line tutorial
that comes with pygame. It is based on a 'popular' web banner.
Note there are comments here, but for the full explanation,
follow along in the tutorial.
"""
import os, pygame
from pygame.locals import *
if not pygame.font: print 'Warning, fonts disabled'
if not pygame.mixer: print 'Warning, sound disabled'
USE_GL = 1
if USE_GL:
from rdpyg.sprites.spritegl import SpriteGL, GroupGL, gl_display_get_surface, gl_display_set_mode
pygame.sprite.Sprite = SpriteGL
pygame.sprite.Group = GroupGL
pygame.sprite.RenderPlain = GroupGL
pygame.display.old_get_surface = pygame.display.get_surface
pygame.display.get_surface = gl_display_get_surface
pygame.display.old_set_mode = pygame.display.set_mode
pygame.display.set_mode = gl_display_set_mode
def load_image(name, colorkey=None):
fullname = os.path.join('data', name)
try:
image = pygame.image.load(fullname)
except pygame.error, message:
print 'Cannot load image:', fullname
raise SystemExit, message
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect()
def load_sound(name):
class NoneSound:
def play(self): pass
if not pygame.mixer or not pygame.mixer.get_init():
return NoneSound()
fullname = os.path.join('data', name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error, message:
print 'Cannot load sound:', fullname
return NoneSound()
raise SystemExit, message
return sound
class Fist(pygame.sprite.Sprite):
"""moves a clenched fist on the screen, following the mouse"""
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image, self.rect = load_image('fist.bmp', -1)
self.punching = 0
def update(self):
"move the fist based on the mouse position"
pos = pygame.mouse.get_pos()
self.rect.midtop = pos
if self.punching:
self.rect.move_ip(5, 10)
def punch(self, target):
"returns true if the fist collides with the target"
if not self.punching:
self.punching = 1
hitbox = self.rect.inflate(-5, -5)
return hitbox.colliderect(target.rect)
def unpunch(self):
"called to pull the fist back"
self.punching = 0
class Chimp(pygame.sprite.Sprite):
"""moves a monkey critter across the screen. it can spin the
monkey when it is punched."""
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image, self.rect = load_image('chimp.bmp', -1)
screen = pygame.display.get_surface()
self.area = screen.get_rect()
self.rect.topleft = 10, 10
self.move = 9
self.dizzy = 0
def update(self):
"walk or spin, depending on the monkeys state"
if self.dizzy:
self._spin()
else:
self._walk()
def _walk(self):
"move the monkey across the screen, and turn at the ends"
newpos = self.rect.move((self.move, 0))
if self.rect.left < self.area.left or \
self.rect.right > self.area.right:
self.move = -self.move
newpos = self.rect.move((self.move, 0))
self.image = pygame.transform.flip(self.image, 1, 0)
self.rect = newpos
def _spin(self):
"spin the monkey image"
center = self.rect.center
self.dizzy = self.dizzy + 12
if self.dizzy >= 360:
self.dizzy = 0
self.image = self.original
else:
rotate = pygame.transform.rotate
self.image = rotate(self.original, self.dizzy)
self.rect = self.image.get_rect()
self.rect.center = center
def punched(self):
"this will cause the monkey to start spinning"
if not self.dizzy:
self.dizzy = 1
self.original = self.image
def main():
"""this function is called when the program starts.
it initializes everything it needs, then runs in
a loop until the function returns."""
pygame.init()
screen = pygame.display.set_mode((468, 60))
pygame.display.set_caption('Monkey Fever')
pygame.mouse.set_visible(0)
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250, 250, 250))
if pygame.font:
font = pygame.font.Font(None, 36)
text = font.render("Pummel The Chimp, And Win $$$", 1, (10, 10, 10))
textpos = text.get_rect()
textpos.centerx = background.get_rect().centerx
background.blit(text, textpos)
screen.blit(background, (0, 0))
pygame.display.flip()
clock = pygame.time.Clock()
whiff_sound = load_sound('whiff.wav')
punch_sound = load_sound('punch.wav')
chimp = Chimp()
fist = Fist()
allsprites = pygame.sprite.RenderPlain((fist, chimp))
while 1:
clock.tick(60)
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN and event.key == K_ESCAPE:
return
elif event.type == MOUSEBUTTONDOWN:
if fist.punch(chimp):
punch_sound.play()
chimp.punched()
else:
whiff_sound.play()
elif event.type == MOUSEBUTTONUP:
fist.unpunch()
allsprites.update()
screen.blit(background, (0, 0))
allsprites.draw(screen)
pygame.display.flip()
print clock.get_fps()
if __name__ == '__main__': main()
new_rdpyg/docs/tests/test_milk_skeleton.py.html 0000644 0001751 0001751 00000015042 10160167712 022273 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
"""
Copyright (C) 2002 by Rene Dudfield.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
import unittest
from urdpyg import milk_skeleton
import os
class TestCaseBase(unittest.TestCase):
_debug_level = 1
def _debug(self, d, debug_level = 1):
if self._debug_level >= debug_level:
sys.stderr.write(":::%s:::\n" % d)
class Time2Keyframe_Map_test(TestCaseBase):
def test_no_loop(self):
""" Do the end conditions work when there is loop is set to false.
"""
def test_zero_seconds(self):
""" tests to see if the correct results are returned at zero seconds.
"""
t2kf = milk_skeleton.Time2Keyframe_Map()
t2kf.Update([4.0, 15.3, 16.2, 16.7, 16.9, 17.3, 130.0, 140.0, 150.9])
class BoneHeirachy_test(TestCaseBase):
def test_MilkBonesConversion(self):
""" test the conversion from milk_bone class into
BoneHeirarchy.
"""
model_path = os.path.join("data", "models", "bend.txt")
m = milk_skeleton.MilkshapeModelLoader(model_path)
should_be = {'': ['joint1'],
'joint1': ['joint2'],
'joint2': ['joint3'],
'joint3': ['joint4'],
'joint4': ['joint5'],
'joint5': ['joint6'],
'joint6': ['joint7']}
self.assertEqual(m.skeleton.bone_heirarchy.bone_parents_dict, should_be)
should_be = {'joint1': [''],
'joint2': ['joint1'],
'joint3': ['joint2'],
'joint4': ['joint3'],
'joint5': ['joint4'],
'joint6': ['joint5'],
'joint7': ['joint6']}
self.assertEqual(m.skeleton.bone_heirarchy.bone_children_dict,should_be)
def test_bone_name2bone_number_map(self):
model_path = os.path.join("data", "models", "bend.txt")
m = milk_skeleton.MilkshapeModelLoader(model_path)
should_be = {'joint5': 4,
'joint4': 3,
'joint7': 6,
'joint6': 5,
'joint1': 0,
'joint3': 2,
'joint2': 1}
self.assertEqual(m.skeleton.bone_name2bone_number_map, should_be)
if __name__ == "__main__":
unittest.main()
new_rdpyg/docs/tests/sounds_test.py.html 0000644 0001751 0001751 00000017244 10160167712 020754 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
"""
Tests out the features of the urdpyg.sounds module.
Try the keys: o i u y t
o: will play a sound and queue it if it's allready playing.
i: will play a sound and queue it if it's allready playing.
y: will play a sound if playing will play it anyway.
t: will play a sound if playing will not play it.
u: should fade out tracks.
"""
from OpenGL.GL import *
from OpenGL.GLU import *
from pygame.locals import *
import pygame
import time
from rdpyg.app import the_app_gl
pygame.init()
from urdpyg import sounds
import os
SOUND_PATH = os.path.join("data", "sounds")
SOUND_LIST = sounds.get_sound_list(SOUND_PATH)
class SoundsTestApp(the_app_gl.TheAppGL):
def __init__(self):
the_app_gl.TheAppGL.__init__(self)
def Load(self):
the_app_gl.TheAppGL.Load(self)
self.sound_manager = sounds.SoundManager(sound_list = SOUND_LIST, sound_path = SOUND_PATH)
self.sound_manager._debug_level = 1
self.sound_manager.Load(sound_list = SOUND_LIST, sound_path = SOUND_PATH)
def HandleEvents(self, event_list):
if the_app_gl.TheAppGL.HandleEvents(self, event_list) == 0:
return 0
for event in event_list:
if event.type == KEYDOWN and event.key == K_o:
self.sound_manager.Play("one_bump3", wait = 1)
if event.type == KEYDOWN and event.key == K_i:
self.sound_manager.Play("one_bump4", wait = 1)
if event.type == KEYDOWN and event.key == K_y:
self.sound_manager.Play("one_bump4")
if event.type == KEYDOWN and event.key == K_t:
self.sound_manager.Play("one_bump4", wait = 2)
if event.type == KEYDOWN and event.key == K_u:
self.sound_manager.Play("one_bump4")
self.sound_manager.Play("one_bump4")
self.sound_manager.Play("one_bump4")
self.sound_manager.Play("one_bump4")
self.sound_manager.Play("one_bump4")
self.sound_manager.Play("one_bump4")
self.sound_manager.Play("one_bump4")
self.sound_manager.Play("one_bump4")
self.sound_manager.Play("one_bump4")
self.sound_manager.Play("one_bump3")
self.sound_manager.Play("one_bump3")
self.sound_manager.Play("one_bump3")
self.sound_manager.Play("one_bump3")
if event.type == KEYDOWN and event.key == K_u:
self.sound_manager.Play("one_bump99999999")
return 1
def Update(self, elapsed_time):
the_app_gl.TheAppGL.Update(self, elapsed_time)
self.sound_manager.Update(elapsed_time)
def Display(self):
""" Basic display function just clears the screen.
"""
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
if __name__ == "__main__":
print "Try the keys: o i u y t"
print "o: will play a sound and queue it if it's allready playing."
print "i: will play a sound and queue it if it's allready playing."
print "y: will play a sound if playing will play it anyway."
print "t: will play a sound if playing will not play it."
print "u: should fade out tracks."
a = SoundsTestApp()
a.Start()
a.Loop()
new_rdpyg/docs/tests/visual_test_milkviewer4.py.html 0000644 0001751 0001751 00000006445 10160167712 023267 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
from OpenGL.GL import *
from OpenGL.GLU import *
from pygame.locals import *
import pygame
import time, os, sys
from rdpyg.app import the_app_gl
from urdpyg import milkviewer4
from numeric_gl import *
pygame.init()
class MilkViewerVisualTest(the_app_gl.TheAppGL):
def __init__(self):
the_app_gl.TheAppGL.__init__(self)
def Load(self):
old_cwd = os.path.realpath( os.curdir )
model_path = os.path.join("../", "data", "models", "monkeyluvva")
model_path = os.path.join("data", "models")
os.chdir(model_path)
self.models = []
m = milkviewer4.MilkshapeModel()
m.Load("bend.txt")
self.models.append(m)
os.chdir( old_cwd )
def Display(self):
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(0., 0., -100)
for m in self.models:
if not m.IsTextured():
glColor3f(1., 0., 1.)
m.Display()
if __name__ == "__main__":
a = MilkViewerVisualTest()
a.Start()
a.Loop()
new_rdpyg/docs/tests/test_pack_textures.py.html 0000644 0001751 0001751 00000013467 10160167712 022325 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
import unittest
from rdpyg.util import pack_textures
class TestPackTextures(unittest.TestCase):
"""
"""
def test_could_fit(self):
"""
"""
t1 = pack_textures.Texture(0,0,256,256)
t2 = pack_textures.Texture(0,0,256,256)
t3 = pack_textures.Texture(0,0,128,256)
t4 = pack_textures.Texture(0,0,128,256)
t5 = pack_textures.Texture(0,0,512,512)
t6 = pack_textures.Texture(500,500,128,128)
t7 = pack_textures.Texture(0,500,128,128)
t8 = pack_textures.Texture(500,0,128,128)
t9 = pack_textures.Texture(0,128,128,128)
t10 = pack_textures.Texture(128,0,128,128)
self.assertEqual(True, t1.could_fit(t2))
t1.clear()
self.assertEqual(True, t1.could_fit(t3))
t1.clear()
self.assertEqual(False, t1.could_fit(t5))
t1.clear()
self.assertEqual(False, t1.could_fit(t6))
t1.clear()
self.assertEqual(False, t1.could_fit(t7))
t1.clear()
self.assertEqual(False, t1.could_fit(t8))
t1.clear()
self.assertEqual(True, t1.could_fit(t9))
t1.clear()
self.assertEqual(True, t1.could_fit(t10))
t1.clear()
def test_try_fit(self):
"""
"""
t1 = pack_textures.Texture(0,0,256,256)
t2 = pack_textures.Texture(0,0,256,256)
t3 = pack_textures.Texture(0,0,128,256)
t4 = pack_textures.Texture(0,0,128,256)
t5 = pack_textures.Texture(0,0,512,512)
t6 = pack_textures.Texture(500,500,128,128)
t7 = pack_textures.Texture(0,500,128,128)
t8 = pack_textures.Texture(500,0,128,128)
t9 = pack_textures.Texture(0,128,128,128)
t10 = pack_textures.Texture(128,0,128,128)
self.assertEqual(True, t5.try_fit(t1))
self.assertEqual(True, t5.try_fit(t2))
self.assertEqual(True, t5.try_fit(t3))
self.assertEqual(True, t5.try_fit(t4))
t5.sub_textures
t5.clear()
t11 = pack_textures.Texture(0,0,4096,4096)
smalls = []
x in range(130):
for x in range(3030):
smalls.append(pack_textures.Texture(0,0,32,32))
r = t11.try_fit_batch(smalls)
t11.sub_textures
t11.clear()
for x in range(20000):
smalls.append(pack_textures.Texture(0,0,32,32))
r = t11.try_fit_batch(smalls)
print len(r)
t11.sub_textures
t11.clear()
def test_collide(self):
""" does collision work?
"""
t1 = pack_textures.Texture(0,0,256,256)
t2 = pack_textures.Texture(0,0,256,256)
t3 = pack_textures.Texture(0,0,128,256)
t4 = pack_textures.Texture(0,0,128,256)
t5 = pack_textures.Texture(0,0,512,512)
t6 = pack_textures.Texture(500,500,128,128)
t7 = pack_textures.Texture(0,500,128,128)
t8 = pack_textures.Texture(500,0,128,128)
t9 = pack_textures.Texture(0,128,128,128)
t10 = pack_textures.Texture(128,0,128,128)
t11 = pack_textures.Texture(1,1,256,256)
self.assertEqual(True, t1.collide(t3))
self.assertEqual(True, t1.collide(t2))
self.assertEqual(True, t1.collide(t4))
self.assertEqual(True, t1.collide(t9))
self.assertEqual(True, t1.collide(t11))
self.assertEqual(False, t1.collide(t6))
self.assertEqual(False, t9.collide(t10))
if __name__ == "__main__":
unittest.main()
new_rdpyg/docs/tests/test_paths.py.html 0000644 0001751 0001751 00000003566 10160167712 020562 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
import unittest
from rdpyg.util import paths
import pickle
class TestPaths(unittest.TestCase):
"""
"""
def test_pickling(self):
"""
"""
p = paths.Path()
p.SetPoints([[0., 0., 0.],
[0., 1., 0.],
[1., 1., 0.],
[2., 2., 0.],
[3., 3., 0.]])
pickled_path = pickle.dumps(p)
unpickled_path = pickle.loads(pickled_path)
self.assertEqual(p, unpickled_path)
if __name__ == "__main__":
unittest.main()
new_rdpyg/docs/tests/test_quaternion.py.html 0000644 0001751 0001751 00000023474 10160167712 021630 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
import unittest
import pickle
from rdpyg.util.quaternion import *
import rdpyg.util.quaternion as quaternion
import time
psyco
def within_accuracy(a,b, allowable_error = 0.000001):
""" Is a equal to b within the allowable_error?
"""
a <= b+ allowable_error and a > b- allowable_error
return math.fabs(a -b) < allowable_error
class TestBla(unittest.TestCase):
_debug_level = 1
def _debug(self, d, debug_level = 1):
if self._debug_level >= debug_level:
sys.stderr.write(":::%s:::\n" % d)
class TestExtraFuncs(unittest.TestCase):
""" tests the extra functions.
"""
_debug_level = 1
def _debug(self, d, debug_level = 1):
if self._debug_level >= debug_level:
sys.stderr.write(":::%s:::\n" % d)
def test_get_angles_from_two_points(self):
""" does the angle come out correctly for the given points.
"""
p1 = [0., 0., 0.]
p2 = [2., 0., 0.]
angles = quaternion.get_angles_from_two_points(p1, p2)
print angles
p1 = [0., 0., 0.]
p2 = [2., 1., 0.]
angles = quaternion.get_angles_from_two_points(p1, p2)
print angles
class TestQuaternions(unittest.TestCase):
""" The quaternion functions which I need for
"""
_debug_level = 1
def _debug(self, d, debug_level = 1):
if self._debug_level >= debug_level:
sys.stderr.write(":::%s:::\n" % d)
def test_length(self):
""" Is the length equal to 1.0?
"""
w,x,y,z = fromEuler( y = pi/2 ).internal
length = x**2 + y**2 + z**2 + w**2
self.assertEqual(1.0, length)
q1 = fromEuler( y = pi/2 )
q2 = fromEuler( x = pi/2 )
q3 = q1 * q2
w,x,y,z = q3.internal
length = x**2 + y**2 + z**2 + w**2
self.assertEqual(1.0, length)
def test_fromEuler(self):
"""
"""
fromEuler( y = pi/2 ).XYZR()
def test_to_matrix_and_back(self):
""" Does the conversion to matrix and from matrix work correctly?
"""
a = fromEuler( y = pi/2 )
b = fromMatrix(a.matrix())
w,x,y,z = b.internal
length = x**2 + y**2 + z**2 + w**2
self.assertEqual(1.0, length)
self.assertEqual(a.matrix(), b.matrix())
def test_speed_of_convert_to_matrix(self):
""" Is the speed of the quaternion to matrix acceptable?
"""
t1 = time.time()
a = fromEuler( z = pi/2 )
a_matrix = a.matrix
for x in range(13 * 300):
b = a_matrix()
t2 = time.time()
total_time = t2 -t1
print total_time
def test_slerp(self):
""" Does the slerp work correctly?
"""
a = fromEuler( z = pi/2 )
b = fromEuler( x = pi/2 )
c = slerp_quat(a,b, 0.5)
self.assertEqual( 1, within_accuracy(1.,length_quat(c)) )
def test_euler_to_quats(self):
"""
"""
a = [[0.0, 0.0, 0.0], [1.2042771577835081, 0.0, 0.0], [0.89011788368225098, 0.0, 0.0]]
quats_a = euler_to_quats(a)
b = [[0.087266437709331512, 5.1804383005560339e-10, 0.113446407020092], [-0.13962611556053159, -2.62412314100402e-08, 0.1134487614035606], [0.078540049493312836, -2.7923498180371101e-08, 0.1134487614035606]]
quats_b = euler_to_quats(b)
print quats_a
print quats_b
def test_pickling(self):
""" Can we pickle and unpickle the quaternions nicely?
"""
a = [[0.0, 0.0, 0.0],
[1.2042771577835081, 0.0, 0.0],
[0.89011788368225098, 0.0, 0.0]]
q = euler_to_quats(a)
pickled_q = pickle.dumps(q)
unpickled_q = pickle.loads(pickled_q)
self.assertEqual(q, unpickled_q)
def test_pickle(self):
""" can we pickle/unpickle it properly.
"""
q = fromEuler(1.2042771577835081, 0.0, 0.0)
pickled_quat = pickle.dumps(q)
unpickled_q = pickle.loads(pickled_quat)
self.assertEqual(q.internal, unpickled_q.internal)
def test_invert(self):
""" tests the inverse is correct. That is the opposite direction.
"""
q = fromAXYZ(180,1.,0.,0.)
q2 = -q
self.assertEqual(q2.AXYZ(), [180.00000000000003, -1.0, -0.0, -0.0] )
if __name__ == "__main__":
unittest.main()
new_rdpyg/docs/tests/visual_test_map.py.html 0000644 0001751 0001751 00000002527 10160167712 021577 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
from rdpyg.app import the_app
from urdpyg.map import map
import pygame
pygame.init()
a = the_app.TheApp()
a.Start()
a.Loop()
print a.GetFps()
a.Stop()
new_rdpyg/docs/tests/visual_test_particles.py.html 0000644 0001751 0001751 00000011356 10160167712 023010 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
"""
"""
import rdpyg.app.the_app_gl as the_app_gl
import rdpyg.draw.pyopengl.particles as particles
import traceback
import time
import sys
import pygame
from pygame.locals import *
from OpenGL.GL import *
import os
pygame.init()
class AApp(the_app_gl.TheAppGL):
draw_mode = 0
def Display(self):
pass
self._debug("running display", 4)
glClearColor(0.0, 0.0, 0.3, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glTranslate(0., 0., -20)
self.particles.DisplayStateBegin()
self.particles.Display()
self.particles.DisplayStateEnd()
def Load(self):
""" Place to load stuff. duh!
"""
self._debug("loading")
self.particles = particles.Particles(44)
self.particles.Load(file_name = os.path.join("data", "particle.png"))
def HandleEvents(self, event_list):
for event in event_list:
if event.type == QUIT or (event.type == KEYDOWN and
event.key == K_ESCAPE):
self.Stop()
return 0
break
if event.type == KEYDOWN and event.key == K_LEFT:
pass
if event.type == KEYDOWN and event.key == K_RIGHT:
pass
return 1
def Update(self, elapsed_time):
self.particles.Update(elapsed_time)
def main():
pygame.key.set_repeat(500, 30)
a = AApp()
t1 = time.time()
a.Start()
try:
a.Loop()
except:
traceback.print_exc(sys.stderr)
print "Cleaning up."
a.Stop()
total_time = time.time() - t1
print "time:%s frames:%s frames/time:%s" % (total_time, a.frames, a.frames/total_time)
if(__name__ == "__main__"):
if len(sys.argv) != 1:
if sys.argv[1] == "profile":
import profile
profile.run('main()', '/tmp/prof')
else:
main()
new_rdpyg/docs/tests/visual_test_paths.py.html 0000644 0001751 0001751 00000015400 10160167712 022133 0 ustar rene rene 0000000 0000000
/home/rene/mystuff/python/new_rdpyg/tests/chimpgl.py
"""
"""
import rdpyg.util.paths as paths
import rdpyg.util.cyclic_list as cyclic_list
import rdpyg.app.the_app_gl as the_app_gl
import rdpyg.draw.pyopengl.paths as draw_paths
import traceback
import time
import sys
import pygame
from pygame.locals import *
from OpenGL.GL import *
pygame.init()
class AApp(the_app_gl.TheAppGL):
draw_mode = 0
def Display(self):
pass
self._debug("running display", 4)
glClearColor(0.0, 0.0, 0.3, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glTranslate(0., 0., -10)
self.DrawPath()
def DrawPath(self):
if self.draw_mode:
draw = draw_paths.draw_path
else:
draw = draw_paths.draw_path_with_traveler
for p in self.paths:
draw(p)
def Load(self):
""" Place to load stuff. duh!
"""
self._debug("loading")
self.paths = cyclic_list.cyclic_list()
p = self.paths
p.append(paths.Path() )
p[0].SetPoints([[0., 0., 0.],
[0., 1., 0.],
[1., 1., 0.],
[2., 2., 0.],
[3., 3., 0.]])
def HandleEvents(self, event_list):
for event in event_list:
if event.type == QUIT or (event.type == KEYDOWN and
event.key == K_ESCAPE):
self.Stop()
return 0
break
if event.type == KEYDOWN and event.key == K_LEFT:
pass
if event.type == KEYDOWN and event.key == K_RIGHT:
pass
if event.type == KEYDOWN:
p = self.paths.cur()
if event.key == K_SPACE:
if pygame.key.get_mods() == KMOD_SHIFT:
self.paths.prev()
else:
self.paths.next()
if event.key == K_RETURN:
if pygame.key.get_mods() == KMOD_SHIFT:
for path in self.paths:
print path.length()
else:
pass
if event.key == K_BACKSPACE:
if self.draw_mode:
self.draw_mode = 0
else:
self.draw_mode = 1
if event.key == K_a:
if pygame.key.get_mods() & KMOD_SHIFT:
r = p.Travel(1., 1.)
else:
r = p.Travel(0.1, 0.1)
print r
if event.key == K_b:
if pygame.key.get_mods() & KMOD_SHIFT:
pass
else:
pass
self.points
return 1
def Update(self, elapsed_time):
p = self.paths.cur()
p.Travel(0.7, elapsed_time)
def main():
pygame.key.set_repeat(500, 30)
a = AApp()
t1 = time.time()
a.Start()
try:
a.Loop()
except:
traceback.print_exc(sys.stderr)
print "Cleaning up."
a.Stop()
total_time = time.time() - t1
print "time:%s frames:%s frames/time:%s" % (total_time, a.frames, a.frames/total_time)
if(__name__ == "__main__"):
if len(sys.argv) != 1:
if sys.argv[1] == "profile":
import profile
profile.run('main()', '/tmp/prof')
else:
main()
new_rdpyg/docs/urdpyg/ 0000755 0001751 0001751 00000000000 10160167717 015232 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/ 0000755 0001751 0001751 00000000000 10160167720 016536 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/converters/ 0000755 0001751 0001751 00000000000 10160167720 020730 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/converters/cal3d_exporter/ 0000755 0001751 0001751 00000000000 10160167717 023654 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/converters/cal3d_exporter/Cal3dSkeleton.html 0000644 0001751 0001751 00000006336 10160167717 027205 0 ustar rene rene 0000000 0000000
Class: Cal3dSkeleton
Table of Contents
| Class: Cal3dSkeleton
|
urdpyg/converters/cal3d_exporter.py
|
|
Methods
|
|
__init__
to_xml
|
|
|
__init__
|
__init__ ( self )
|
|
|
to_xml
|
to_xml ( self, indentation=0 )
returns a string with the xml for the cal3d skeleton.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/cal3d_exporter/Cal3dBone.html 0000644 0001751 0001751 00000006372 10160167717 026304 0 ustar rene rene 0000000 0000000
Class: Cal3dBone
Table of Contents
| Class: Cal3dBone
|
urdpyg/converters/cal3d_exporter.py
|
|
a class representing a cal3d bone.
|
Methods
|
|
__init__
to_xml
|
|
|
__init__
|
__init__ ( self )
|
|
|
to_xml
|
to_xml ( self, indentation=4 )
returns a string of xml representing this bone.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/md2_importer/ 0000755 0001751 0001751 00000000000 10160167717 023341 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/converters/md2_importer/Md2Model.html 0000644 0001751 0001751 00000014705 10160167717 025641 0 ustar rene rene 0000000 0000000
Class: Md2Model
Table of Contents
| Class: Md2Model
|
urdpyg/converters/md2_importer.py
|
|
Methods
|
|
Load
_ConvertTexcoords
_ReadHeader
_ReadMd2Data
__init__
|
|
|
Load
|
Load (
self,
md2_file_name=None,
md2_texture_file_name=None,
)
|
Exceptions
|
|
"Object has no file to load."
"file corrupt, version is not 8"
|
|
|
|
_ConvertTexcoords
|
_ConvertTexcoords (
self,
texcoords,
texture_indices,
w,
h,
)
Flips the v coordinate part, and makes a new array based on the
texture indices. texcoords -
texture_indices -
|
|
|
_ReadHeader
|
_ReadHeader (
self,
md2_file_name=None,
md2_texture_file_name=None,
)
|
|
|
_ReadMd2Data
|
_ReadMd2Data (
self,
md2_file_name=None,
md2_texture_file_name=None,
)
|
|
|
__init__
|
__init__ (
self,
md2_file_name=None,
md2_texture_file_name=None,
)
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/middle_obj/ 0000755 0001751 0001751 00000000000 10160167717 023026 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/converters/middle_obj/MiddleObject.html 0000644 0001751 0001751 00000011574 10160167717 026251 0 ustar rene rene 0000000 0000000
Class: MiddleObject
Table of Contents
| Class: MiddleObject
|
urdpyg/converters/middle_obj.py
|
|
Methods
|
|
AddExporter
AddImporter
SendFeatureRequestsToImporter
__init__
|
|
|
AddExporter
|
AddExporter ( self, exporter )
exporter - an object used to export 3d data from the middle object.
|
|
|
AddImporter
|
AddImporter ( self, importer )
importer - an object used to import 3d data into the middle object.
|
|
|
SendFeatureRequestsToImporter
|
SendFeatureRequestsToImporter ( self )
Goes through the exporters and gathers a set of
features which need to be sent to the importer.
|
|
|
__init__
|
__init__ ( self )
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/middle_obj/Exporter.html 0000644 0001751 0001751 00000010472 10160167717 025530 0 ustar rene rene 0000000 0000000
Class: Exporter
Table of Contents
| Class: Exporter
|
urdpyg/converters/middle_obj.py
|
|
Used for exporting 3d data from the MiddleObject.
This is a base class, to be used for exporters for various
3d formats.
|
Methods
|
|
GetSupportedFeatures
SetFeaturesWanted
__init__
|
|
|
GetSupportedFeatures
|
GetSupportedFeatures ( self )
Returns the features that this exporter supports.
|
|
|
SetFeaturesWanted
|
SetFeaturesWanted ( self, features )
Used to tell the exporter what features the exporter should
get from the middle object.
|
|
|
__init__
|
__init__ (
self,
supported_features,
wanted_features={},
)
supported_features -
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/middle_obj/Importer.html 0000644 0001751 0001751 00000013757 10160167717 025532 0 ustar rene rene 0000000 0000000
Class: Importer
Table of Contents
| Class: Importer
|
urdpyg/converters/middle_obj.py
|
|
Used for importing 3d data into a MiddleObject.
This is a base class, to be used for importers for various
3d formats.
|
Methods
|
|
GetSupportedFeatures
SetFeaturesWanted
Start
__init__
|
|
|
GetSupportedFeatures
|
GetSupportedFeatures ( self )
Returns the features that this importer supports.
|
|
|
SetFeaturesWanted
|
SetFeaturesWanted ( self, features )
Used to tell the importer what features the importer should
pass onto the middle object.
NOTE: this does not mean that the importer should not load all
of the 3d format. If it has to load it all so be it. Just pass
the features that are wanted.
|
|
|
Start
|
Start ( self )
Starts the importer doing its import thing.
|
Exceptions
|
|
"This importer is missing an implementation of Start()"
|
|
|
|
__init__
|
__init__ (
self,
supported_features,
wanted_features={},
)
supported_features - features which the
wanted_features - defaults to all features if not specified.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/ms3d_ascii_importer/ 0000755 0001751 0001751 00000000000 10160167720 024667 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/converters/ms3d_ascii_importer/MS3dImporter.html 0000644 0001751 0001751 00000017023 10160167720 030050 0 ustar rene rene 0000000 0000000
Class: MS3dImporter
Table of Contents
| Class: MS3dImporter
|
urdpyg/converters/ms3d_ascii_importer.py
|
|
Methods
|
|
Initialize
ReadBones
ReadMaterials
ReadMeshes
Start
__init__
|
|
|
Initialize
|
Initialize ( self, file )
|
|
|
ReadBones
|
ReadBones (
self,
a_file,
num_bones,
)
a_file should be set to after the Bones line.
|
|
|
ReadMaterials
|
ReadMaterials (
self,
a_file,
num_materials,
)
a_file should be set to after the Materials line.
|
|
|
ReadMeshes
|
ReadMeshes (
self,
a_file,
num_meshes,
)
|
|
|
Start
|
Start ( self )
|
|
|
__init__
|
__init__ ( self, wanted_features=None )
If wanted_features equals None then all features are given.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/ms3d_ascii_importer/milk_bones.html 0000644 0001751 0001751 00000006225 10160167720 027704 0 ustar rene rene 0000000 0000000
Class: milk_bones
Table of Contents
| Class: milk_bones
|
urdpyg/converters/ms3d_ascii_importer.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/ms3d_ascii_importer/milk_material.html 0000644 0001751 0001751 00000005000 10160167720 030362 0 ustar rene rene 0000000 0000000
Class: milk_material
Table of Contents
| Class: milk_material
|
urdpyg/converters/ms3d_ascii_importer.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/ms3d_ascii_importer/milk_mesh.html 0000644 0001751 0001751 00000006223 10160167720 027530 0 ustar rene rene 0000000 0000000
Class: milk_mesh
Table of Contents
| Class: milk_mesh
|
urdpyg/converters/ms3d_ascii_importer.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/test_cal3d_exporter/ 0000755 0001751 0001751 00000000000 10160167720 024705 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/converters/test_cal3d_exporter/Cal3dExporter.html 0000644 0001751 0001751 00000010125 10160167720 030251 0 ustar rene rene 0000000 0000000
Class: Cal3dExporter
Table of Contents
| Class: Cal3dExporter
|
urdpyg/converters/test_cal3d_exporter.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/test_md2_importer/ 0000755 0001751 0001751 00000000000 10160167720 024372 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/converters/test_md2_importer/TestMd2Importer.html 0000644 0001751 0001751 00000006321 10160167720 030266 0 ustar rene rene 0000000 0000000
Class: TestMd2Importer
Table of Contents
| Class: TestMd2Importer
|
urdpyg/converters/test_md2_importer.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/test_middle_obj/ 0000755 0001751 0001751 00000000000 10160167720 024057 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/converters/test_middle_obj/fsdf.html 0000644 0001751 0001751 00000003663 10160167720 025677 0 ustar rene rene 0000000 0000000
Class: fsdf
Table of Contents
| Class: fsdf
|
urdpyg/converters/test_middle_obj.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/cal3d_exporter.html 0000644 0001751 0001751 00000015332 10160167717 024546 0 ustar rene rene 0000000 0000000
Module: cal3d_exporter
Table of Contents
| Module: cal3d_exporter
|
urdpyg/converters/cal3d_exporter.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/__init__.html 0000644 0001751 0001751 00000002377 10160167717 023374 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
urdpyg/converters/__init__.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/md2_importer.html 0000644 0001751 0001751 00000012010 10160167717 024221 0 ustar rene rene 0000000 0000000
Module: md2_importer
Table of Contents
| Module: md2_importer
|
urdpyg/converters/md2_importer.py
|
|
Copyright (C) 2002, 2003 by Rene Dudfield.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/index.html 0000644 0001751 0001751 00000006651 10160167720 022735 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: urdpyg.converters
Table of Contents
| HappyDoc Generated Documentation: urdpyg.converters
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/ms3d_ascii_exporter.html 0000644 0001751 0001751 00000007134 10160167717 025577 0 ustar rene rene 0000000 0000000
Module: ms3d_ascii_exporter
Table of Contents
| Module: ms3d_ascii_exporter
|
urdpyg/converters/ms3d_ascii_exporter.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/middle_obj.html 0000644 0001751 0001751 00000006257 10160167717 023726 0 ustar rene rene 0000000 0000000
Module: middle_obj
Table of Contents
| Module: middle_obj
|
urdpyg/converters/middle_obj.py
|
|
Copyright (C) 2002 by Rene Dudfield.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/ms3d_ascii_importer.html 0000644 0001751 0001751 00000025612 10160167720 025563 0 ustar rene rene 0000000 0000000
Module: ms3d_ascii_importer
Table of Contents
| Module: ms3d_ascii_importer
|
urdpyg/converters/ms3d_ascii_importer.py
|
|
Copyright (C) 2002 by Rene Dudfield.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Imported modules
|
|
import cPickle
import md5
from middle_obj import *
import operator
import os
import re
import string
from string import split, join
import time
|
|
Functions
|
|
chomp
convert_array_shape2
convert_array_shape3
convert_milkshape
str_parse
test_MS3dImporter
|
|
|
chomp
|
chomp ( s )
|
|
|
convert_array_shape2
|
convert_array_shape2 ( verts )
|
|
|
convert_array_shape3
|
convert_array_shape3 ( verts )
Converts a [[1,1,1,1], [1,1,1,1]] into [1,1,1,1,1,1]
|
|
|
convert_milkshape
|
convert_milkshape ( a_file )
Returns a list of [points, indices, texcoords]
Only converts one mesh.
|
|
|
str_parse
|
str_parse (
string_to_parse,
conversion_list,
seperator=" ",
)
returns a list of formated converted variables based on the
string_to_parse - um..
conversion_list - list of functions, to convert parts of the string.
Use str for strings, int for ints, floats for floats etc :)
seperator - string to use to seperate the elements of the string. Will raise exceptions if string not correctly set up. Or if data fails
to convert.
|
Exceptions
|
|
"wrong number of converters, or string doesn't match."
|
|
|
|
test_MS3dImporter
|
test_MS3dImporter ( file_name )
points,indices,texcoords = convert_milkshape(file_name)
|
|
Classes
|
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/test_cal3d_exporter.html 0000644 0001751 0001751 00000005547 10160167720 025606 0 ustar rene rene 0000000 0000000
Module: test_cal3d_exporter
Table of Contents
| Module: test_cal3d_exporter
|
urdpyg/converters/test_cal3d_exporter.py
|
|
unit tests for the cal3d exporter.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/test_md2_importer.html 0000644 0001751 0001751 00000006025 10160167720 025263 0 ustar rene rene 0000000 0000000
Module: test_md2_importer
Table of Contents
| Module: test_md2_importer
|
urdpyg/converters/test_md2_importer.py
|
|
unit tests for the md2 importer.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/converters/test_middle_obj.html 0000644 0001751 0001751 00000005400 10160167720 024744 0 ustar rene rene 0000000 0000000
Module: test_middle_obj
Table of Contents
| Module: test_middle_obj
|
urdpyg/converters/test_middle_obj.py
|
|
unit tests for the md2 importer.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/map/ 0000755 0001751 0001751 00000000000 10160167720 017313 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/map/__init__.html 0000644 0001751 0001751 00000002370 10160167720 021742 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
urdpyg/map/__init__.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/map/index.html 0000644 0001751 0001751 00000004276 10160167720 021321 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: urdpyg.map
Table of Contents
| HappyDoc Generated Documentation: urdpyg.map
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/map/map.html 0000644 0001751 0001751 00000016060 10160167720 020761 0 ustar rene rene 0000000 0000000
Module: map
Table of Contents
| Module: map
|
urdpyg/map/map.py
|
|
= Features wanted =
When not moving it can take only update parts of the screen.
update(dirty_rects) can be used to speed up drawing.
by only updating areas which are dirty.
if the map is not moving we can make it lots speedier.
Offscreen buffer. Blit all smaller tiles to an offscreen buffer then blit
one big image to the screen. This can be faster on some screens/computers.
Different tile sizes.
different sizes on the same map.
Join maps together easily.
Different drawable sizes. Ie different camera views.
Be able to be used with pygame or pyopengl.
Different camera modes:
jump scrolling,
jump the map in blocks. Like ten pixels at a time.
smooth scrolling,
every pixel the camera moves the tiles move.
smooth-jump scrolling.
Mostly the screen stays still. When the character nears the edge
everything stops moving while the maps scrolls over a little way.
centered camera.
Can center the camera on
Looping Map Edges
Paralax scrolling.
Moving layers at different speeds.
Multiple views of the map.
* miniview of the map. Perhaps using a scaled version or one pixel per tile.
minimize overdraw.
using dirty rectangles.
for alpha images precalculate full rects.
That is like a bounding box in the middle where the area is full.
think about using a coverage buffer.
* animated tiles will probably always need to be redrawn(unless it's the same frame).
Overlapping tiles.
As well as overlapping whole maps. For joining maps together.
Layers/Z ordering.
draw characters by descending y value on same layer.
for certain types of games: see for explanation:
* http://www.gamedev.net/reference/programming/features/gpgenesis9/page7.asp
line of sight tests between tiles and pixels/rects.
collision detection between tiles and pixels/rects.
some tiles may be pass through.
* tiles on different layers may be collidable, others not.
fog of war.
* darkening/lightening of areas.
Rotatable tiles.
* scalable tiles? Other transforms needed?
Easy layer toggling.
* So eg when you go inside a building the roof comes off and you can see inside.
= Implementation ideas =
Use pygame sprites and sprite groups.
could then reuse lots of code... optimize in one place. Speed development.
think of camera movement as simply moving a sprite group in a certain way.
Use a quad tree for the collision detection.
* Could use it for moving, and non moving.
Left to right, or top to bottom scrollers can be optimized in different ways.
= Some map editors =
The tile combie(or engine if you want) should have most of the features that these map editors contain.
http://tilestudio.sourceforge.net/
http://www.tilemap.co.uk/
= A discussion about features =
<geoffh> background tiling, layers, collision detection between layers and stuff (rect and pixel)
<geoffh> paralax scrolling
<geoffh> animation of background/sprites
<geoffh> line of sight tests between tiles and pixels
<geoffh> based on layer compositions and such
<illumeh> eek, that's a lot of stuff
<illumeh> good stuff :)
<geoffh> separate environmental and UI layer systems
<illumeh> what do you mean?
<geoffh> so you can draw your UI without worrying how height your environments layers are
<geoffh> the UI layers are alwayrs on top
<illumeh> ah, cool
<geoffh> basically, just 2 lists for heights
<geoffh> auto-shadowing for sprites is good
<illumeh> indeed, that'd be cool
<geoffh> doing like angled skews on the images, and drawing them on the ground layer
<geoffh> so you dont have to have separate shadow images for them
<illumeh> nice
<geoffh> or just auto positioning the same image, but based on heigth of the sprite
<geoffh> so like a flying ship has its shadow in the real place, and its in its height-adjusted place, like zaxxon
<geoffh> which basically just means you have a transformation for height built in, and use a sort of worrld coords and translated drawing coords
<illumeh> aah
<geoffh> which makes sense
<geoffh> so you should have parameters to what your viewing perspective is, so they can adjust it based on how their art is rendered
<geoffh> like: 1.5:1.0 or something
<geoffh> you could also have layer toggling like i did in VT, where if you go into a building, it switches what the background tiles are. and if you change floors, it also does that
<illumeh> ah, that sounds nice too
<geoffh> but that may be a bit specific. though, you could make the design so its possible to rotate through BG tile maps specifically, like theyre layered and do a fall through if the current selected one doesnt exist
<geoffh> to the default background map, which has all its spaces mapped
<geoffh> sorta an "optional current level background"
<geoffh> good for things where people take stairs, and you still want the ground of things outside buildings and such
<geoffh> im running out of stuff ive thought about for tiling engines
<illumeh> hehe. that's all stuff I didn't think about :)
<geoffh> i want to retire
<geoffh> im pretty happy doing fuck all all the time now
<geoffh> heh
<illumeh> having layers greyed out would be good
<illumeh> hehe. mostly I'm happy doing fuck all too :)
<geoffh> optional layers? or you mean something else?
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:42 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/ 0000755 0001751 0001751 00000000000 10160167720 021376 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/BoneName2BoneNumber_Map.html 0000644 0001751 0001751 00000007632 10160167720 026614 0 ustar rene rene 0000000 0000000
Class: BoneName2BoneNumber_Map
Table of Contents
| Class: BoneName2BoneNumber_Map
|
urdpyg/milk_skeleton.py
|
|
mapping of bone names to a number in the bone index.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/AbsoluteBones.html 0000644 0001751 0001751 00000004303 10160167720 025031 0 ustar rene rene 0000000 0000000
Class: AbsoluteBones
Table of Contents
| Class: AbsoluteBones
|
urdpyg/milk_skeleton.py
|
|
Stores the absolute transforms. There is a seperate one of these
for each keyframe.
Need matrix, and quat+pos_vector versions
- The matrix versions would be used to transform verts.
- The quat_pos_vector versions will blend with other bones.
- The conversion to matrices will need to be cached.
- Use three arrays.
- rotation quats( an array of four elements ).
- translation quats(array of four elements ).
Maybe only need matrix version for absolute?
- No, need to slerp between two absolute bones.
Don't need a matrix representation?
- maybe not, if the these are only used to slerp up an intermediate
set of bones.
NOTE: for transforming the verts, it will be faster to transform them with
a 3x3 rotation matrix if there is no translation/scaling happening.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/Bone2Vert_Map.html 0000644 0001751 0001751 00000010335 10160167720 024671 0 ustar rene rene 0000000 0000000
Class: Bone2Vert_Map
Table of Contents
| Class: Bone2Vert_Map
|
urdpyg/milk_skeleton.py
|
|
a list of indices for the verts that each bone should transform.
Should probably be a Numeric 3d array.
where self.data[0] == list of vert indices for the first bone. Each index could be 4 bytes for four bones.
- this would be harder to access.
- would limit the total number of bones.
For now keep it simple.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/BoneHeirarchy.html 0000644 0001751 0001751 00000023267 10160167720 025020 0 ustar rene rene 0000000 0000000
Class: BoneHeirarchy
Table of Contents
| Class: BoneHeirarchy
|
urdpyg/milk_skeleton.py
|
|
Which bones are parents/children of which other bones.
- has bone names, and bone indices into AbsoluteBones/RelativeBones.
- GetChildren_names/indices - returns a list of names/indices. BoneName2BoneNumber_Map - mapping of bone names to a number in the bone
index.
|
Methods
|
|
GetChildren
GetChildren_idx
GetParents
GetRootName
PrintTree
Update
__init__
__str__
_make__bone_name_to_idx
|
|
|
GetChildren
|
GetChildren ( self, bone_name )
Returns a list of children milk_bone instances.
|
|
|
GetChildren_idx
|
GetChildren_idx ( self, bone_name )
returns a list of idx for the children of given bone name.
|
|
|
GetParents
|
GetParents ( self, bone_name )
Returns a list of parents milk_bone instances.
|
|
|
GetRootName
|
GetRootName ( self )
Returns the root bones name.
|
|
|
PrintTree
|
PrintTree (
self,
a_bone="ROOT",
indent_level=0,
details=0,
)
Returns a string representation of bones tree.
a_bone - a milk_bone instance, or "ROOT".
if "ROOT" then we return from the root of the tree.
|
|
|
Update
|
Update ( self, milk_bones )
Takes a milk_bones variable from the milkshape converter.
|
|
|
__init__
|
__init__ ( self, milk_bones )
Takes a milk_bones variable from the milkshape converter.
|
|
|
__str__
|
__str__ ( self )
|
|
|
_make__bone_name_to_idx
|
_make__bone_name_to_idx ( self, milk_bones )
returns a dict mapping bone name -> its idx within the list.
|
Exceptions
|
|
ValueError( "bone allready exists with name, %s" % milk_bone.name )
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/MilkshapeModelLoader.html 0000644 0001751 0001751 00000011115 10160167720 026310 0 ustar rene rene 0000000 0000000
Class: MilkshapeModelLoader
Table of Contents
| Class: MilkshapeModelLoader
|
urdpyg/milk_skeleton.py
|
|
responsible for loading a milkshape model.
|
Methods
|
|
IsTextured
Load
__init__
_debug
|
|
|
IsTextured
|
IsTextured ( self )
|
|
|
Load
|
Load ( self, file_name )
|
|
|
__init__
|
__init__ ( self, file_name="" )
|
|
|
_debug
|
_debug (
self,
x,
debug_level=1,
)
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/MilkSkeleton.html 0000644 0001751 0001751 00000032350 10160167720 024670 0 ustar rene rene 0000000 0000000
Class: MilkSkeleton
Table of Contents
| Class: MilkSkeleton
|
urdpyg/milk_skeleton.py
|
|
----------------------------------------------------------------------
Data structures.
- = denotes data belongs to this parent. Skeleton - this is where everything is put together.
- we may want to share some data between skeletons, so we may need a
higher level system.
- this higher level system would share the different parts of memory.
- Maybe it could even transform all of the data at once. = BoneHeirachy DONE.
= Keyframes
= Bone2Vert_Map DONE.
= Time2Keyframe_Map
= KeyframeNumber2Time_Map
Keyframes - collects the different keyframe data for a skeleton.
= AbsoluteBones
= RelativeBones
= Time2Keyframe_Map
= KeyframeNumber2Time_Map
AbsoluteBones - bones represented in their absolute form.
- Need matrix, and quat+pos_vector versions
- The matrix versions would be used to transform verts.
- The quat_pos_vector versions will blend with other bones.
- The conversion to matrices will need to be cached.
- Use three arrays.
- rotation quats( an array of four elements ).
- translation quats(array of four elements ).
- transform matrices(array of 16 elements ie 4x4 matrices).
RelativeBones - these bones will have all relative data. Eg each bone
will only be relative to the others.
Time2Keyframe_Map. - gets two keyframes on either side of a given time.
- this would be per bone? Not at the moment(it should be per skeleton).
KeyframeNumber2Time_Map. - given a keyframe number, give the time for it.
- this would be per bone? Not at the moment(it should be per skeleton).
DONE.
BoneHeirachy - which bones are parents/children of which other bones.
- has bone names, and bone indices into AbsoluteBones/RelativeBones.
- GetChildren_names/indices - returns a list of names/indices. BoneName2BoneNumber_Map - mapping of bone names to a number in the bone
index.
DONE.
Bone2Vert_Map - a list of indices for the verts that each bone should
transform.
Vert2Bone_Map - vert to list of bones which effect them.
MilkBones - this is the data from the milk format. This contains
the positions, and rotations in euler format, and the keyframe times.
local2world_transform - a transform specifying where in the world the
skeleton is.
- This will likely change occasionally.
- from every frame to once every minute.
- is this specified by the root node?
- Could we add this as the new root node?
- would simplify the code if we did.
- Can be added as an after thought if needed. Pretty easy.
- Not really, as it possible this would change all the time.
- We may want to add this, as it will solve having to re-transform them.
- On the other hand this could be done in hardware with gf+ cards.
----------------------------------------------------------------------
---------------------------------------------------------------------
Order of the operations.
- Things that need to be done in order to get the model transformed.
Set up stuff. - things to do around load time.
From the milk bones set up:
- BoneHeirachy
- Set up the relative bones.
- Convert the Euler angle milkshape rotations into quaternions.
- Convert the milkshape positions into quaternions.
Q(Px, Py, Pz, w =0.0)
- rotation, position quaternions multiplied and stored.
AbsoluteBones are made from RelativeBones.
For each keyframe.
Multiply the bones down the heirarchy.
child.absolute = parent.absolute * child.relative
Per frame stuff.
Get current time in animation.
From Time2Keyframe_Map grab two keyframes on either side of current time.
For every absolute quat:
Interpolate between two keyframes:
t1 = current_time_in_animation - kf_a.time
t2 = kf_b.time -kf_a.time
slerp = t1/t2
frame_now = quat_slerp(kf_a.absolute, kf_b.absolute, slerp)
Generate the matrices for each absolute quat.
Transform each absolute matrix by the local2world_transform.
Transform verts of the mesh:
For vertex which is affected by one bone: For each absolute matrix transform its verts.
If the vert is only affected by one bone:
Multiply the vert by the absolute matrix.
else:
somehow interpolate the different bones.
- TODO: ^
- maybe this could be done in the slerp?
- storing some extra absolute quats for the verts affected
by multiple ones.
- this is where bone weights can fit in.
For now we will only support one bone per vertex.
Alternate way to transform the skin:
For each vertex:
look at the weight structure.
ulong32 boneIndices - 4 indices to bones.
ulong32 weights - 4 weights.
---------------------------------------------------------------------
Optimizations.
---------------------------------------------------------------------
When a key frame does not have any translations the transform of the
vertices can be optimized to only use a 3x3 rot, instead of a 4x4.
- There may be other optimizations depending on the bones state.
- Maybe we could store a BONE_STATE int which will allow us to
quickly identify a type of bone? This would allow us to quickly
see if the bone has no translation.
- We could group bones of similar nature together to make the
transforms quicker. Eg all bones with no translation part could
be stuck together.
- Remember that we need to apply a local2world transform to all of the
different absolute matrices.
We may be able to cache certain different transforms.
- I'm pretty sure there will be many repeated transforms.
A cheap way to interpolate between keyframes would be linear using the
mesh's verts.
This would involve calculating the mesh for each key frame, and then
interpolating between each vertex in meshes a, and b. Perhaps this could be an optional thing. To be used for slow
computers, when a character is far away, or when the difference in
time or movement of the character is really small.
A downside to this is that you need to keep at least three sets of the
mesh around at any time.
An upside to this is that interpolation can be done on
lighting values too.
---------------------------------------------------------------------
---------------------------------------------------------------------
TODOS: Future todos:
- have keyframe data for seperate parts of the skeleton.
- eg make the hand have it's own keyframes.
- This would complicate how to construct the absolute quats.
- You would recalculate down from the animation for that part.
- so if the arm was using some extra ones we'd go from there.
Incorporate bone weights into it.
- Milkshape doesn't support these, however others(characterfx) do.
Look at the different ways to accelerate these with hardware.
- ati, and nvidia have things to do this from geforce up.
---------------------------------------------------------------------
---------------------------------------------------------------------
Dependencies
- a list of different dependencies that need to be considered.
- helps with caching different things.
---------------------------------------------------------------------
---------------------------------------------------------------------
OLD Order of the operations.
X Convert the axis angle milkshape rotations into quaternions.
X The translations should also be converted into quaternions,
X and multiplied by the rotation part. Q(Px, Py, Pz, w =0.0)
X Have an absolute quaternion, and a relative one for each bone.
X Quats should be seperate for the current frame that is to be rendered.
X - that is the final bones for the current frame should be in a single
X array.
X - this is so that they may be easily converted to matrices.
X Absolute matrices for the current frame should be made.
X - these matrices include For each keyframe.
Multiply the bones down the heirarchy.
child.absolute = parent.absolute * child.relative
To interpolate between two keyframes we do:
t1 = current_time_in_animation - keyframe_a.time
t2 = keyframe_b.time -keyframe_a.time
slerp = t1/t2
frame_now = quat_slerp(keyframe_a.absolute, keyframe_b.absolute, slerp)
Any time a bones rotation changes we need to recalculate all of its
children.
To transform verts of the mesh:
We need the absolute matricies for each bone. Do we support multiple bones per vertex?
If so will we use weighting?
Apply a local2world transform to all of the different absolute matrices.
- this should be added as a new root node.
|
Methods
|
|
__init__
_convert_angles_to_quats
|
|
|
__init__
|
__init__ ( self, milk_data )
the data attribute from the milkshape converter.
|
|
|
_convert_angles_to_quats
|
_convert_angles_to_quats ( self )
This converts the different rotations of the bones into
quaternions.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/Time2Keyframe_Map.html 0000644 0001751 0001751 00000014110 10160167720 025522 0 ustar rene rene 0000000 0000000
Class: Time2Keyframe_Map
Table of Contents
| Class: Time2Keyframe_Map
|
urdpyg/milk_skeleton.py
|
Each bone should be able to have it's own key frames.
time2keyframe_maps[bone_name] -> time2keyframe_map
time2keyframe_map[seconds_since_start_of_animation] -> keyframe index's.
Depending on whether we want the animation to loop or stop at the start
or the end, we return a keyframe on either side of the time specified.
TODO: we can loop at the start of the keyframes as well as at the end.
|
Methods
|
|
GetIndicesEitherSideOfTime
Update
UpdateFromBones
__init__
|
|
|
GetIndicesEitherSideOfTime
|
GetIndicesEitherSideOfTime ( self, time )
time - a float
Returns the two keyframe indices either side of the time given.
|
|
|
Update
|
Update ( self, times )
times - a sequence of floats representing keyframes.
|
|
|
UpdateFromBones
|
UpdateFromBones ( self, milk_bone )
milk_bone - used to get the different times for the keyframes.
|
|
|
__init__
|
__init__ ( self, loop=0 )
loop - should we loop the animation back to the start once the last
keyframe has been reached?
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/RelativeBones.html 0000644 0001751 0001751 00000007057 10160167720 025037 0 ustar rene rene 0000000 0000000
Class: RelativeBones
Table of Contents
| Class: RelativeBones
|
urdpyg/milk_skeleton.py
|
|
Stores transforms relative to it's parent. There is a seperate set
of these for each of the keyframes.
Need matrix, and quat+pos_vector versions
- The matrix versions would be used to transform verts.
- The quat_pos_vector versions will blend with other bones.
- The conversion to matrices will need to be cached.
- Use three arrays.
- rotation quats( an array of four elements ).
- translation quats(array of four elements ).
TODO: find if a quatRotation quatTranslation is equal to a
matrixRotation matrixTranslation.
|
Methods
|
|
Update
|
|
|
Update
|
Update ( self, milk_bone )
From the milkshape data transform it into an internal representation.
milk_bone - a bone from the converter.
Convert the Euler angle milkshape rotations into quaternions.
- Convert the milkshape positions into quaternions.
Q(Px, Py, Pz, w =0.0)
- rotation, position quaternions multiplied and stored.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton/Vert2Bone_Map.html 0000644 0001751 0001751 00000006213 10160167720 024671 0 ustar rene rene 0000000 0000000
Class: Vert2Bone_Map
Table of Contents
| Class: Vert2Bone_Map
|
urdpyg/milk_skeleton.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milkviewer4/ 0000755 0001751 0001751 00000000000 10160167720 021000 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/milkviewer4/MilkshapeModel.html 0000644 0001751 0001751 00000016663 10160167720 024600 0 ustar rene rene 0000000 0000000
Class: MilkshapeModel
Table of Contents
| Class: MilkshapeModel
|
urdpyg/milkviewer4.py
|
|
Loads and displays a milk shape 3d model.
|
Methods
|
|
Display
Load
LoadImage
ReloadTextures
_FinishDisplay
_MiddleDisplay
_StartDisplay
|
|
|
Display
|
Display ( self )
Call this to draw.
|
|
|
Load
|
Load ( self, file_name )
|
|
|
LoadImage
|
LoadImage ( self, filename )
|
|
|
ReloadTextures
|
ReloadTextures ( self )
reloads any textures. Useful when a context change happens.
|
|
|
_FinishDisplay
|
_FinishDisplay ( self )
Call after drawing.
|
|
|
_MiddleDisplay
|
_MiddleDisplay ( self )
|
|
|
_StartDisplay
|
_StartDisplay ( self )
This is all the stuff you call before drawing.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/music/ 0000755 0001751 0001751 00000000000 10160167720 017656 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/music/Music.html 0000644 0001751 0001751 00000023752 10160167720 021635 0 ustar rene rene 0000000 0000000
Class: Music
Table of Contents
| Class: Music
|
urdpyg/music.py
|
Useage:
m = Music()
m.Play("intro")
m.Play("bla")
Need a directory ../data/music/intro.ogg
|
Methods
|
|
|
|
|
|
GetFileNames
|
GetFileNames ( self, path=os.path.join( "..", "data", "music" ) )
returns a dict of file names to be used as music. keyed by the file name
without path, and .ogg.
path - to the file names.
|
|
|
Load
|
Load ( self, music_type )
music_type - one of the music types from the sound_config.
|
|
|
Pause
|
Pause ( self )
pauses the music.
|
|
|
Play
|
Play (
self,
music_type,
loop=-1,
)
Starts playing the music.
|
|
|
SetLoudVol
|
SetLoudVol ( self, vol )
louder than max volume. this is for special occasions.
|
|
|
SetMaxVol
|
SetMaxVol ( self, vol )
sets the maximum volume for the music.
|
|
|
Stop
|
Stop ( self )
|
|
|
UnPause
|
UnPause ( self )
|
|
|
Update
|
Update ( self, elapsed_time )
To be called frequently.
|
|
|
__init__
|
__init__ ( self )
|
|
|
music_play_callback
|
music_play_callback ( self )
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/some_sound/ 0000755 0001751 0001751 00000000000 10160167720 020711 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/some_sound/SoundManager.html 0000644 0001751 0001751 00000016240 10160167720 024165 0 ustar rene rene 0000000 0000000
Class: SoundManager
Table of Contents
| Class: SoundManager
|
urdpyg/some_sound.py
|
|
Controls loading, mixing, and playing the sounds.
Having seperate classes allows different groups of sounds to be loaded,
and unloaded from memory easily.
|
Methods
|
|
GetSound
Initialize
Load
Play
PlayMusic
__init__
_debug
|
|
|
GetSound
|
GetSound ( self, name )
Returns a Sound object for the given name.
|
|
|
Initialize
|
Initialize ( self )
Initializes the mixer.
|
|
|
Load
|
Load ( self, names=sound_list )
Loads sounds.
|
|
|
Play
|
Play (
self,
name,
volume=[ 1.0, 1.0 ],
wait=1,
)
Plays the sound with the given name.
name - of the sound.
volume - left and right. Ranges 0.0 - 1.0
wait - if there is a sound of this type playing wait for it.
|
|
|
PlayMusic
|
PlayMusic ( self, musicname )
Plays a music track. Only one can be played at a time.
So if there is one playing, it will be stopped and the new one started.
|
|
|
__init__
|
__init__ ( self )
|
|
|
_debug
|
_debug (
self,
x,
debug_level=0,
)
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/some_sprites/ 0000755 0001751 0001751 00000000000 10160167720 021252 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/some_sprites/Animation.html 0000644 0001751 0001751 00000026022 10160167720 024061 0 ustar rene rene 0000000 0000000
Class: Animation
Table of Contents
| Class: Animation
|
urdpyg/some_sprites.py
|
For telling which of the frames should be drawn.
Howto use:
a = Animation(...)
a.Start()
if a.StillGoing():
new_frame_to_draw = a.NewFrame()
if new_frame_to_draw:
draw(new_frame_to_draw)
else:
# old frame to be rendered.
pass
else:
# figure out what to do at end of anim.
pass
|
Methods
|
|
|
|
|
|
A__nonzero__
|
A__nonzero__ ( self )
Used to see if the animation is still going.
|
|
|
GetLengthOfAnim
|
GetLengthOfAnim ( self )
|
|
|
GetName
|
GetName ( self )
|
|
|
GetNumTimesPlayed
|
GetNumTimesPlayed ( self )
Returns the number of times the animation has been played.
|
|
|
NewFrame
|
NewFrame ( self )
Returns the frame name if there is a new frame needed for the animation.
Otherwise returns 0.
|
|
|
SetUpAnimationData
|
SetUpAnimationData ( self, animation_data )
Sets up the animation data ready for processing.
|
|
|
Start
|
Start ( self, loop=1 )
Starts the animation at the beginning.
|
|
|
StillGoing
|
StillGoing ( self )
returns the frame name if still going else, returns 0 if finished.
|
|
|
_GetFrameGivenTimeInAnim
|
_GetFrameGivenTimeInAnim ( self, time_in_anim )
Returns the frame name we should be rendering given a time in the anim.
|
|
|
__init__
|
__init__ (
self,
animation_data,
name,
loop=1,
)
animation_data - a list of tuples (frame_name, time).
The time part says for how long in the animation that the
frame should be shown.
Must have at least one element. loop - should the animation loop.
If 0 the animation will return the last frame when it gets to the end.
If -1 the animation will loop for ever.
If non zero the animation will loop that many times.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/some_sprites/A.html 0000644 0001751 0001751 00000006216 10160167720 022325 0 ustar rene rene 0000000 0000000
Class: A
Table of Contents
| Class: A
|
urdpyg/some_sprites.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/some_sprites/ImageAnimation.html 0000644 0001751 0001751 00000026273 10160167720 025034 0 ustar rene rene 0000000 0000000
Class: ImageAnimation
Table of Contents
| Class: ImageAnimation
|
urdpyg/some_sprites.py
|
|
Methods
|
|
|
|
|
|
LoadAnimationData
|
LoadAnimationData ( self )
|
|
|
LoadImages
|
LoadImages ( self, image_dict={} )
image_dict - should be a dictionary which is keyed by the frame name,
and valued by an image for that frame. If the dict is {}
then the images are loaded from disk.
|
|
|
MakeScaledVersion
|
MakeScaledVersion (
self,
key_name,
size,
)
keyname - what the scaled version should be called.
eg (really small, (0,0))
size - x,y tuple.
|
|
|
ResetImageRect
|
ResetImageRect ( self )
After changing the self.images dict this should be called.
|
|
|
SetLogicalImages
|
SetLogicalImages ( self, x_y )
Sets the appropriate images for the place on the logical grid.
|
|
|
SetPosition
|
SetPosition ( self, position )
|
|
|
StartAnim
|
StartAnim (
self,
anim_name,
loop=1,
)
|
|
|
__init__
|
__init__ (
self,
animation_set_name,
initial_animation,
)
animation_name - name of the animation set to use.
|
|
|
move
|
move ( self, direction )
|
|
|
update
|
update (
self,
frame_name=None,
percent_trans=None,
)
frame_name - this is the name of the frame to draw.
percent_trans - is the alpha value for which to draw If frame_name, and percent_trans are None then they are worked out
for themselves.
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/some_sprites/Timer.html 0000644 0001751 0001751 00000007743 10160167720 023233 0 ustar rene rene 0000000 0000000
Class: Timer
Table of Contents
| Class: Timer
|
urdpyg/some_sprites.py
|
|
Methods
|
|
Start
__init__
__nonzero__
|
|
|
Start
|
Start ( self, length )
length is the amount of time that this timer should go for.
|
|
|
__init__
|
__init__ ( self, length )
a = Timer(10)
# if the timer is finished.
if a:
print "asdf"
|
|
|
__nonzero__
|
__nonzero__ ( self )
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/sounds/ 0000755 0001751 0001751 00000000000 10160167720 020051 5 ustar rene rene 0000000 0000000 new_rdpyg/docs/urdpyg/urdpyg/sounds/SoundManager.html 0000644 0001751 0001751 00000021720 10160167721 023325 0 ustar rene rene 0000000 0000000
Class: SoundManager
Table of Contents
| Class: SoundManager
|
urdpyg/sounds.py
|
|
Controls loading, mixing, and playing the sounds.
Having seperate classes allows different groups of sounds to be
loaded, and unloaded from memory easily. Useage:
sm = SoundManager()
sm.Load()
|
Methods
|
|
GetSound
Load
Play
PlayMusic
Stop
StopAll
Update
__init__
_debug
|
|
|
GetSound
|
GetSound ( self, name )
Returns a Sound object for the given name.
|
|
|
Load
|
Load (
self,
sound_list=[],
sound_path=".",
)
Loads sounds.
|
|
|
Play
|
Play (
self,
name,
volume=[ 1.0, 1.0 ],
wait=0,
loop=0,
)
Plays the sound with the given name.
name - of the sound.
volume - left and right. Ranges 0.0 - 1.0
wait - used to control what happens if sound is allready playing:
0 - will not wait if sound playing. play anyway.
1 - if there is a sound of this type playing wait for it.
2 - if there is a sound of this type playing do not play again.
loop - number of times to loop. -1 means forever.
|
|
|
PlayMusic
|
PlayMusic ( self, musicname )
Plays a music track. Only one can be played at a time.
So if there is one playing, it will be stopped and the new
one started.
|
|
|
Stop
|
Stop ( self, name )
|
|
|
StopAll
|
StopAll ( self )
stops all sounds.
|
|
|
Update
|
Update ( self, elapsed_time )
|
|
|
__init__
|
__init__ (
self,
sound_list=SOUND_LIST,
sound_path=SOUND_PATH,
)
|
|
|
_debug
|
_debug (
self,
x,
debug_level=0,
)
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milk_skeleton.html 0000644 0001751 0001751 00000013363 10160167720 022272 0 ustar rene rene 0000000 0000000
Module: milk_skeleton
Table of Contents
| Module: milk_skeleton
|
urdpyg/milk_skeleton.py
|
|
Copyright (C) 2002 by Rene Dudfield.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/__init__.html 0000644 0001751 0001751 00000002652 10160167720 021170 0 ustar rene rene 0000000 0000000
Module: __init__
Table of Contents
| Module: __init__
|
urdpyg/__init__.py
|
|
The unstable part of rdpyg.
Contains modules that are not very well designed, tested, or commented, and
which are not planned to be have the same api stick around for ages.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/gl_images.html 0000644 0001751 0001751 00000010347 10160167720 021360 0 ustar rene rene 0000000 0000000
Module: gl_images
Table of Contents
| Module: gl_images
|
urdpyg/gl_images.py
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/index.html 0000644 0001751 0001751 00000007146 10160167721 020544 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation: urdpyg
Table of Contents
| HappyDoc Generated Documentation: urdpyg
|
|
|
The unstable part of rdpyg.
Contains modules that are not very well designed, tested, or commented, and
which are not planned to be have the same api stick around for ages.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/some_sprites.html 0000644 0001751 0001751 00000021753 10160167720 022150 0 ustar rene rene 0000000 0000000
Module: some_sprites
Table of Contents
| Module: some_sprites
|
urdpyg/some_sprites.py
|
|
file: some_sprites.py
purpose: animation, sprite playing.
|
Imported modules
|
|
import bisect
import glob
import os
import os.path
import pygame
from pygame.locals import *
import sys
import time
|
|
Functions
|
|
animation_factory
get_background_names
get_character_frame_names
load_image
read_anim_data
|
|
|
animation_factory
|
animation_factory ( anim_data, loop=1 )
Returns a dict keyed by anim_name valued by Animation instances.
anim_data - keyed by anim name, valued by a list of tuples(frame_name, length).
loop - passed through to Animation class.
|
|
|
get_background_names
|
get_background_names ( base_dir )
TODO: needs fixing/testing.
|
|
|
get_character_frame_names
|
get_character_frame_names ( the_layer_order, base_dir=".." )
returns a dict keyed by character name, valued by a
dict(keyed by meaningful name, valued by image path name).
|
|
|
load_image
|
load_image (
name,
colorkey=None,
convert_alpha=0,
)
|
|
|
read_anim_data
|
read_anim_data ( character_name, base_dir=".." )
Reads the animation data from the characters anim.py file.
|
|
Classes
|
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/milkviewer4.html 0000644 0001751 0001751 00000005745 10160167720 021701 0 ustar rene rene 0000000 0000000
Module: milkviewer4
Table of Contents
| Module: milkviewer4
|
urdpyg/milkviewer4.py
|
|
Imported modules
|
|
from OpenGL.GL import *
from numeric_gl import *
import pygame
from urdpyg import gl_images
from urdpyg.converters import ms3d_ascii_importer
from urdpyg.milk_skeleton import *
|
|
Classes
|
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/music.html 0000644 0001751 0001751 00000005672 10160167720 020556 0 ustar rene rene 0000000 0000000
Module: music
Table of Contents
| Module: music
|
urdpyg/music.py
|
|
Imported modules
|
|
import config
import glob
import os
import pygame.mixer
import pygame.mixer_music
from rdpyg.util import cyclic_list, vtimer
import sound_config
|
|
Classes
|
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/some_sound.html 0000644 0001751 0001751 00000010463 10160167720 021603 0 ustar rene rene 0000000 0000000
Module: some_sound
Table of Contents
| Module: some_sound
|
urdpyg/some_sound.py
|
|
file: some_sound.py
purpose: to load all the sounds, and manage the playing of them.
Probably have different sets of sounds in here somehow.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/urdpyg/sounds.html 0000644 0001751 0001751 00000011146 10160167721 020743 0 ustar rene rene 0000000 0000000
Module: sounds
Table of Contents
| Module: sounds
|
urdpyg/sounds.py
|
|
file: sounds.py
purpose: to load all the sounds, and manage the playing of them.
Probably have different sets of sounds in here somehow.
NOTE: not using pygames channel queueing as it only allows one sound to be
queued. Also the sound can only be queued on a certain channel.
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/docs/urdpyg/index.html 0000644 0001751 0001751 00000004056 10160167721 017227 0 ustar rene rene 0000000 0000000
HappyDoc Generated Documentation
Table of Contents
| HappyDoc Generated Documentation
|
|
|
|
Table of Contents
This document was automatically generated
on Thu Dec 16 13:15:41 2004 by
HappyDoc version
2.1
new_rdpyg/examples/ 0000755 0001751 0001751 00000000000 10156245512 014601 5 ustar rene rene 0000000 0000000 new_rdpyg/examples/.minimal_gl.py.swp 0000644 0001751 0001751 00000030000 10156245516 020146 0 ustar rene rene 0000000 0000000 b0VIM 6.3 gbÝ@7 *C rene grace /mnt/hdc3/home/rene/dev/mystuff/python/new_rdpyg/examples/minimal_gl.py 3210#"! U tp ÿ ad M ß Þ ´ ¦ ˜ — – | { q h W N M L a.Stop() print a.GetFps() a.Loop() a.Start() a = the_app_gl.TheAppGL() pygame.init() import pygame # We have to initialise pygame ourselves. from rdpyg.app import the_app_gl new_rdpyg/examples/minimal.py 0000644 0001751 0001751 00000000232 10067257511 016601 0 ustar rene rene 0000000 0000000 from rdpyg.app import the_app
# We have to initialise pygame ourselves.
import pygame
pygame.init()
a = the_app.TheApp()
a.Start()
a.Loop()
a.Stop()
new_rdpyg/examples/minimal_gl.py 0000644 0001751 0001751 00000000263 10067261147 017267 0 ustar rene rene 0000000 0000000 from rdpyg.app import the_app_gl
# We have to initialise pygame ourselves.
import pygame
pygame.init()
a = the_app_gl.TheAppGL()
a.Start()
a.Loop()
print a.GetFps()
a.Stop()
new_rdpyg/rdpyg/ 0000755 0001751 0001751 00000000000 10160170501 014076 5 ustar rene rene 0000000 0000000 new_rdpyg/rdpyg/app/ 0000755 0001751 0001751 00000000000 10160420572 014664 5 ustar rene rene 0000000 0000000 new_rdpyg/rdpyg/app/the_app_gl.py 0000755 0001751 0001751 00000010453 10065303172 017346 0 ustar rene rene 0000000 0000000 import the_app
import pygame
from pygame.locals import DOUBLEBUF, OPENGL, FULLSCREEN, QUIT, KEYDOWN, K_ESCAPE
from OpenGL.GL import glMatrixMode, GL_PROJECTION, glLoadIdentity, glClearColor, glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, glGetFloatv, GL_PROJECTION_MATRIX, GL_MODELVIEW, glViewport, glGetDoublev, GL_MODELVIEW_MATRIX
from OpenGL.GLU import gluPerspective, gluUnProject
class TheAppGL(the_app.TheApp):
def Display(self):
""" A default display. Which clears the color buffer and depth buffer.
"""
self._debug("running display", 4)
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
def InitDisplay(self, width, height, first_time = 0):
""" A default InitDisplay.
"""
self._debug("initializing display", 4)
if first_time:
full_display_flags = DOUBLEBUF | OPENGL | FULLSCREEN
display_flags = DOUBLEBUF | OPENGL
if self.full_screen:
if pygame.display.mode_ok((width, height), display_flags ):
self.screen = pygame.display.set_mode((width, height), display_flags)
else:
raise ValueError("error initializing display, can not get mode")
if pygame.display.mode_ok((width, height), full_display_flags ):
self.screen = pygame.display.set_mode((width, height), full_display_flags)
else:
raise ValueError("error initializing display, can not get mode")
else:
if pygame.display.mode_ok((width, height), display_flags ):
self.screen = pygame.display.set_mode((width, height), display_flags)
else:
raise ValueError("error initializing display, can not get mode")
else:
if self.full_screen:
display_flags = DOUBLEBUF | OPENGL | FULLSCREEN
else:
display_flags = DOUBLEBUF | OPENGL
if pygame.display.mode_ok((width, height), display_flags ):
self.screen = pygame.display.set_mode((width, height), display_flags)
else:
raise ValueError("error initializing display, can not get mode")
def Start(self):
""" """
self._debug("starting", 4)
width, height = 640, 480
#width, height = 1024, 768
self.width, self.height = width, height
self.InitDisplay(width, height, first_time = 1)
glViewport(0,0, width, height)
# sets up the projection matrix.
self.SetupProjection(width, height)
self.Load()
def SetupProjection(self, width = 640,
height = 480,
zNear = 5.,
zFar = 300.):
""" Sets up the projection matrix for opengl.
"""
# set the projection transformation
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
#TODO: replace the glu call with something else.
#gluPerspective(45.0, float(width) / height, scale * 50.0, scale * 1000.0)
#gluPerspective(45.0, float(self.width) / float(self.height), 5.0, 1000.0)
self.zNear = zNear
self.zFar = zFar
self.buffer_calc_a = self.zFar / ( self.zFar - self.zNear )
self.buffer_calc_b = self.zFar * self.zNear / ( self.zNear - self.zFar )
gluPerspective(45.0,
float(width) / float(height),
self.zNear,
self.zFar)
self.gl_projection_matrix = glGetFloatv(GL_PROJECTION_MATRIX)
# set the model transformation
glMatrixMode(GL_MODELVIEW)
def GetWorldCoords(self, x,y, camera_z):
""" returns (x,y,z) given x,y pygame screen coords.
NOTE: try and get the model view matrix back to the camera
position when using.
"""
y = self.height - y
mod = glGetDoublev(GL_MODELVIEW_MATRIX)
proj = glGetDoublev(GL_PROJECTION_MATRIX)
#view = glGetIntegerv(GL_VIEWPORT)
view = (0, 0, self.width, self.height)
z = abs(camera_z)
z_buffer_value = self.buffer_calc_a +self.buffer_calc_b / z
objx, objy, objz = gluUnProject(x,y,z_buffer_value, mod, proj,view)
return (objx, objy, objz)
new_rdpyg/rdpyg/app/__init__.py 0000644 0001751 0001751 00000000057 10160167023 016776 0 ustar rene rene 0000000 0000000 """ Common functionality for applications.
"""
new_rdpyg/rdpyg/app/__init__.pyc 0000644 0001751 0001751 00000000246 10160170543 017142 0 ustar rene rene 0000000 0000000 ;ò
îÀAc @ s
d Z d S( s( Common functionality for applications.
N( s __doc__( ( ( s ./rdpyg/app/__init__.pys ? s new_rdpyg/rdpyg/app/the_app.py 0000755 0001751 0001751 00000020622 10160167011 016657 0 ustar rene rene 0000000 0000000 #file: the_app.py
#purpose: a base class for making applications from.
"""
TheApp is a class for making a game like application, implementing
functionality common in many games. The idea is to make constructing games
and demos quick, with minimal code.
TODO: a way to chose between display flip and update. without overriding the
whole method.
There are a number of different methods with default implementations to save
work. Most of these can be overridden if you need to specialise any parts.
= How the main loop works. =
TheApp class has a couple of different ways which it handles the main loop internally. It can use a while loop or the twisted reactor.
However by using the methods provided you should not have to modify this.
It can be instructional to have at a look at the source for different methods, so that overriding them can be easy.
This is the 2d pygame version of the class. There is an opengl version named
rdpyg.app.the_app_gl.TheAppGL
= Commonly overridden methods =
* Display
* Your drawing code.
* Update
* Updating your game logic, game play, and game ai.
* HandleEvents
* Code to handle user input, operating system interaction, and other events.
* Load
* Code to load your game data. Like images, sounds etc.
= Order of operation =
The order in which the different methods get called is to update your game
objects, handle user input, do your display changes.
Start()
InitDislpay()
Load()
Loop()
Before loops starts looping:
LoopInit()
SetupTiming()
Every 'tic' or frame of loop:
Update()
HandleEvents()
DoBeforeDisplay()
Display()
DoAfterFlip()
"""
try:
import config
except:
class blablablabla:
USE_TWISTED = 0
full_screen = 0
config = blablablabla()
import time
import pygame
from pygame.locals import DOUBLEBUF, OPENGL, FULLSCREEN, QUIT, KEYDOWN, K_ESCAPE
# TODO: speed up loading time. this takes 0.2959 to load.
if config.USE_TWISTED:
import twisted.internet.reactor
import traceback
import sys
class TheApp:
"""
An application class to handle lots of common things within games, and
game like applications, using pygame.
A lot of the methods are meant to be overrided. However they all come
with sane default implementations.
Useage:
a = TheApp()
a.Start()
a.Loop()
a.Stop()
"""
def __init__(self, debug_level = 0):
self._debug_level = debug_level
self.frames = 0
self.full_screen = config.full_screen
def _debug(self, x, debug_level = 0):
"""
"""
if self._debug_level > debug_level:
print x
def Display(self):
""" This is called before the display is flipped(or updated).
Your drawing code should go in here.
"""
self._debug("running display", 4)
def InitDisplay(self, width, height, first_time = 0):
""" A default InitDisplay.
first_time - useful for working around some buggy systems.
make it true if this is the first time calling it.
"""
self._debug("initializing display", 4)
if first_time:
full_display_flags = DOUBLEBUF | FULLSCREEN
display_flags = DOUBLEBUF
if self.full_screen:
if pygame.display.mode_ok((width, height), display_flags ):
self.screen = pygame.display.set_mode((width, height), display_flags)
else:
raise ValueError("error initializing display, can not get mode")
if pygame.display.mode_ok((width, height), full_display_flags ):
self.screen = pygame.display.set_mode((width, height), full_display_flags)
else:
raise ValueError("error initializing display, can not get mode")
else:
if pygame.display.mode_ok((width, height), display_flags ):
self.screen = pygame.display.set_mode((width, height), display_flags)
else:
raise ValueError("error initializing display, can not get mode")
else:
if self.full_screen:
display_flags = DOUBLEBUF | FULLSCREEN
else:
display_flags = DOUBLEBUF
if pygame.display.mode_ok((width, height), display_flags ):
self.screen = pygame.display.set_mode((width, height), display_flags)
else:
raise ValueError("error initializing display, can not get mode")
def Stop(self):
""" Called when we want to stop.
"""
pygame.quit()
def Start(self):
""" Do the game loading.
"""
self._debug("starting", 4)
width, height = 640, 480
#width, height = 1024, 768
self.width, self.height = width, height
self.InitDisplay(width, height, first_time = 1)
self.Load()
def Load(self):
""" For loading stuff.
"""
def HandleEvents(self, event_list):
""" should handle the events every game tic.
"""
for event in event_list:
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
self.Stop()
return 0
return 1
def Update(self, elapsed_time):
""" update any game state.
"""
def OneTic(self):
""" Does one game 'tic' worth of stuff.
Should return 1 if not wanting to quit.
If wanting to quit return 0.
"""
try:
self.current_time, self.elapsed_time = self.TicTiming()
if not self.DoBeforeHandlingEvents():
if config.USE_TWISTED:
twisted.internet.reactor.stop()
#self.Stop()
return 0
else:
return 0
self.Update(self.elapsed_time)
event_list = pygame.event.get()
if not self.HandleEvents(event_list):
if config.USE_TWISTED:
twisted.internet.reactor.stop()
#self.Stop()
return 0
else:
return 0
self.DoBeforeDisplay()
self.Display()
#flip_time1 = time.time()
pygame.display.flip()
#flip_time2 = time.time()
#flip_time = flip_time2 - flip_time1
#print "flip_time:", flip_time
self.DoAfterFlip()
self.frames += 1
self.last_time = self.current_time
if config.USE_TWISTED:
# run as fast as it can.
twisted.internet.reactor.callLater(0.0, self.OneTic)
else:
return 1
except:
traceback.print_exc(sys.stderr)
# we have an error, quit instead.
if config.USE_TWISTED:
twisted.internet.reactor.stop()
return 0
def DoAfterFlip(self):
""" Called after flip is done.
"""
def DoBeforeDisplay(self):
""" Stuff done before Display() is called.
"""
def DoBeforeHandlingEvents(self):
""" Stuff done before we handle the events.
Should return 0 to quit.
"""
return 1
def TicTiming(self):
""" Call this once per tic to update the timing.
"""
current_time = time.time()
elapsed_time = current_time - self.last_time
self.total_elapsed_time += elapsed_time
return (current_time, elapsed_time)
def GetFps(self):
""" Returns the frames per second since the timing has begun.
"""
if self.total_elapsed_time == 0:
return 0.
return self.frames/self.total_elapsed_time
def LoopInit(self):
""" Should put use loop initialisation stuff here.
"""
def SetupTiming(self):
""" Sets up some timing code.
"""
self.last_time = time.time()
self.total_elapsed_time = 0.
def Loop(self):
""" Starts the game looping. Will eventually return.
"""
self.LoopInit()
self.SetupTiming()
if config.USE_TWISTED:
twisted.internet.reactor.callLater(0.0, self.OneTic)
twisted.internet.reactor.run()
else:
while 1:
if not self.OneTic():
break
new_rdpyg/rdpyg/app/the_app.pyc 0000644 0001751 0001751 00000023103 10160170546 017023 0 ustar rene rene 0000000 0000000 ;ò
îÀAc @ s¶ d Z y
d k Z Wn# d f d „ ƒ YZ e ƒ Z n Xd k Z d k Z d k l Z l Z l Z l Z l
Z
l Z e i o
d k
Z n d k Z d k Z d f d „ ƒ YZ d S( s4
TheApp is a class for making a game like application, implementing
functionality common in many games. The idea is to make constructing games
and demos quick, with minimal code.
TODO: a way to chose between display flip and update. without overriding the
whole method.
There are a number of different methods with default implementations to save
work. Most of these can be overridden if you need to specialise any parts.
= How the main loop works. =
TheApp class has a couple of different ways which it handles the main loop internally. It can use a while loop or the twisted reactor.
However by using the methods provided you should not have to modify this.
It can be instructional to have at a look at the source for different methods, so that overriding them can be easy.
This is the 2d pygame version of the class. There is an opengl version named
rdpyg.app.the_app_gl.TheAppGL
= Commonly overridden methods =
* Display
* Your drawing code.
* Update
* Updating your game logic, game play, and game ai.
* HandleEvents
* Code to handle user input, operating system interaction, and other events.
* Load
* Code to load your game data. Like images, sounds etc.
= Order of operation =
The order in which the different methods get called is to update your game
objects, handle user input, do your display changes.
Start()
InitDislpay()
Load()
Loop()
Before loops starts looping:
LoopInit()
SetupTiming()
Every 'tic' or frame of loop:
Update()
HandleEvents()
DoBeforeDisplay()
Display()
DoAfterFlip()
Ns blablablablac B s t Z d Z d Z RS( Ni ( s __name__s
__module__s USE_TWISTEDs full_screen( ( ( s ./rdpyg/app/the_app.pys blablablablaD s ( s DOUBLEBUFs OPENGLs
FULLSCREENs QUITs KEYDOWNs K_ESCAPEs TheAppc B s¹ t Z d Z d d „ Z d d „ Z d „ Z d d „ Z d „ Z d „ Z d „ Z d „ Z
d
„ Z d „ Z d „ Z
d
„ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z RS( sN
An application class to handle lots of common things within games, and
game like applications, using pygame.
A lot of the methods are meant to be overrided. However they all come
with sane default implementations.
Useage:
a = TheApp()
a.Start()
a.Loop()
a.Stop()
i c C s" | | _ d | _ t i | _ d S( Ni ( s debug_levels selfs _debug_levels framess configs full_screen( s selfs debug_level( ( s ./rdpyg/app/the_app.pys __init__l s c C s | i | j o | GHn d S( s
N( s selfs _debug_levels debug_levels x( s selfs xs debug_level( ( s ./rdpyg/app/the_app.pys _debugs s c C s | i d d ƒ d S( st This is called before the display is flipped(or updated).
Your drawing code should go in here.
s running displayi N( s selfs _debug( s self( ( s ./rdpyg/app/the_app.pys Display{ s c C sƒ | i d d ƒ | o t t B} t } | i o˜ t i i
| | f | ƒ o" t i i
| | f | ƒ | _ n
t d ƒ ‚ t i i
| | f | ƒ o" t i i
| | f | ƒ | _ qt d ƒ ‚ qt i i
| | f | ƒ o" t i i
| | f | ƒ | _ qt d ƒ ‚ ni | i o t t B} n t } t i i
| | f | ƒ o" t i i
| | f | ƒ | _ n
t d ƒ ‚ d S( s³ A default InitDisplay.
first_time - useful for working around some buggy systems.
make it true if this is the first time calling it.
s initializing displayi s, error initializing display, can not get modeN( s selfs _debugs
first_times DOUBLEBUFs
FULLSCREENs full_display_flagss
display_flagss full_screens pygames displays mode_oks widths heights set_modes screens
ValueError( s selfs widths heights
first_times full_display_flagss
display_flags( ( s ./rdpyg/app/the_app.pys InitDisplay… s*
"""
"c C s t i ƒ d S( s Called when we want to stop.
N( s pygames quit( s self( ( s ./rdpyg/app/the_app.pys Stop½ s c C s^ | i d d ƒ d d f \ } } | | f \ | _ | _ | i | | d d ƒ| i ƒ d S( s Do the game loading.
s startingi i€ ià s
first_timei N( s selfs _debugs widths heights InitDisplays Load( s selfs widths height( ( s ./rdpyg/app/the_app.pys StartÅ s c C s d S( s For loading stuff.
N( ( s self( ( s ./rdpyg/app/the_app.pys LoadÕ s c C s[ xP | D]H } | i t j p | i t j o
| i t j o | i ƒ d Sq q Wd Sd S( s2 should handle the events every game tic.
i i N( s
event_lists events types QUITs KEYDOWNs keys K_ESCAPEs selfs Stop( s selfs
event_lists event( ( s ./rdpyg/app/the_app.pys HandleEventsÚ s 0
c C s d S( s update any game state.
N( ( s selfs elapsed_time( ( s ./rdpyg/app/the_app.pys Updateå s c C s_ y| i ƒ \ | _ | _ | i ƒ o* t i o t i i i
ƒ d SqS d Sn | i | i ƒ t i
i ƒ } | i | ƒ o* t i o t i i i
ƒ d Sq d Sn | i ƒ | i ƒ t i i ƒ | i ƒ | i d 7_ | i | _ t i o t i i i d | i ƒ n d SWn9 t i t i ƒ t i o t i i i
ƒ n d Sn Xd S( sŽ Does one game 'tic' worth of stuff.
Should return 1 if not wanting to quit.
If wanting to quit return 0.
i i f0.0N( s selfs TicTimings current_times elapsed_times DoBeforeHandlingEventss configs USE_TWISTEDs twisteds internets reactors stops Updates pygames events gets
event_lists HandleEventss DoBeforeDisplays Displays displays flips DoAfterFlips framess last_times callLaters OneTics tracebacks print_excs syss stderr( s selfs
event_list( ( s ./rdpyg/app/the_app.pys OneTicë s:
c C s d S( s$ Called after flip is done.
N( ( s self( ( s ./rdpyg/app/the_app.pys DoAfterFlip( s c C s d S( s0 Stuff done before Display() is called.
N( ( s self( ( s ./rdpyg/app/the_app.pys DoBeforeDisplay- s c C s d Sd S( sV Stuff done before we handle the events.
Should return 0 to quit.
i N( ( s self( ( s ./rdpyg/app/the_app.pys DoBeforeHandlingEvents1 s c C s6 t i ƒ } | | i } | i | 7_ | | f Sd S( s6 Call this once per tic to update the timing.
N( s times current_times selfs last_times elapsed_times total_elapsed_time( s selfs elapsed_times current_time( ( s ./rdpyg/app/the_app.pys TicTiming9 s
c C s* | i d j o d Sn | i | i Sd S( sC Returns the frames per second since the timing has begun.
i f0.0N( s selfs total_elapsed_times frames( s self( ( s ./rdpyg/app/the_app.pys GetFpsD s c C s d S( s8 Should put use loop initialisation stuff here.
N( ( s self( ( s ./rdpyg/app/the_app.pys LoopInitN s c C s t i ƒ | _ d | _ d S( s# Sets up some timing code.
f0.0N( s times selfs last_times total_elapsed_time( s self( ( s ./rdpyg/app/the_app.pys SetupTimingS s c C sq | i ƒ | i ƒ t i o- t i i i d | i ƒ t i i i
ƒ n# x n o | i ƒ o PqN qU Wd S( s; Starts the game looping. Will eventually return.
f0.0i N( s selfs LoopInits SetupTimings configs USE_TWISTEDs twisteds internets reactors callLaters OneTics run( s self( ( s ./rdpyg/app/the_app.pys LoopZ s
( s __name__s
__module__s __doc__s __init__s _debugs Displays InitDisplays Stops Starts Loads HandleEventss Updates OneTics DoAfterFlips DoBeforeDisplays DoBeforeHandlingEventss TicTimings GetFpss LoopInits SetupTimings Loop( ( ( s ./rdpyg/app/the_app.pys TheApp[ s&