cModel.translate()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 9
rs 9.6666
1
class cModel(object):
2
3
    def __init__(self, obj):
4
        # The following need to be "overwritten" by
5
        # by the object class.. ie. rectangle or circle in case of 2D
6
        self.object = obj
7
        self.type = obj.getType()
8
        self.cmodel = obj.getCollisionData()
9
10
    def intersect(self, cother):
11
        '''Check interesection between two colliders'''
12
        if self.type == "AABB" and cother.getType() == "AABB":
13
            # The following interesection test is for a AABBB
14
            # The AABB has only 4 edges to check against
15
            # This intersection function will be called by physics engine via physics object
16
            # It returns a collisiondata object
17
            # It will contains, direction, distance and state
18
            for i in range(4):
19
                for j in range(4):
20
                    ctemp = self.cmodel[i].IntersectAABB(cother.getCModel()[j])
21
                    if ctemp.getState():
22
                        print('Collision:', 'Dist:', ctemp.getDistance(), 'Dir:', ctemp.getDirection().vector)
23
        else:
24
            return NotImplemented
25
26
    def translate(self, translation):
27
        # This function is best called before interesction is used
28
        # For now it takes in a vector of any size but it will only use X and Y
29
        # If there is not translation then it doesn't make any sense to even update the matrix
30
        if (translation.vector[0] != 0.0 and translation.vector[1] != 0.0):
31
            self.object.translate(translation.vector[0], translation.vector[1])
32
            self.object.update()
33
34
        self.cmodel = self.object.getCollisionData()
35
36
    def getCenter(self):
37
        return self.object.getCenter()
38
39
    def getModel(self):
40
        return self.object
41
42
    def getCModel(self):
43
        return self.cmodel
44
45
    def getType(self):
46
        return self.type
47