| Total Complexity | 4 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| 1 | from ed2d.physics.collisiondata import* |
||
| 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 |