//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2017 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// #pragma once #include "Prerequisites/BsPrerequisitesUtil.h" #include "Math/BsVector4.h" #include "Math/BsAABox.h" #include "Math/BsSphere.h" #define SIMDPP_ARCH_X86_SSE4_1 #if BS_COMPILER == BS_COMPILER_MSVC #pragma warning(disable: 4244) #endif #include "ThirdParty/simdpp/simd.h" #if BS_COMPILER == BS_COMPILER_MSVC #pragma warning(default: 4244) #endif namespace bs { namespace simd { using namespace simdpp; /** @addtogroup Math * @{ */ /** * Version of bs::AABox suitable for SIMD use. Takes up a bit more memory than standard AABox and is always 16-byte * aligned. */ struct AABox { /** Center of the bounds, W component unused. */ SIMDPP_ALIGN(16) Vector4 center; /** Extents (half-size) of the bounds, W component unused. */ SIMDPP_ALIGN(16) Vector4 extents; AABox() { } /** Initializes bounds from an AABox. */ AABox(const bs::AABox& box) { center = Vector4(box.getCenter()); extents = Vector4(box.getHalfSize()); } /** Initializes bounds from a Sphere. */ AABox(const Sphere& sphere) { center = Vector4(sphere.getCenter()); float radius = sphere.getRadius(); extents = Vector4(radius, radius, radius, 0.0f); } /** Initializes bounds from a vector representing the center and equal extents in all directions. */ AABox(const Vector3& center, float extent) { this->center = Vector4(center); extents = Vector4(extent, extent, extent, 0.0f); } /** Returns true if the current bounds object intersects the provided object. */ bool intersects(const AABox& other) const { auto myCenter = load(¢er); auto otherCenter = load(&other.center); float32x4 diff = abs(sub(myCenter, otherCenter)); auto myExtents = simd::load(&extents); auto otherExtents = simd::load(&other.extents); float32x4 extents = add(myExtents, otherExtents); return test_bits_any(bit_cast(cmp_gt(diff, extents))) == false; } }; /** @} */ } }