summaryrefslogtreecommitdiff
path: root/cad/src/experimental/oleksandr/psurface.pyx
blob: ecfe6cdb446753b0be3e76c6ea784c34b99ce09e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright 2006-2007 Nanorex, Inc.  See LICENSE file for details. 
cdef extern from "csurface.h":
    void cAdd(double x, double y, double z, double r, int p)
    void cCreateSurface()
    void cCollisionDetection(double delta)
    void cAllocate()
    void cFree()
    int cNp()
    int cNt()
    double cPx(int i)
    double cPy(int i)
    double cPz(int i)
    double cNx(int i)
    double cNy(int i)
    double cNz(int i)
    int cC(int i)
    int cI(int i)
    void cLevel(int i)
    int cType()
    void cMethod(int m)
def CreateSurface(spheres,level,method):
    cAllocate()
    for s in spheres:
        cAdd(s[0],s[1],s[2],s[3],s[4])
    cLevel(level)
    cMethod(method)
    cCreateSurface()
    points = []
    normals = []
    colors = []
    for i in range(cNp()):
        points.append((cPx(i),cPy(i),cPz(i)))
        normals.append((cNx(i),cNy(i),cNz(i)))
        colors.append(cC(i)) 
    entities = []
    if cType() == 0 :
        for i in range(cNt() / 3):
            entities.append((cI(3*i),cI(3*i+1),cI(3*i+2)))
    else:
        for i in range(cNt() / 4):
            entities.append((cI(4*i),cI(4*i+1),cI(4*i+2),cI(4*i+3)))
    cFree()
    return ((entities, points, colors), normals)
def CollisionDetection(spheres,level,method,delta):    
    cAllocate()
    for s in spheres:
        cAdd(s[0],s[1],s[2],s[3],s[4])
    cLevel(level)
    cMethod(method)
    cCollisionDetection(delta)
    points = []
    normals = []
    colors = []
    for i in range(cNp()):
        points.append((cPx(i),cPy(i),cPz(i)))
        normals.append((cNx(i),cNy(i),cNz(i)))
        colors.append(cC(i)) 
    entities = []
    if cType() == 0 :
        for i in range(cNt() / 3):
            entities.append((cI(3*i),cI(3*i+1),cI(3*i+2)))
    else:
        for i in range(cNt() / 4):
            entities.append((cI(4*i),cI(4*i+1),cI(4*i+2),cI(4*i+3)))
    return ((entities, points, colors), normals)