MeshLib C++ Docs
Loading...
Searching...
No Matches
MRRayBoxIntersection2.h
Go to the documentation of this file.
1#pragma once
2#include "MRBox.h"
4
5namespace MR
6{
9
10
11template<typename T>
12bool rayBoxIntersect( const Box2<T>& box, const Vector2<T> & rayOrigin, T & t0, T & t1, const IntersectionPrecomputes2<T>& prec )
13{
14 const Vector2i& sign = prec.sign;
15
17 t1 = std::min( (box[sign.x].x - rayOrigin.x) * prec.invDir.x, t1 );
18 t0 = std::max( (box[1 - sign.x].x - rayOrigin.x) * prec.invDir.x, t0 );
19
21 t1 = std::min( (box[sign.y].y - rayOrigin.y) * prec.invDir.y, t1 );
22 t0 = std::max( (box[1 - sign.y].y - rayOrigin.y) * prec.invDir.y, t0 );
23
24 return t0 <= t1;
25}
26
27template <typename T = float>
28bool rayBoxIntersect( const Box2<T>& box, const Line2<T>& line, T t0, T t1 )
29{
30 IntersectionPrecomputes2<T> prec( line.d );
31 return rayBoxIntersect( box, line.p, t0, t1, prec );
32}
33
34}
bool rayBoxIntersect(const Box3< T > &box, const RayOrigin< T > &rayOrigin, T &t0, T &t1, const IntersectionPrecomputes< T > &prec)
Definition MRRayBoxIntersection.h:36
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRIntersectionPrecomputes2.h:35
Vector2i sign
stores signs of direction vector;
Definition MRIntersectionPrecomputes2.h:44
Vector2< T > invDir
{1 / dir}
Definition MRIntersectionPrecomputes2.h:37
Definition MRVector2.h:29
T x
Definition MRVector2.h:35
T y
Definition MRVector2.h:35