KiCad PCB EDA Suite
RAY Struct Reference

#include <ray.h>

Public Member Functions

void Init (const SFVEC3F &o, const SFVEC3F &d)
 
bool IntersectSphere (const SFVEC3F &aCenter, float aRadius, float &aOutT0, float &aOutT1) const
 
SFVEC3F at (float t) const
 
SFVEC2F at2D (float t) const
 

Public Attributes

SFVEC3F m_Origin
 
unsigned int rayID
 unique ray ID - not used - dummy More...
 
SFVEC3F m_Dir
 
RAY_CLASSIFICATION m_Classification
 
SFVEC3F m_InvDir
 
float ibyj
 
float jbyi
 
float kbyj
 
float jbyk
 
float ibyk
 
float kbyi
 
float c_xy
 
float c_xz
 
float c_yx
 
float c_yz
 
float c_zx
 
float c_zy
 
unsigned int m_dirIsNeg [3]
 

Detailed Description

Definition at line 67 of file ray.h.

Member Function Documentation

◆ at()

◆ at2D()

SFVEC2F RAY::at2D ( float  t) const
inline

Definition at line 91 of file ray.h.

92  {
93  return SFVEC2F( m_Origin.x + m_Dir.x * t, m_Origin.y + m_Dir.y * t );
94  }
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
SFVEC3F m_Dir
Definition: ray.h:72
SFVEC3F m_Origin
Definition: ray.h:69

References m_Dir, and m_Origin.

◆ Init()

void RAY::Init ( const SFVEC3F o,
const SFVEC3F d 
)

Definition at line 41 of file ray.cpp.

42 {
43  m_Origin = o;
44  m_Dir = d;
45  m_InvDir = 1.0f / d;
46 
47  rayID = 0; // Not used, just set to 0
48  //rayID = gs_next_rayID;
49  //gs_next_rayID++;
50 
51  // An Efficient and Robust Ray–Box Intersection Algorithm
52  // Amy Williams Steve Barrus R. Keith Morley Peter Shirley
53  // University of Utah
54  // http://people.csail.mit.edu/amy/papers/box-jgt.pdf
55  m_dirIsNeg[0] = m_Dir.x < 0.0f;
56  m_dirIsNeg[1] = m_Dir.y < 0.0f;
57  m_dirIsNeg[2] = m_Dir.z < 0.0f;
58 
59  // ray slope
60 
61  // "Fast Ray / Axis-Aligned Bounding Box Overlap Tests using Ray Slopes"
62  // by Martin Eisemann, Thorsten Grosch, Stefan Müller and Marcus Magnor
63  // Computer Graphics Lab, TU Braunschweig, Germany and
64  // University of Koblenz-Landau, Germany
65  // Licence: "This source code is public domain, but please mention us if you use it."
66  //
67  // https://github.com/rjw57/mcvoxel/tree/master/third-party/rayslope
68  // https://github.com/rjw57/mcvoxel/blob/master/third-party/rayslope/ray.cpp
69 
70  ibyj = m_Dir.x * m_InvDir.y;
71  jbyi = m_Dir.y * m_InvDir.x;
72  jbyk = m_Dir.y * m_InvDir.z;
73  kbyj = m_Dir.z * m_InvDir.y;
74  ibyk = m_Dir.x * m_InvDir.z;
75  kbyi = m_Dir.z * m_InvDir.x;
76  c_xy = m_Origin.y - jbyi * m_Origin.x;
77  c_xz = m_Origin.z - kbyi * m_Origin.x;
78  c_yx = m_Origin.x - ibyj * m_Origin.y;
79  c_yz = m_Origin.z - kbyj * m_Origin.y;
80  c_zx = m_Origin.x - ibyk * m_Origin.z;
81  c_zy = m_Origin.y - jbyk * m_Origin.z;
82 
83  // ray slope classification
84  if( m_Dir.x < 0 )
85  {
86  if( m_Dir.y < 0 )
87  {
88  if( m_Dir.z < 0 )
89  {
91  }
92  else if( m_Dir.z > 0 )
93  {
95  }
96  else
97  {
99  }
100  }
101  else
102  {
103  if( m_Dir.z < 0 )
104  {
106 
107  if( m_Dir.y == 0 )
109  }
110  else
111  {
112  if( ( m_Dir.y == 0 ) && ( m_Dir.z == 0 ) )
114  else if( m_Dir.z == 0 )
116  else if( m_Dir.y == 0 )
118  else
120  }
121  }
122  }
123  else
124  {
125  if( m_Dir.y < 0 )
126  {
127  if( m_Dir.z < 0 )
128  {
130 
131  if( m_Dir.x == 0 )
133  }
134  else
135  {
136  if( ( m_Dir.x == 0 ) && ( m_Dir.z == 0 ) )
138  else if( m_Dir.z == 0 )
140  else if( m_Dir.x == 0 )
142  else
144  }
145  }
146  else
147  {
148  if( m_Dir.z < 0 )
149  {
150  if( ( m_Dir.x == 0 ) && ( m_Dir.y == 0 ) )
152  else if( m_Dir.x == 0 )
154  else if( m_Dir.y == 0 )
156  else
158  }
159  else
160  {
161  if( m_Dir.x == 0 )
162  {
163  if( m_Dir.y == 0 )
165  else if( m_Dir.z == 0 )
167  else
169  }
170  else
171  {
172  if( ( m_Dir.y == 0 ) && ( m_Dir.z == 0 ) )
174  else if( m_Dir.y == 0 )
176  else if( m_Dir.z == 0 )
178  else
180  }
181  }
182  }
183  }
184 }
float c_xy
Definition: ray.h:78
float c_zy
Definition: ray.h:78
float jbyk
Definition: ray.h:77
float kbyi
Definition: ray.h:77
float c_yx
Definition: ray.h:78
SFVEC3F m_InvDir
Definition: ray.h:75
float kbyj
Definition: ray.h:77
RAY_CLASSIFICATION m_Classification
Definition: ray.h:73
unsigned int m_dirIsNeg[3]
Definition: ray.h:80
unsigned int rayID
unique ray ID - not used - dummy
Definition: ray.h:70
SFVEC3F m_Dir
Definition: ray.h:72
float ibyj
Definition: ray.h:77
float jbyi
Definition: ray.h:77
float c_yz
Definition: ray.h:78
SFVEC3F m_Origin
Definition: ray.h:69
float c_zx
Definition: ray.h:78
float c_xz
Definition: ray.h:78
float ibyk
Definition: ray.h:77

References c_xy, c_xz, c_yx, c_yz, c_zx, c_zy, ibyj, ibyk, jbyi, jbyk, kbyi, kbyj, m_Classification, m_Dir, m_dirIsNeg, m_InvDir, m_Origin, MMM, MMO, MMP, MOM, MOO, MOP, MPM, MPO, MPP, OMM, OMO, OMP, OOM, OOP, OPM, OPO, OPP, PMM, PMO, PMP, POM, POO, POP, PPM, PPO, PPP, and rayID.

Referenced by EDA_3D_CANVAS::getRayAtCurrrentMousePosition(), RAYPACKET::RAYPACKET(), RAYPACKET_InitRays(), RAYPACKET_InitRays_with2DDisplacement(), RENDER_3D_RAYTRACE::renderPreview(), and RENDER_3D_RAYTRACE::shadeHit().

◆ IntersectSphere()

bool RAY::IntersectSphere ( const SFVEC3F aCenter,
float  aRadius,
float &  aOutT0,
float &  aOutT1 
) const
Todo:
: not tested

Definition at line 217 of file ray.cpp.

219 {
220  // Ray-sphere intersection: geometric
221  SFVEC3F OC = aCenter - m_Origin;
222  float p_dot_d = glm::dot( OC, m_Dir );
223 
224  if( p_dot_d < 0.0f )
225  return 0.0f;
226 
227  float p_dot_p = glm::dot( OC, OC );
228  float discriminant = p_dot_p - p_dot_d * p_dot_d;
229 
230  if( discriminant > aRadius*aRadius )
231  return false;
232 
233  discriminant = sqrtf( aRadius*aRadius - discriminant );
234 
235  aOutT0 = p_dot_d - discriminant;
236  aOutT1 = p_dot_d + discriminant;
237 
238  if( aOutT0 > aOutT1 )
239  {
240  float temp = aOutT0;
241  aOutT0 = aOutT1;
242  aOutT1 = temp;
243  }
244 
245  return true;
246 }
SFVEC3F m_Dir
Definition: ray.h:72
SFVEC3F m_Origin
Definition: ray.h:69
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44

References m_Dir, and m_Origin.

Member Data Documentation

◆ c_xy

float RAY::c_xy

Definition at line 78 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ c_xz

float RAY::c_xz

Definition at line 78 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ c_yx

float RAY::c_yx

Definition at line 78 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ c_yz

float RAY::c_yz

Definition at line 78 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ c_zx

float RAY::c_zx

Definition at line 78 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ c_zy

float RAY::c_zy

Definition at line 78 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ ibyj

float RAY::ibyj

Definition at line 77 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ ibyk

float RAY::ibyk

Definition at line 77 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ jbyi

float RAY::jbyi

Definition at line 77 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ jbyk

float RAY::jbyk

Definition at line 77 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ kbyi

float RAY::kbyi

Definition at line 77 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ kbyj

float RAY::kbyj

Definition at line 77 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ m_Classification

RAY_CLASSIFICATION RAY::m_Classification

Definition at line 73 of file ray.h.

Referenced by Init(), and BBOX_3D::Intersect().

◆ m_Dir

◆ m_dirIsNeg

◆ m_InvDir

◆ m_Origin

◆ rayID

unsigned int RAY::rayID

unique ray ID - not used - dummy

Definition at line 70 of file ray.h.

Referenced by Init().


The documentation for this struct was generated from the following files: