~codeforger/pypal/docs

« back to all changes in this revision

Viewing changes to pypal/geometry/convex.py

  • Committer: Michael Rochester
  • Date: 2014-07-14 13:56:54 UTC
  • Revision ID: m.rochester93@googlemail.com-20140714135654-wnomyvcyicfwukeo
added convex geometry

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from pypal import private_globals as pal
 
1
from pypal import private_globals as _pal
2
2
import ctypes as c
3
3
import weakref
4
 
from geometry_base import GeometryBase
5
 
class Convex(GeometryBase):
6
 
    typechar = 'x'
7
 
    """a geometry that represents a convex shape"""
8
 
    def __init__(self, rect, rotation = [0,0,0],points=((0,0,0)),mass=1):
9
 
        """
10
 
        constructs a convex shape
11
 
        
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.
17
 
        """
18
 
 
 
4
class Convex(_pal.PalObject):
 
5
    def __init__(self, pos, points, triangles=None, mass = 1.):
19
6
        CPoints = c.c_float * (len(points) * 3)
20
7
        cpoints = CPoints()
21
8
        for i in xrange(len(points)):
22
9
            for j in xrange(3):
23
10
                cpoints[(i*3)+j] = points[i][j]
24
 
 
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))
 
11
        if triangles==None:
 
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))
 
14
        else:
 
15
            CTris = c.c_int * len(triangles*3)
 
16
            ctris = CTris()
 
17
            for i in xrange(len(triangles)):
 
18
                for j in xrange(3):
 
19
                    ctris[(i*3)+j] = triangles[i][j]
 
20
 
 
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))
 
23
 
 
24
        self.points = points
 
25
 
 
26
 
 
27
    def delete(self):
 
28
        _pal.lib.geometry_convex_remove(self.obj)
 
29
        del _pal.all_objects[str(self.obj)]
 
30
 
 
31
    def get_location(self):
 
32
        ret = _pal.Mat4x4()
 
33
        _pal.lib.geometry_convex_get_location(self.obj, ret)
 
34
        return [x for x in ret]
 
35
 
 
36
    def get_offsett(self):
 
37
        ret = _pal.Mat4x4()
 
38
        _pal.lib.geometry_convex_get_offsett(self.obj, ret)
 
39
        return [x for x in ret]
 
40
 
 
41
    def get_position(self):
 
42
        ret = _pal.Vec3()
 
43
        _pal.lib.geometry_convex_get_position(self.obj, ret)
 
44
        return [x for x in ret]
 
45
 
 
46
    def set_margin(self, margin):
 
47
        _pal.lib.geometry_convex_set_margin(self.obj, c.c_float(margin))
 
48
 
 
49
    def get_margin(self):
 
50
        _pal.lib.geometry_convex_get_margin.restype = c.c_float
 
51
        return _pal.lib.geometry_convex_get_margin(self.obj)
 
52
 
 
53
    def set_mass(self, mass):
 
54
        _pal.lib.geometry_convex_set_mass(self.obj, c.c_float(mass))
 
55
 
 
56
    def get_mass(self):
 
57
        _pal.lib.geometry_convex_get_mass.restype = c.c_float
 
58
        return _pal.lib.geometry_convex_get_mass(self.obj)
27
59