intersectOBB method
Performs a ray/OBB intersection test and stores the intersection point to the given 3D vector. If no intersection is detected, null is returned.
Implementation
Vector3? intersectOBB(OBB obb, Vector3 result ) {
// the idea is to perform the intersection test in the local space
// of the OBB.
obb.getSize( size );
aabb.fromCenterAndSize( v1.set( 0, 0, 0 ), size );
matrix.fromMatrix3( obb.rotation );
matrix.setPosition( obb.center );
// transform ray to the local space of the OBB
_localRay.copy( this ).applyMatrix4( matrix.getInverse( inverse ) );
// perform ray <-> AABB intersection test
if ( _localRay.intersectAABB( aabb, result ) != null) {
// transform the intersection point back to world space
return result.applyMatrix4( matrix );
}
else {
return null;
}
}