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

401 {
402  wxLogDebug( "O(%f, %f, %f) D(%f, %f, %f)\n", m_Origin.x, m_Origin.y, m_Origin.z,
403  m_Dir.x, m_Dir.y, m_Dir.z );
404 }
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 = gs_next_rayID;
48  //gs_next_rayID++;
49 
50  // An Efficient and Robust Ray–Box Intersection Algorithm
51  // Amy Williams Steve Barrus R. Keith Morley Peter Shirley
52  // University of Utah
53  // http://people.csail.mit.edu/amy/papers/box-jgt.pdf
54  m_dirIsNeg[0] = m_Dir.x < 0.0f;
55  m_dirIsNeg[1] = m_Dir.y < 0.0f;
56  m_dirIsNeg[2] = m_Dir.z < 0.0f;
57 
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//( m_Dir.z >= 0 )
97  {
99  }
100  }
101  else//( m_Dir.y >= 0 )
102  {
103  if( m_Dir.z < 0 )
104  {
106  if( m_Dir.y == 0 )
108  }
109  else//( m_Dir.z >= 0 )
110  {
111  if( ( m_Dir.y == 0 ) && ( m_Dir.z == 0 ) )
113  else if( m_Dir.z == 0 )
115  else if( m_Dir.y == 0 )
117  else
119  }
120  }
121  }
122  else//( m_Dir.x >= 0 )
123  {
124  if( m_Dir.y < 0 )
125  {
126  if( m_Dir.z < 0 )
127  {
129  if( m_Dir.x == 0 )
131  }
132  else//( m_Dir.z >= 0 )
133  {
134  if( ( m_Dir.x == 0 ) && ( m_Dir.z == 0 ) )
136  else if( m_Dir.z == 0 )
138  else if( m_Dir.x == 0 )
140  else
142  }
143  }
144  else//( m_Dir.y >= 0 )
145  {
146  if( m_Dir.z < 0 )
147  {
148  if( ( m_Dir.x == 0 ) && ( m_Dir.y == 0 ) )
150  else if( m_Dir.x == 0 )
152  else if( m_Dir.y == 0 )
154  else
156  }
157  else//( m_Dir.z > 0 )
158  {
159  if( m_Dir.x == 0 )
160  {
161  if( m_Dir.y == 0 )
163  else if( m_Dir.z == 0 )
165  else
167  }
168  else
169  {
170  if( ( m_Dir.y == 0 ) && ( m_Dir.z == 0 ) )
172  else if( m_Dir.y == 0 )
174  else if( m_Dir.z == 0 )
176  else
178  }
179  }
180  }
181  }
182 }
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
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, and PPP.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position(), 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 216 of file ray.cpp.

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


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