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
 
void debug () 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.

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

References m_Dir, and m_Origin.

◆ debug()

void RAY::debug ( ) const

Definition at line 401 of file ray.cpp.

402 {
403  wxLogDebug( "O(%f, %f, %f) D(%f, %f, %f)\n", m_Origin.x, m_Origin.y, m_Origin.z,
404  m_Dir.x, m_Dir.y, m_Dir.z );
405 }
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 
60  // ray slope
61 
62  // "Fast Ray / Axis-Aligned Bounding Box Overlap Tests using Ray Slopes"
63  // by Martin Eisemann, Thorsten Grosch, Stefan Müller and Marcus Magnor
64  // Computer Graphics Lab, TU Braunschweig, Germany and
65  // University of Koblenz-Landau, Germany
66  // Licence: "This source code is public domain, but please mention us if you use it."
67  //
68  // https://github.com/rjw57/mcvoxel/tree/master/third-party/rayslope
69  // https://github.com/rjw57/mcvoxel/blob/master/third-party/rayslope/ray.cpp
70 
71  ibyj = m_Dir.x * m_InvDir.y;
72  jbyi = m_Dir.y * m_InvDir.x;
73  jbyk = m_Dir.y * m_InvDir.z;
74  kbyj = m_Dir.z * m_InvDir.y;
75  ibyk = m_Dir.x * m_InvDir.z;
76  kbyi = m_Dir.z * m_InvDir.x;
77  c_xy = m_Origin.y - jbyi * m_Origin.x;
78  c_xz = m_Origin.z - kbyi * m_Origin.x;
79  c_yx = m_Origin.x - ibyj * m_Origin.y;
80  c_yz = m_Origin.z - kbyj * m_Origin.y;
81  c_zx = m_Origin.x - ibyk * m_Origin.z;
82  c_zy = m_Origin.y - jbyk * m_Origin.z;
83 
84  // ray slope classification
85  if( m_Dir.x < 0 )
86  {
87  if( m_Dir.y < 0 )
88  {
89  if( m_Dir.z < 0 )
90  {
92  }
93  else if( m_Dir.z > 0 )
94  {
96  }
97  else//( m_Dir.z >= 0 )
98  {
100  }
101  }
102  else//( m_Dir.y >= 0 )
103  {
104  if( m_Dir.z < 0 )
105  {
107  if( m_Dir.y == 0 )
109  }
110  else//( m_Dir.z >= 0 )
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//( m_Dir.x >= 0 )
124  {
125  if( m_Dir.y < 0 )
126  {
127  if( m_Dir.z < 0 )
128  {
130  if( m_Dir.x == 0 )
132  }
133  else//( m_Dir.z >= 0 )
134  {
135  if( ( m_Dir.x == 0 ) && ( m_Dir.z == 0 ) )
137  else if( m_Dir.z == 0 )
139  else if( m_Dir.x == 0 )
141  else
143  }
144  }
145  else//( m_Dir.y >= 0 )
146  {
147  if( m_Dir.z < 0 )
148  {
149  if( ( m_Dir.x == 0 ) && ( m_Dir.y == 0 ) )
151  else if( m_Dir.x == 0 )
153  else if( m_Dir.y == 0 )
155  else
157  }
158  else//( m_Dir.z > 0 )
159  {
160  if( m_Dir.x == 0 )
161  {
162  if( m_Dir.y == 0 )
164  else if( m_Dir.z == 0 )
166  else
168  }
169  else
170  {
171  if( ( m_Dir.y == 0 ) && ( m_Dir.z == 0 ) )
173  else if( m_Dir.y == 0 )
175  else if( m_Dir.z == 0 )
177  else
179  }
180  }
181  }
182  }
183 }
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(), C3D_RENDER_RAYTRACING::render_preview(), and C3D_RENDER_RAYTRACING::shadeHit().

◆ IntersectSphere()

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

Definition at line 217 of file ray.cpp.

218 {
219 /*
220  // Ray-sphere intersection: algebraic
221 
222  SFVEC3F CO = m_Origin - aCenter;
223 
224  float a = glm::dot( m_Dir, m_Dir );
225  float b = 2.0f * glm::dot( CO, m_Dir );
226  float c = glm::dot( CO, CO ) - aRadius*aRadius;
227 
228  float discriminant = b * b - 4.0f * a * c;
229 
230  if( discriminant < 0.0f )
231  return false;
232 
233  aOutT0 = (-b - sqrtf(discriminant)) / (2.0f * a);
234  aOutT1 = (-b + sqrtf(discriminant)) / (2.0f * a);
235 
236  if( aOutT0 > aOutT1 )
237  {
238  float temp = aOutT0;
239  aOutT0 = aOutT1;
240  aOutT1 = temp;
241  }
242 
243  return true;
244 */
245 
246  // Ray-sphere intersection: geometric
247  SFVEC3F OC = aCenter - m_Origin;
248  float p_dot_d = glm::dot( OC, m_Dir );
249 
250  if( p_dot_d < 0.0f )
251  return 0.0f;
252 
253  float p_dot_p = glm::dot( OC, OC );
254  float discriminant = p_dot_p - p_dot_d * p_dot_d;
255 
256  if( discriminant > aRadius*aRadius )
257  return false;
258 
259  discriminant = sqrtf( aRadius*aRadius - discriminant );
260 
261  aOutT0 = p_dot_d - discriminant;
262  aOutT1 = p_dot_d + discriminant;
263 
264  if( aOutT0 > aOutT1 )
265  {
266  float temp = aOutT0;
267  aOutT0 = aOutT1;
268  aOutT1 = temp;
269  }
270 
271  return true;
272 }
SFVEC3F m_Dir
Definition: ray.h:72
SFVEC3F m_Origin
Definition: ray.h:69
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47

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 CBBOX::Intersect().

◆ c_xz

float RAY::c_xz

Definition at line 78 of file ray.h.

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

◆ c_yx

float RAY::c_yx

Definition at line 78 of file ray.h.

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

◆ c_yz

float RAY::c_yz

Definition at line 78 of file ray.h.

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

◆ c_zx

float RAY::c_zx

Definition at line 78 of file ray.h.

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

◆ c_zy

float RAY::c_zy

Definition at line 78 of file ray.h.

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

◆ ibyj

float RAY::ibyj

Definition at line 77 of file ray.h.

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

◆ ibyk

float RAY::ibyk

Definition at line 77 of file ray.h.

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

◆ jbyi

float RAY::jbyi

Definition at line 77 of file ray.h.

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

◆ jbyk

float RAY::jbyk

Definition at line 77 of file ray.h.

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

◆ kbyi

float RAY::kbyi

Definition at line 77 of file ray.h.

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

◆ kbyj

float RAY::kbyj

Definition at line 77 of file ray.h.

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

◆ m_Classification

RAY_CLASSIFICATION RAY::m_Classification

Definition at line 73 of file ray.h.

Referenced by Init(), and CBBOX::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: