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