|
@@ 118-142 (lines=25) @@
|
| 115 |
|
self.halfDims = vector.Vector(3, data=[w / 2.0, h / 2.0, 0.0]) |
| 116 |
|
self.rotation = rotation |
| 117 |
|
|
| 118 |
|
def getFurthestPoint(self, direction): |
| 119 |
|
halfWidth = vector.Vector(3).right() * self.halfDims.vector[0] |
| 120 |
|
halfHeight = vector.Vector(3).up() * self.halfDims.vector[1] |
| 121 |
|
|
| 122 |
|
direction4 = vector.Vector(4, data=[direction.vector[0], direction.vector[1], direction.vector[2], 1.0]) |
| 123 |
|
|
| 124 |
|
vertices = [] |
| 125 |
|
vertices.append( halfWidth + halfHeight) |
| 126 |
|
vertices.append(-halfWidth + halfHeight) |
| 127 |
|
vertices.append(-halfWidth - halfHeight) |
| 128 |
|
vertices.append( halfWidth - halfHeight) |
| 129 |
|
|
| 130 |
|
translation = matrix.Matrix(4).translate(vector.Vector(4, data=[self.center.vector[0], self.center.vector[1], self.center.vector[2], 1.0])) |
| 131 |
|
world = self.rotation * translation |
| 132 |
|
|
| 133 |
|
furtherPoint = world * vector.Vector(4, data=[vertices[0].vector[0], vertices[0].vector[1], vertices[0].vector[2], 1.0]) |
| 134 |
|
|
| 135 |
|
maxDot = furtherPoint.dot(direction4) |
| 136 |
|
for i in range(1, 4, 1): |
| 137 |
|
vertex = world * vector.Vector(4, data=[vertices[i].vector[0], vertices[i].vector[1], vertices[i].vector[2], 1.0]) |
| 138 |
|
dot = vertex.dot(direction4) |
| 139 |
|
if(dot > maxDot): |
| 140 |
|
maxDot = dot |
| 141 |
|
furtherPoint = vertex |
| 142 |
|
return vector.Vector(3, data=[furtherPoint.vector[0], furtherPoint.vector[1], furtherPoint.vector[2]]) |
| 143 |
|
|
| 144 |
|
class Box(object): |
| 145 |
|
def __init__(self, center, w, h ,d , rotation): |
|
@@ 87-110 (lines=24) @@
|
| 84 |
|
bV = self.barycentric(a, b, c, p) |
| 85 |
|
return (bV[1] >= 0.0) and (bV[2] >= 0.0) and ((bV[1] + bV[2]) <= 1.0) |
| 86 |
|
|
| 87 |
|
def getFurthestPoint(self, direction): |
| 88 |
|
midBase = vector.Vector(3).right() * self.thirdDims.vector[0] |
| 89 |
|
midHeight = vector.Vector(3).up() * self.thirdDims.vector[1] |
| 90 |
|
|
| 91 |
|
direction4 = vector.Vector(4, data=[direction.vector[0], direction.vector[1], direction.vector[2], 1.0]) |
| 92 |
|
|
| 93 |
|
vertices = [] |
| 94 |
|
vertices.append( self.center.vector[1], midHeight) |
| 95 |
|
vertices.append( midBase, -midHeight) |
| 96 |
|
vertices.append(-midBase, -midHeight) |
| 97 |
|
|
| 98 |
|
translation = matrix.Matrix(4).translate(vector.Vector(4, data=[self.center.vector[0], self.center.vector[1], self.center.vector[2], 1.0])) |
| 99 |
|
world = self.rotation * translation |
| 100 |
|
|
| 101 |
|
furtherPoint = world * vector.Vector(4, data=[vertices[0].vector[0], vertices[0].vector[1], vertices[0].vector[2], 1.0]) |
| 102 |
|
|
| 103 |
|
maxDot = furtherPoint.dot(direction4) |
| 104 |
|
for i in range(1, 3, 1): |
| 105 |
|
vertex = world * vector.vector(4, data=[vertices[i].vector[0], vertices[i].vector[1], vertices[i].vector[2], 1.0]) |
| 106 |
|
dot = vertex.dot(direction4) |
| 107 |
|
if(dot > maxDot): |
| 108 |
|
maxDot = dot |
| 109 |
|
furtherPoint = vertex |
| 110 |
|
return vector.Vector(3, data=[furtherPoint.vector[0], furtherPoint.vector[1], furtherPoint.vector[2]]) |
| 111 |
|
|
| 112 |
|
class Rectangle(object): |
| 113 |
|
def __init__(self, center, w, h, rotation): |