4
4
from body import Body
5
5
class Compound(Body):
6
""" A Rigid Body With No Initial Geometry """
6
7
def __init__(self, pos):
8
constructs a compound and adds it to the world
10
pos: a 3 part tuple with x,y,z.
11
size: a 3 part tuple with width, height, depth
12
mass: the mass of the object, if mass is specified it will be used.
10
pos: ``float[3]`` The x, y, z position of the Compound body.
14
12
self.obj = _pal.lib.body_compound_create(c.c_float(pos[0]),c.c_float(pos[1]),c.c_float(pos[2]))
15
13
self._body_base = _pal.lib.cast_compound_body_base(self.obj)
19
17
x, y, z = self.get_position()
20
18
return "A CompoundBody at : %.2f, %.2f, %.2f" % (x, y, z)
22
def add_box(self,pos,mass,rotation=(0,0,0)):
23
"""adds a box geometry to the compound body"""
20
def add_box(self, pos, mass=1.,rotation=(0,0,0)):
22
Adds a box geometry to the compound body.
25
pos: ``float[3]`` The x, y, z, positional offsett for the new geometry
26
mass: ``float`` The mass of the new geometry
24
28
_pal.lib.body_compound_add_box(self.obj, c.c_float(pos[0]), c.c_float(pos[1]), c.c_float(pos[2]), c.c_float(rotation[0]), c.c_float(rotation[1]), c.c_float(rotation[2]), c.c_float(pos[3]), c.c_float(pos[4]), c.c_float(pos[5]),c.c_float(mass))
26
def add_sphere(self,pos,mass,rotation=(0,0,0)):
27
"""adds a sphere geometry to the compound body"""
30
def add_sphere(self, pos, mass=1.,rotation=(0,0,0)):
32
Adds a sphere geometry to the compound body.
35
pos: ``float[3]`` The x, y, z, positional offsett for the new geometry
36
mass: ``float`` The mass of the new geometry
28
38
_pal.lib.body_compound_add_sphere(self.obj, c.c_float(pos[0]), c.c_float(pos[1]), c.c_float(pos[2]), c.c_float(rotation[0]), c.c_float(rotation[1]), c.c_float(rotation[2]), c.c_float(pos[3]),c.c_float(mass))
30
def add_capsule(self,pos,mass,rotation=(0,0,0)):
31
"""adds a sphere geometry to the compound body"""
40
def add_capsule(self, pos, mass=1.,rotation=(0,0,0)):
42
Adds a sphere geometry to the compound body.
45
pos: ``float[3]`` The x, y, z, positional offsett for the new geometry
46
mass: ``float`` The mass of the new geometry
32
48
_pal.lib.body_compound_add_capsule(self.obj, c.c_float(pos[0]), c.c_float(pos[1]), c.c_float(pos[2]), c.c_float(rotation[0]), c.c_float(rotation[1]), c.c_float(rotation[2]), c.c_float(pos[3]), c.c_float(pos[4]),c.c_float(mass))
34
def add_convex(self,pos,points,mass,rotation=(0,0,0)):
35
"""adds a sphere geometry to the compound body"""
50
def add_convex(self, pos, points, mass=1., rotation=(0,0,0)):
52
Adds a sphere geometry to the compound body.
55
pos: ``float[3]`` The x, y, z, positional offsett for the new geometry
56
mass: ``float`` The mass of the new geometry
36
58
CPoints = c.c_float * (len(points) * 3)
37
59
cpoints = CPoints()
38
60
for i in xrange(len(points)):