a faster funtion to transform aabb
This commit is contained in:
parent
65d1b0b427
commit
e7febd72d6
@ -154,22 +154,29 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ AABB Transform::xform(const AABB &p_aabb) const {
|
_FORCE_INLINE_ AABB Transform::xform(const AABB &p_aabb) const {
|
||||||
/* define vertices */
|
|
||||||
Vector3 x = basis.get_axis(0) * p_aabb.size.x;
|
/* http://dev.theomader.com/transform-bounding-boxes/ */
|
||||||
Vector3 y = basis.get_axis(1) * p_aabb.size.y;
|
Vector3 min = p_aabb.position;
|
||||||
Vector3 z = basis.get_axis(2) * p_aabb.size.z;
|
Vector3 max = p_aabb.position + p_aabb.size;
|
||||||
Vector3 pos = xform(p_aabb.position);
|
Vector3 tmin, tmax;
|
||||||
//could be even further optimized
|
for (int i = 0; i < 3; i++) {
|
||||||
AABB new_aabb;
|
tmin[i] = tmax[i] = origin[i];
|
||||||
new_aabb.position = pos;
|
for (int j = 0; j < 3; j++) {
|
||||||
new_aabb.expand_to(pos + x);
|
real_t e = basis[i][j] * min[j];
|
||||||
new_aabb.expand_to(pos + y);
|
real_t f = basis[i][j] * max[j];
|
||||||
new_aabb.expand_to(pos + z);
|
if (e < f) {
|
||||||
new_aabb.expand_to(pos + x + y);
|
tmin[i] += e;
|
||||||
new_aabb.expand_to(pos + x + z);
|
tmax[i] += f;
|
||||||
new_aabb.expand_to(pos + y + z);
|
} else {
|
||||||
new_aabb.expand_to(pos + x + y + z);
|
tmin[i] += f;
|
||||||
return new_aabb;
|
tmax[i] += e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AABB r_aabb;
|
||||||
|
r_aabb.position = tmin;
|
||||||
|
r_aabb.size = tmax - tmin;
|
||||||
|
return r_aabb;
|
||||||
}
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const {
|
_FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const {
|
||||||
|
Loading…
Reference in New Issue
Block a user