20#if defined(__x86_64__) || defined(_M_X64)
22struct RayOrigin<float>
31inline bool rayBoxIntersect(
const Box3f& box,
const RayOrigin<float> & rayOrigin,
float & t0,
float & t1,
const IntersectionPrecomputes<float>& prec )
33 __m128 l = _mm_set_ps( box.min.x, box.min.y, box.min.z, t0 );
34 __m128 r = _mm_set_ps( box.max.x, box.max.y, box.max.z, t1 );
35 l = _mm_sub_ps( l, rayOrigin.p );
36 r = _mm_sub_ps( r, rayOrigin.p );
37 l = _mm_mul_ps( l, prec.invDir );
38 r = _mm_mul_ps( r, prec.invDir );
40 __m128 a = _mm_min_ps( l, r );
41 __m128 b = _mm_max_ps( l, r );
43 __m128 aa = _mm_movehl_ps( a, a );
44 aa = _mm_max_ps( aa, a );
45 __m128 aaa = _mm_shuffle_ps( aa, aa, 1 );
46 aaa = _mm_max_ss( aaa, aa );
47 t0 = _mm_cvtss_f32( aaa );
49 __m128 bb = _mm_movehl_ps( b, b );
50 bb = _mm_min_ps( bb, b );
51 __m128 bbb = _mm_shuffle_ps( bb, bb, 1 );
52 bbb = _mm_min_ss( bbb, bb );
53 t1 = _mm_cvtss_f32( bbb );
58 #pragma message("rayBoxIntersect: no hardware optimized instructions")
67 t1 = std::min( (box[sign.
x].x - rayOrigin.p.x) * prec.
invDir.x, t1 );
68 t0 = std::max( (box[1 - sign.
x].x - rayOrigin.p.x) * prec.
invDir.x, t0 );
71 t1 = std::min( (box[sign.
y].y - rayOrigin.p.y) * prec.
invDir.y, t1 );
72 t0 = std::max( (box[1 - sign.
y].y - rayOrigin.p.y) * prec.
invDir.y, t0 );
75 t1 = std::min( (box[sign.
z].z - rayOrigin.p.z) * prec.
invDir.z, t1 );
76 t0 = std::max( (box[1 - sign.
z].z - rayOrigin.p.z) * prec.
invDir.z, t0 );
80template <
typename T =
float>
Box given by its min- and max- corners.
Definition MRBox3.h:8
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
Vector3i sign
stores signs of direction vector;
Definition MRIntersectionPrecomputes.h:126
Vector3< T > invDir
Definition MRIntersectionPrecomputes.h:118
bool rayBoxIntersect(const Box3< T > &box, const RayOrigin< T > &rayOrigin, T &t0, T &t1, const IntersectionPrecomputes< T > &prec)
Definition MRRayBoxIntersection.h:62
Definition MRCameraOrientationPlugin.h:8
Box given by its min- and max- corners.
Definition MRMesh/MRBox.h:25
Definition MRMesh/MRMeshFwd.h:373
Definition MRRayBoxIntersection.h:14
RayOrigin(const Vector3< T > &ro)
Definition MRRayBoxIntersection.h:16
Vector3< T > p
Definition MRRayBoxIntersection.h:15
Definition MRMesh/MRVector3.h:19
T x
Definition MRMesh/MRVector3.h:25
T y
Definition MRMesh/MRVector3.h:25
T z
Definition MRMesh/MRVector3.h:25