KiCad PCB EDA Suite
ray.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef _RAY_H_
31 #define _RAY_H_
32 
34 
35 
37 {
38  MMM,
39  MMP,
40  MPM,
41  MPP,
42  PMM,
43  PMP,
44  PPM,
45  PPP,
46  POO,
47  MOO,
48  OPO,
49  OMO,
50  OOP,
51  OOM,
52  OMM,
53  OMP,
54  OPM,
55  OPP,
56  MOM,
57  MOP,
58  POM,
59  POP,
60  MMO,
61  MPO,
62  PMO,
63  PPO
64 };
65 
66 
67 struct RAY
68 {
70  unsigned int rayID;
71 
74 
76 
77  float ibyj, jbyi, kbyj, jbyk, ibyk, kbyi; // slope
78  float c_xy, c_xz, c_yx, c_yz, c_zx, c_zy;
79 
80  unsigned int m_dirIsNeg[3];
81 
82  void Init( const SFVEC3F& o, const SFVEC3F& d );
83 
84  bool IntersectSphere( const SFVEC3F &aCenter,
85  float aRadius,
86  float &aOutT0,
87  float &aOutT1 ) const;
88 
89  SFVEC3F at( float t ) const { return m_Origin + m_Dir * t; }
90 
91  SFVEC2F at2D( float t ) const {
92  return SFVEC2F( m_Origin.x + m_Dir.x * t, m_Origin.y + m_Dir.y * t ); }
93 
94  void debug() const;
95 };
96 
97 
98 struct RAY2D
99 {
103 
104  RAY2D( const SFVEC2F& o, const SFVEC2F& d ) { m_Origin = o; m_Dir = d; m_InvDir = (1.0f / d); }
105 
106  SFVEC2F at( float t ) const { return m_Origin + m_Dir * t; }
107 };
108 
109 
110 struct RAYSEG2D
111 {
117  float m_Length;
119 
120  RAYSEG2D( const SFVEC2F& s, const SFVEC2F& e );
121 
122  bool IntersectSegment( const SFVEC2F &aStart,
123  const SFVEC2F &aEnd_minus_start,
124  float *aOutT ) const;
125 
126  bool IntersectCircle( const SFVEC2F &aCenter,
127  float aRadius,
128  float *aOutT0,
129  float *aOutT1,
130  SFVEC2F *aOutNormalT0,
131  SFVEC2F *aOutNormalT1 ) const;
132 
133  float DistanceToPointSquared( const SFVEC2F &aPoint ) const;
134 
139  SFVEC2F atNormalized( float t ) const { return m_Start + m_End_minus_start * t; }
140 
141  SFVEC2F at( float t ) const { return m_Start + m_Dir * t; }
142 };
143 
144 
145 bool IntersectSegment( const SFVEC2F &aStartA, const SFVEC2F &aEnd_minus_startA,
146  const SFVEC2F &aStartB, const SFVEC2F &aEnd_minus_startB );
147 
148 #if(GLM_ARCH != GLM_ARCH_PURE)
149 /*
150 struct RAY4
151 {
152  glm::simdVec4 m_orgX; ///< x coordinate of ray origin
153  glm::simdVec4 m_orgy; ///< y coordinate of ray origin
154  glm::simdVec4 m_orgz; ///< z coordinate of ray origin
155 
156  glm::simdVec4 m_dirX; ///< x direction of ray
157  glm::simdVec4 m_diry; ///< y direction of ray
158  glm::simdVec4 m_dirz; ///< z direction of ray
159 
160  glm::simdVec4 m_tnear; ///< Start of ray segment
161  glm::simdVec4 m_tfar; ///< End of ray segment
162 };*/
163 
164 #endif
165 
166 
167 #endif // _RAY_H_
SFVEC2F atNormalized(float t) const
Function atNormalized - returns the position at t t - value 0.0 ...
Definition: ray.h:139
RAY2D(const SFVEC2F &o, const SFVEC2F &d)
Definition: ray.h:104
float c_xy
Definition: ray.h:78
void Init(const SFVEC3F &o, const SFVEC3F &d)
Definition: ray.cpp:40
bool IntersectSegment(const SFVEC2F &aStartA, const SFVEC2F &aEnd_minus_startA, const SFVEC2F &aStartB, const SFVEC2F &aEnd_minus_startB)
Definition: ray.cpp:183
bool IntersectSphere(const SFVEC3F &aCenter, float aRadius, float &aOutT0, float &aOutT1) const
Definition: ray.cpp:214
bool IntersectCircle(const SFVEC2F &aCenter, float aRadius, float *aOutT0, float *aOutT1, SFVEC2F *aOutNormalT0, SFVEC2F *aOutNormalT1) const
Definition: ray.cpp:348
float c_zy
Definition: ray.h:78
SFVEC2F m_Dir
Definition: ray.h:115
Definition: ray.h:67
float jbyk
Definition: ray.h:77
SFVEC3F at(float t) const
Definition: ray.h:89
RAY_CLASSIFICATION
Definition: ray.h:36
void debug() const
Definition: ray.cpp:398
float kbyi
Definition: ray.h:77
float c_yx
Definition: ray.h:78
SFVEC2F m_Dir
Definition: ray.h:101
SFVEC2F at(float t) const
Definition: ray.h:141
SFVEC3F m_InvDir
Definition: ray.h:75
float kbyj
Definition: ray.h:77
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
RAY_CLASSIFICATION m_Classification
Definition: ray.h:73
bool IntersectSegment(const SFVEC2F &aStart, const SFVEC2F &aEnd_minus_start, float *aOutT) const
Definition: ray.cpp:291
unsigned int m_dirIsNeg[3]
Definition: ray.h:80
float m_DOT_End_minus_start
dot( m_End_minus_start, m_End_minus_start)
Definition: ray.h:118
float m_Length
Definition: ray.h:117
SFVEC2F m_End
Definition: ray.h:113
unsigned int rayID
unique ray ID - not used - dummy
Definition: ray.h:70
SFVEC2F m_InvDir
Definition: ray.h:116
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
SFVEC2F m_Start
Definition: ray.h:112
float c_zx
Definition: ray.h:78
SFVEC2F at(float t) const
Definition: ray.h:106
Definition: ray.h:98
RAYSEG2D(const SFVEC2F &s, const SFVEC2F &e)
Definition: ray.cpp:272
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
float DistanceToPointSquared(const SFVEC2F &aPoint) const
Definition: ray.cpp:325
SFVEC2F m_InvDir
Definition: ray.h:102
float c_xz
Definition: ray.h:78
SFVEC2F m_Origin
Definition: ray.h:100
SFVEC2F m_End_minus_start
Definition: ray.h:114
float ibyk
Definition: ray.h:77
SFVEC2F at2D(float t) const
Definition: ray.h:91
Definition: ray.h:110