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

Member Function Documentation

SFVEC2F RAY::at2D ( float  t) const
inline

Definition at line 67 of file ray.h.

67  {
68  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:48
SFVEC3F m_Origin
Definition: ray.h:45
void RAY::debug ( ) const

Definition at line 398 of file ray.cpp.

References m_Dir, and m_Origin.

399 {
400  printf("O(%f, %f, %f) D(%f, %f, %f)\n", m_Origin.x, m_Origin.y, m_Origin.z,
401  m_Dir.x, m_Dir.y, m_Dir.z );
402 }
SFVEC3F m_Dir
Definition: ray.h:48
SFVEC3F m_Origin
Definition: ray.h:45
void RAY::Init ( const SFVEC3F o,
const SFVEC3F d 
)

Definition at line 40 of file ray.cpp.

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

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

Definition at line 214 of file ray.cpp.

References m_Dir, and m_Origin.

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

Member Data Documentation

float RAY::c_xy

Definition at line 54 of file ray.h.

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

float RAY::c_xz

Definition at line 54 of file ray.h.

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

float RAY::c_yx

Definition at line 54 of file ray.h.

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

float RAY::c_yz

Definition at line 54 of file ray.h.

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

float RAY::c_zx

Definition at line 54 of file ray.h.

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

float RAY::c_zy

Definition at line 54 of file ray.h.

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

float RAY::ibyj

Definition at line 53 of file ray.h.

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

float RAY::ibyk

Definition at line 53 of file ray.h.

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

float RAY::jbyi

Definition at line 53 of file ray.h.

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

float RAY::jbyk

Definition at line 53 of file ray.h.

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

float RAY::kbyi

Definition at line 53 of file ray.h.

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

float RAY::kbyj

Definition at line 53 of file ray.h.

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

RAY_CLASSIFICATION RAY::m_Classification

Definition at line 49 of file ray.h.

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

unsigned int RAY::rayID

unique ray ID - not used - dummy

Definition at line 46 of file ray.h.


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