1
from pypal import private_globals as pal
1
from pypal import private_globals as _pal
4
from geometry_base import GeometryBase
5
class Convex(GeometryBase):
7
"""a geometry that represents a convex shape"""
8
def __init__(self, rect, rotation = [0,0,0],points=((0,0,0)),mass=1):
10
constructs a convex shape
12
points: A set of vertices, which describe the location of corners in an object.
13
rect: a 6 part tuple with x,y,z,width,height,depth.
14
mass: the mass of the object, if mass is specified it will be used.
15
density: if no mass is specified and a density is, the mass will be
16
calculated from the density and the volumne.
4
class Convex(_pal.PalObject):
5
def __init__(self, pos, points, triangles=None, mass = 1.):
19
6
CPoints = c.c_float * (len(points) * 3)
21
8
for i in xrange(len(points)):
23
10
cpoints[(i*3)+j] = points[i][j]
25
self.obj = pal.lib.create_geometry_box(c.c_float(rect[0]),c.c_float(rect[1]),c.c_float(rect[2]),c.c_float(rotation[0]),c.c_float(rotation[1]),c.c_float(rotation[2]),
26
c.pointer(cpoints),len(points)*3,c.c_float(mass))
12
self.obj = _pal.lib.geometry_convex_create_no_triangles(c.c_float(pos[0]), c.c_float(pos[1]), c.c_float(pos[2]),
13
c.pointer(cpoints),len(points)*3,c.c_float(mass))
15
CTris = c.c_int * len(triangles*3)
17
for i in xrange(len(triangles)):
19
ctris[(i*3)+j] = triangles[i][j]
21
self.obj = _pal.lib.geometry_convex_create_triangles(c.c_float(pos[0]), c.c_float(pos[1]), c.c_float(pos[2]),
22
c.pointer(cpoints),len(points)*3, c.pointer(ctris), len(triangles)*3,c.c_float(mass))
28
_pal.lib.geometry_convex_remove(self.obj)
29
del _pal.all_objects[str(self.obj)]
31
def get_location(self):
33
_pal.lib.geometry_convex_get_location(self.obj, ret)
34
return [x for x in ret]
36
def get_offsett(self):
38
_pal.lib.geometry_convex_get_offsett(self.obj, ret)
39
return [x for x in ret]
41
def get_position(self):
43
_pal.lib.geometry_convex_get_position(self.obj, ret)
44
return [x for x in ret]
46
def set_margin(self, margin):
47
_pal.lib.geometry_convex_set_margin(self.obj, c.c_float(margin))
50
_pal.lib.geometry_convex_get_margin.restype = c.c_float
51
return _pal.lib.geometry_convex_get_margin(self.obj)
53
def set_mass(self, mass):
54
_pal.lib.geometry_convex_set_mass(self.obj, c.c_float(mass))
57
_pal.lib.geometry_convex_get_mass.restype = c.c_float
58
return _pal.lib.geometry_convex_get_mass(self.obj)