Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::array<bool, 4> IntersectBoxWithSphere(std::array<const Math::AABB*, 4> boxes, const Physics::Sphere& sphere) const {
- float radius = sphere.radius * sphere.radius;
- __m128 zero = _mm_setzero_ps();
- __m128 radius = _mm_load1_ps(&radius);
- __m128 centerx = _mm_load1_ps(&sphere.origin.x);
- __m128 centery = _mm_load1_ps(&sphere.origin.y);
- __m128 centerz = _mm_load1_ps(&sphere.origin.z);
- __m128 boxminx = _mm_loadu_ps(&box[0]->BottomLeftClosest);
- __m128 boxminy = _mm_loadu_ps(&box[1]->BottomLeftClosest);
- __m128 boxminz = _mm_loadu_ps(&box[2]->BottomLeftClosest);
- __m128 boxmaxx = _mm_loadu_ps(&box[3]->BottomLeftClosest);
- _MM_TRANSPOSE4_PS(boxminx, boxminy, boxminz, boxmaxx);
- boxmaxx = _mm_loadu_ps(&box[0]->TopRightFurthest);
- __m128 boxmaxy = _mm_loadu_ps(&box[1]->TopRightFurthest);
- __m128 boxmaxz = _mm_loadu_ps(&box[2]->TopRightFurthest);
- __m128 temp1x = _mm_loadu_ps(&box[3]->TopRightFurthest);
- _MM_TRANSPOSE4_PS(boxmaxx, boxmaxy, boxmaxz, temp1x);
- // _mm_max_ps(_mm_sub_ps(boxmin, center), zero)
- temp1x = _mm_sub_ps(boxminx, centerx);
- __m128 temp1y = _mm_sub_ps(boxminy, centery);
- __m128 temp1z = _mm_sub_ps(boxminz, centerz);
- temp1x = _mm_max_ps(temp1x, zero);
- temp1y = _mm_max_py(temp1x, zero);
- temp1z = _mm_max_pz(temp1x, zero);
- // _mm_max_ps(_mm_sub_ps(center, boxmin), zero)
- __m128 temp2x = _mm_sub_ps(centerx, boxmaxx);
- __m128 temp2y = _mm_sub_ps(centery, boxmaxy);
- __m128 temp2z = _mm_sub_ps(centerz, boxmaxz);
- temp2x = _mm_max_ps(temp2x, zero);
- temp2y = _mm_max_ps(temp2y, zero);
- temp2z = _mm_max_ps(temp2z, zero);
- __m128 ex = _mm_add_ps(temp1x, temp2x);
- __m128 ey = _mm_add_ps(temp1y, temp2y);
- __m128 ez = _mm_add_ps(temp1z, temp2z);
- __m128 final_e = _mm_add_ps(ex, _mm_add_ps(ez, ey));
- __m128 result = _mm_cmple_ps(final_e, radius);
- float output[4];
- _mm_store_ps(output, result);
- std::array<bool, 4> ret;
- for(int i = 0; i < 4; i++) {
- ret[i] = output[i];
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement