KiCad PCB EDA Suite
raypacket.cpp
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-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 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 #include "raypacket.h"
31 #include "../3d_fastmath.h"
32 #include <wx/debug.h>
33 
34 
35 static void RAYPACKET_GenerateFrustum( CFRUSTUM *m_Frustum, RAY *m_ray )
36 {
37  m_Frustum->GenerateFrustum(
38  m_ray[ 0 * RAYPACKET_DIM + 0 ],
39  m_ray[ 0 * RAYPACKET_DIM + (RAYPACKET_DIM - 1) ],
40  m_ray[ (RAYPACKET_DIM - 1) * RAYPACKET_DIM + 0 ],
41  m_ray[ (RAYPACKET_DIM - 1) * RAYPACKET_DIM + (RAYPACKET_DIM - 1) ] );
42 }
43 
44 
45 RAYPACKET::RAYPACKET( const CCAMERA &aCamera, const SFVEC2I &aWindowsPosition )
46 {
47  unsigned int i = 0;
48 
49  for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
50  {
51  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x )
52  {
53  SFVEC3F rayOrigin;
54  SFVEC3F rayDir;
55 
56  aCamera.MakeRay( SFVEC2I( aWindowsPosition.x + x,
57  aWindowsPosition.y + y ),
58  rayOrigin, rayDir );
59 
60  m_ray[i].Init( rayOrigin, rayDir );
61 
62  i++;
63  }
64  }
65 
66  wxASSERT( i == RAYPACKET_RAYS_PER_PACKET );
67 
69 }
70 
71 
72 RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
73  const SFVEC2F &aWindowsPosition )
74 {
75  RAYPACKET_InitRays( aCamera, aWindowsPosition, m_ray );
76 
78 }
79 
80 
81 RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
82  const SFVEC2F &aWindowsPosition,
83  const SFVEC2F &a2DWindowsPosDisplacementFactor )
84 {
86  aWindowsPosition,
87  a2DWindowsPosDisplacementFactor,
88  m_ray );
89 
91 }
92 
93 
94 RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
95  const SFVEC2I &aWindowsPosition,
96  const SFVEC3F &aDirectionDisplacementFactor )
97 {
98  unsigned int i = 0;
99  for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
100  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x )
101  {
102  SFVEC3F rayOrigin;
103  SFVEC3F rayDir;
104 
105  aCamera.MakeRay( SFVEC2I( aWindowsPosition.x + x,
106  aWindowsPosition.y + y ),
107  rayOrigin, rayDir );
108 
109  const SFVEC3F randVector = SFVEC3F( Fast_RandFloat() * aDirectionDisplacementFactor.x,
110  Fast_RandFloat() * aDirectionDisplacementFactor.y,
111  Fast_RandFloat() * aDirectionDisplacementFactor.z );
112 
113  m_ray[i].Init( rayOrigin,
114  glm::normalize( rayDir + randVector ) );
115 
116  i++;
117  }
118 
119  wxASSERT( i == RAYPACKET_RAYS_PER_PACKET );
120 
122 }
123 
124 
126  const SFVEC2I &aWindowsPosition,
127  unsigned int aPixelMultiple )
128 {
129  unsigned int i = 0;
130 
131  for( unsigned int y = 0; y < RAYPACKET_DIM; y++ )
132  {
133  for( unsigned int x = 0; x < RAYPACKET_DIM; x++ )
134  {
135  SFVEC3F rayOrigin;
136  SFVEC3F rayDir;
137 
138  aCamera.MakeRay( SFVEC2I( aWindowsPosition.x + x * aPixelMultiple,
139  aWindowsPosition.y + y * aPixelMultiple),
140  rayOrigin, rayDir );
141 
142  m_ray[i].Init( rayOrigin, rayDir );
143 
144  i++;
145  }
146  }
147 
148  wxASSERT( i == RAYPACKET_RAYS_PER_PACKET );
149 
151 }
152 
153 
154 void RAYPACKET_InitRays( const CCAMERA &aCamera,
155  const SFVEC2F &aWindowsPosition,
156  RAY *aRayPck )
157 {
158  for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
159  {
160  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
161  {
162  SFVEC3F rayOrigin;
163  SFVEC3F rayDir;
164 
165  aCamera.MakeRay( SFVEC2F( aWindowsPosition.x + (float)x,
166  aWindowsPosition.y + (float)y ),
167  rayOrigin, rayDir );
168 
169  aRayPck[i].Init( rayOrigin, rayDir );
170  }
171  }
172 }
173 
175  const SFVEC2F &aWindowsPosition,
176  const SFVEC2F &a2DWindowsPosDisplacementFactor,
177  RAY *aRayPck )
178 {
179  for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
180  {
181  for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
182  {
183  SFVEC3F rayOrigin;
184  SFVEC3F rayDir;
185 
186  aCamera.MakeRay( SFVEC2F( aWindowsPosition.x +(float)x +
187  Fast_RandFloat() * a2DWindowsPosDisplacementFactor.x,
188  aWindowsPosition.y + (float)y +
189  Fast_RandFloat() * a2DWindowsPosDisplacementFactor.y ),
190  rayOrigin, rayDir );
191 
192  aRayPck[i].Init( rayOrigin, rayDir );
193  }
194  }
195 }
#define RAYPACKET_DIM
Definition: raypacket.h:37
RAY m_ray[RAYPACKET_RAYS_PER_PACKET]
Definition: raypacket.h:46
void GenerateFrustum(const RAY &topLeft, const RAY &topRight, const RAY &bottomLeft, const RAY &bottomRight)
GenerateFrustum.
Definition: cfrustum.cpp:42
void Init(const SFVEC3F &o, const SFVEC3F &d)
Definition: ray.cpp:38
void RAYPACKET_InitRays(const CCAMERA &aCamera, const SFVEC2F &aWindowsPosition, RAY *aRayPck)
Definition: raypacket.cpp:154
Class CCAMERA is a virtual class used to derive CCAMERA objects from.
Definition: ccamera.h:80
Definition: ray.h:43
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
float Fast_RandFloat()
Definition: 3d_fastmath.cpp:45
static void RAYPACKET_GenerateFrustum(CFRUSTUM *m_Frustum, RAY *m_ray)
Definition: raypacket.cpp:35
CFRUSTUM m_Frustum
Definition: raypacket.h:45
RAYPACKET(const CCAMERA &aCamera, const SFVEC2I &aWindowsPosition)
Definition: raypacket.cpp:45
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
void MakeRay(const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
MakeRay - Make a ray based on a windows screen position.
Definition: ccamera.cpp:293
#define RAYPACKET_RAYS_PER_PACKET
Definition: raypacket.h:40
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
void RAYPACKET_InitRays_with2DDisplacement(const CCAMERA &aCamera, const SFVEC2F &aWindowsPosition, const SFVEC2F &a2DWindowsPosDisplacementFactor, RAY *aRayPck)
Definition: raypacket.cpp:174