MeshLib Documentation
Loading...
Searching...
No Matches
MRRayBoxIntersection2.h
Go to the documentation of this file.
1#pragma once
2#include "MRBox.h"
4
5namespace MR
6{
7
8template<typename T>
9bool rayBoxIntersect( const Box2<T>& box, const Vector2<T> & rayOrigin, T & t0, T & t1, const IntersectionPrecomputes2<T>& prec )
10{
11 const Vector2i& sign = prec.sign;
12
13 // compare and update x-dimension with t0-t1
14 t1 = std::min( (box[sign.x].x - rayOrigin.x) * prec.invDir.x, t1 );
15 t0 = std::max( (box[1 - sign.x].x - rayOrigin.x) * prec.invDir.x, t0 );
16
17 // compare and update y-dimension with t0-t1
18 t1 = std::min( (box[sign.y].y - rayOrigin.y) * prec.invDir.y, t1 );
19 t0 = std::max( (box[1 - sign.y].y - rayOrigin.y) * prec.invDir.y, t0 );
20
21 return t0 <= t1;
22}
23
24template <typename T = float>
25bool rayBoxIntersect( const Box2<T>& box, const Line2<T>& line, T t0, T t1 )
26{
27 IntersectionPrecomputes2<T> prec( line.d );
28 return rayBoxIntersect( box, line, t0, t1, prec );
29}
30
31}
bool rayBoxIntersect(const Box3< T > &box, const RayOrigin< T > &rayOrigin, T &t0, T &t1, const IntersectionPrecomputes< T > &prec)
Definition MRRayBoxIntersection.h:63
Definition MRCameraOrientationPlugin.h:8
Box given by its min- and max- corners.
Definition MRMesh/MRBox.h:25
Definition MRMesh/MRMeshFwd.h:508
Vector2i sign
stores signs of direction vector;
Definition MRIntersectionPrecomputes2.h:44
Vector2< T > invDir
Definition MRIntersectionPrecomputes2.h:37
Definition MRVector2.h:18
T x
Definition MRVector2.h:24
T y
Definition MRVector2.h:24