CBB.intersectCBB()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 12
rs 9.4285
1
from ed2d.physics.collisiondata import*
2
from gem import vector
3
4
# Circle Bounding Box
5
class CBB(object):
6
7
    def __init__(self, radius, center):
8
        '''Creates a circle bounding box object to be used with the physics engine. Takes in a float for the radius and an array for the center.'''
9
        self.radius = radius
10
        self.center = vector.Vector(3, data=center)
11
12
    def intersectCBB(self, oCBB):
13
        tempDistance = self.center - oCBB.center
14
        distanceCenters = tempDistance.magnitude()
15
        distanceRadii = self.radius + oCBB.radius
16
17
        # Collision happens when the distance between the two centers is less than the sum of the radii
18
        state = distanceCenters < distanceRadii
19
20
        # Calculate the depth penetration
21
        depthPenetration = distanceCenters - (distanceRadii)
22
23
        return CollisionData(state, tempDistance, depthPenetration)
24
25
    def getCenter(self):
26
        return self.center
27
28
    def getRadius(self):
29
        return self.radius
30