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