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 62 of file ray.h.

Member Function Documentation

◆ at()

◆ at2D()

SFVEC2F RAY::at2D ( float  t) const
inline

Definition at line 86 of file ray.h.

87  {
88  return SFVEC2F( m_Origin.x + m_Dir.x * t, m_Origin.y + m_Dir.y * t );
89  }
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
SFVEC3F m_Dir
Definition: ray.h:67
SFVEC3F m_Origin
Definition: ray.h:64

References m_Dir, and m_Origin.

◆ Init()

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

Definition at line 35 of file ray.cpp.

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

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 211 of file ray.cpp.

213 {
214  // Ray-sphere intersection: geometric
215  SFVEC3F OC = aCenter - m_Origin;
216  float p_dot_d = glm::dot( OC, m_Dir );
217 
218  if( p_dot_d < 0.0f )
219  return 0.0f;
220 
221  float p_dot_p = glm::dot( OC, OC );
222  float discriminant = p_dot_p - p_dot_d * p_dot_d;
223 
224  if( discriminant > aRadius*aRadius )
225  return false;
226 
227  discriminant = sqrtf( aRadius*aRadius - discriminant );
228 
229  aOutT0 = p_dot_d - discriminant;
230  aOutT1 = p_dot_d + discriminant;
231 
232  if( aOutT0 > aOutT1 )
233  {
234  float temp = aOutT0;
235  aOutT0 = aOutT1;
236  aOutT1 = temp;
237  }
238 
239  return true;
240 }
SFVEC3F m_Dir
Definition: ray.h:67
SFVEC3F m_Origin
Definition: ray.h:64
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 73 of file ray.h.

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

◆ c_xz

float RAY::c_xz

Definition at line 73 of file ray.h.

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

◆ c_yx

float RAY::c_yx

Definition at line 73 of file ray.h.

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

◆ c_yz

float RAY::c_yz

Definition at line 73 of file ray.h.

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

◆ c_zx

float RAY::c_zx

Definition at line 73 of file ray.h.

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

◆ c_zy

float RAY::c_zy

Definition at line 73 of file ray.h.

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

◆ ibyj

float RAY::ibyj

Definition at line 72 of file ray.h.

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

◆ ibyk

float RAY::ibyk

Definition at line 72 of file ray.h.

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

◆ jbyi

float RAY::jbyi

Definition at line 72 of file ray.h.

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

◆ jbyk

float RAY::jbyk

Definition at line 72 of file ray.h.

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

◆ kbyi

float RAY::kbyi

Definition at line 72 of file ray.h.

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

◆ kbyj

float RAY::kbyj

Definition at line 72 of file ray.h.

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

◆ m_Classification

RAY_CLASSIFICATION RAY::m_Classification

Definition at line 68 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 65 of file ray.h.

Referenced by Init().


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