You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
6.2 KiB

  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. /**
  25. * @file raypacket.cpp
  26. * @brief
  27. */
  28. #include "raypacket.h"
  29. #include "../3d_fastmath.h"
  30. #include <wx/debug.h>
  31. static void RAYPACKET_GenerateFrustum( CFRUSTUM *m_Frustum, RAY *m_ray )
  32. {
  33. m_Frustum->GenerateFrustum(
  34. m_ray[ 0 * RAYPACKET_DIM + 0 ],
  35. m_ray[ 0 * RAYPACKET_DIM + (RAYPACKET_DIM - 1) ],
  36. m_ray[ (RAYPACKET_DIM - 1) * RAYPACKET_DIM + 0 ],
  37. m_ray[ (RAYPACKET_DIM - 1) * RAYPACKET_DIM + (RAYPACKET_DIM - 1) ] );
  38. }
  39. RAYPACKET::RAYPACKET( const CCAMERA &aCamera, const SFVEC2I &aWindowsPosition )
  40. {
  41. unsigned int i = 0;
  42. for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
  43. {
  44. for( unsigned int x = 0; x < RAYPACKET_DIM; ++x )
  45. {
  46. SFVEC3F rayOrigin;
  47. SFVEC3F rayDir;
  48. aCamera.MakeRay( SFVEC2I( aWindowsPosition.x + x,
  49. aWindowsPosition.y + y ),
  50. rayOrigin, rayDir );
  51. m_ray[i].Init( rayOrigin, rayDir );
  52. i++;
  53. }
  54. }
  55. wxASSERT( i == RAYPACKET_RAYS_PER_PACKET );
  56. RAYPACKET_GenerateFrustum( &m_Frustum, m_ray );
  57. }
  58. RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
  59. const SFVEC2F &aWindowsPosition )
  60. {
  61. RAYPACKET_InitRays( aCamera, aWindowsPosition, m_ray );
  62. RAYPACKET_GenerateFrustum( &m_Frustum, m_ray );
  63. }
  64. RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
  65. const SFVEC2F &aWindowsPosition,
  66. const SFVEC2F &a2DWindowsPosDisplacementFactor )
  67. {
  68. RAYPACKET_InitRays_with2DDisplacement( aCamera,
  69. aWindowsPosition,
  70. a2DWindowsPosDisplacementFactor,
  71. m_ray );
  72. RAYPACKET_GenerateFrustum( &m_Frustum, m_ray );
  73. }
  74. RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
  75. const SFVEC2I &aWindowsPosition,
  76. const SFVEC3F &aDirectionDisplacementFactor )
  77. {
  78. unsigned int i = 0;
  79. for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
  80. for( unsigned int x = 0; x < RAYPACKET_DIM; ++x )
  81. {
  82. SFVEC3F rayOrigin;
  83. SFVEC3F rayDir;
  84. aCamera.MakeRay( SFVEC2I( aWindowsPosition.x + x,
  85. aWindowsPosition.y + y ),
  86. rayOrigin, rayDir );
  87. const SFVEC3F randVector = SFVEC3F( Fast_RandFloat() * aDirectionDisplacementFactor.x,
  88. Fast_RandFloat() * aDirectionDisplacementFactor.y,
  89. Fast_RandFloat() * aDirectionDisplacementFactor.z );
  90. m_ray[i].Init( rayOrigin,
  91. glm::normalize( rayDir + randVector ) );
  92. i++;
  93. }
  94. wxASSERT( i == RAYPACKET_RAYS_PER_PACKET );
  95. RAYPACKET_GenerateFrustum( &m_Frustum, m_ray );
  96. }
  97. RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
  98. const SFVEC2I &aWindowsPosition,
  99. unsigned int aPixelMultiple )
  100. {
  101. unsigned int i = 0;
  102. for( unsigned int y = 0; y < RAYPACKET_DIM; y++ )
  103. {
  104. for( unsigned int x = 0; x < RAYPACKET_DIM; x++ )
  105. {
  106. SFVEC3F rayOrigin;
  107. SFVEC3F rayDir;
  108. aCamera.MakeRay( SFVEC2I( aWindowsPosition.x + x * aPixelMultiple,
  109. aWindowsPosition.y + y * aPixelMultiple),
  110. rayOrigin, rayDir );
  111. m_ray[i].Init( rayOrigin, rayDir );
  112. i++;
  113. }
  114. }
  115. wxASSERT( i == RAYPACKET_RAYS_PER_PACKET );
  116. RAYPACKET_GenerateFrustum( &m_Frustum, m_ray );
  117. }
  118. void RAYPACKET_InitRays( const CCAMERA &aCamera,
  119. const SFVEC2F &aWindowsPosition,
  120. RAY *aRayPck )
  121. {
  122. for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
  123. {
  124. for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
  125. {
  126. SFVEC3F rayOrigin;
  127. SFVEC3F rayDir;
  128. aCamera.MakeRay( SFVEC2F( aWindowsPosition.x + (float)x,
  129. aWindowsPosition.y + (float)y ),
  130. rayOrigin, rayDir );
  131. aRayPck[i].Init( rayOrigin, rayDir );
  132. }
  133. }
  134. }
  135. void RAYPACKET_InitRays_with2DDisplacement( const CCAMERA &aCamera,
  136. const SFVEC2F &aWindowsPosition,
  137. const SFVEC2F &a2DWindowsPosDisplacementFactor,
  138. RAY *aRayPck )
  139. {
  140. for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
  141. {
  142. for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
  143. {
  144. SFVEC3F rayOrigin;
  145. SFVEC3F rayDir;
  146. aCamera.MakeRay( SFVEC2F( aWindowsPosition.x +(float)x +
  147. Fast_RandFloat() * a2DWindowsPosDisplacementFactor.x,
  148. aWindowsPosition.y + (float)y +
  149. Fast_RandFloat() * a2DWindowsPosDisplacementFactor.y ),
  150. rayOrigin, rayDir );
  151. aRayPck[i].Init( rayOrigin, rayDir );
  152. }
  153. }
  154. }