Skip to content

Commit

Permalink
not sure if this is the correct way to transform aabb2
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlokorte committed Jul 6, 2013
1 parent fd25c38 commit 2b9ae90
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/src/vector_math/aabb2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,43 @@ class Aabb2 {
o._max.setFrom(_max);
}

Aabb2 transform(Matrix2 T) {
Vector2 center = new Vector2.zero();
Vector2 halfExtents = new Vector2.zero();
copyCenterAndHalfExtents(center, halfExtents);
T.transform(center);
T.absolute().transform(halfExtents);
_min.setFrom(center);
_max.setFrom(center);

_min.sub(halfExtents);
_max.add(halfExtents);
return this;
}

Aabb2 rotate(Matrix2 T) {
Vector2 center = new Vector2.zero();
Vector2 halfExtents = new Vector2.zero();
copyCenterAndHalfExtents(center, halfExtents);
T.absolute().transform(halfExtents);
_min.setFrom(center);
_max.setFrom(center);

_min.sub(halfExtents);
_max.add(halfExtents);
return this;
}

Aabb2 transformed(Matrix2 T, Aabb2 out) {
out.copyFrom(this);
return out.transform(T);
}

Aabb2 rotated(Matrix2 T, Aabb2 out) {
out.copyFrom(this);
return out.rotate(T);
}

/// Set the min and max of [this] so that [this] is a hull of [this] and [other].
void hull(Aabb2 other) {
min.x = Math.min(_min.x, other.min.x);
Expand Down

0 comments on commit 2b9ae90

Please sign in to comment.