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

References m_Dir, and m_Origin.

397 {
398  printf("O(%f, %f, %f) D(%f, %f, %f)\n", m_Origin.x, m_Origin.y, m_Origin.z,
399  m_Dir.x, m_Dir.y, m_Dir.z );
400 }
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 38 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().

39 {
40  m_Origin = o;
41  m_Dir = d;
42  m_InvDir = 1.0f / d;
43 
44  //rayID = gs_next_rayID;
45  //gs_next_rayID++;
46 
47  // An Efficient and Robust Ray–Box Intersection Algorithm
48  // Amy Williams Steve Barrus R. Keith Morley Peter Shirley
49  // University of Utah
50  // http://people.csail.mit.edu/amy/papers/box-jgt.pdf
51  m_dirIsNeg[0] = m_Dir.x <= 0.0f;
52  m_dirIsNeg[1] = m_Dir.y <= 0.0f;
53  m_dirIsNeg[2] = m_Dir.z <= 0.0f;
54 
55 
56  // ray slope
57 
58  // "Fast Ray / Axis-Aligned Bounding Box Overlap Tests using Ray Slopes"
59  // by Martin Eisemann, Thorsten Grosch, Stefan Müller and Marcus Magnor
60  // Computer Graphics Lab, TU Braunschweig, Germany and
61  // University of Koblenz-Landau, Germany
62  // Licence: "This source code is public domain, but please mention us if you use it."
63  //
64  // https://github.com/rjw57/mcvoxel/tree/master/third-party/rayslope
65  // https://github.com/rjw57/mcvoxel/blob/master/third-party/rayslope/ray.cpp
66 
67  ibyj = m_Dir.x * m_InvDir.y;
68  jbyi = m_Dir.y * m_InvDir.x;
69  jbyk = m_Dir.y * m_InvDir.z;
70  kbyj = m_Dir.z * m_InvDir.y;
71  ibyk = m_Dir.x * m_InvDir.z;
72  kbyi = m_Dir.z * m_InvDir.x;
73  c_xy = m_Origin.y - jbyi * m_Origin.x;
74  c_xz = m_Origin.z - kbyi * m_Origin.x;
75  c_yx = m_Origin.x - ibyj * m_Origin.y;
76  c_yz = m_Origin.z - kbyj * m_Origin.y;
77  c_zx = m_Origin.x - ibyk * m_Origin.z;
78  c_zy = m_Origin.y - jbyk * m_Origin.z;
79 
80  // ray slope classification
81  if( m_Dir.x < 0 )
82  {
83  if( m_Dir.y < 0 )
84  {
85  if( m_Dir.z < 0 )
86  {
88  }
89  else if( m_Dir.z > 0 ){
91  }
92  else//( m_Dir.z >= 0 )
93  {
95  }
96  }
97  else//( m_Dir.y >= 0 )
98  {
99  if( m_Dir.z < 0 )
100  {
102  if( m_Dir.y == 0 )
104  }
105  else//( m_Dir.z >= 0 )
106  {
107  if( ( m_Dir.y == 0 ) && ( m_Dir.z == 0 ) )
109  else if( m_Dir.z == 0 )
111  else if( m_Dir.y == 0 )
113  else
115  }
116  }
117  }
118  else//( m_Dir.x >= 0 )
119  {
120  if( m_Dir.y < 0 )
121  {
122  if( m_Dir.z < 0 )
123  {
125  if( m_Dir.x == 0 )
127  }
128  else//( m_Dir.z >= 0 )
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//( m_Dir.y >= 0 )
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//( m_Dir.z > 0 )
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 }
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 212 of file ray.cpp.

References m_Dir, and m_Origin.

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