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.

161 lines
4.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
  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, 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 eda_3d_canvas_pivot.cpp
  26. * @brief Implementation of a 3d cursor
  27. */
  28. #include "../common_ogl/openGL_includes.h"
  29. #include "../common_ogl/ogl_utils.h"
  30. #include "eda_3d_canvas.h"
  31. static void pivot_render_triangles( float t )
  32. {
  33. wxASSERT( t >= 0.0f );
  34. SFVEC3F vertexPointer[12];
  35. const float u = 1.0f / 6.0f;
  36. vertexPointer[0] = SFVEC3F( ( -3.0f + t ) * u, -2.0f * u, 0.0f );
  37. vertexPointer[1] = SFVEC3F( ( -3.0f + t ) * u, 2.0f * u, 0.0f );
  38. vertexPointer[2] = SFVEC3F( ( -1.0f + t ) * u, 0.0f * u, 0.0f );
  39. vertexPointer[3] = SFVEC3F( -2.0f * u, ( -3.0f + t ) * u, 0.0f );
  40. vertexPointer[4] = SFVEC3F( 2.0f * u, ( -3.0f + t ) * u, 0.0f );
  41. vertexPointer[5] = SFVEC3F( 0.0f * u, ( -1.0f + t ) * u, 0.0f );
  42. vertexPointer[6] = SFVEC3F( ( 3.0f - t ) * u, -2.0f * u, 0.0f );
  43. vertexPointer[7] = SFVEC3F( ( 3.0f - t ) * u, 2.0f * u, 0.0f );
  44. vertexPointer[8] = SFVEC3F( ( 1.0f - t ) * u, 0.0f * u, 0.0f );
  45. vertexPointer[9] = SFVEC3F( 2.0f * u, ( 3.0f - t ) * u, 0.0f );
  46. vertexPointer[10] = SFVEC3F( -2.0f * u, ( 3.0f - t ) * u, 0.0f );
  47. vertexPointer[11] = SFVEC3F( 0.0f * u, ( 1.0f - t ) * u, 0.0f );
  48. glDisableClientState( GL_TEXTURE_COORD_ARRAY );
  49. glDisableClientState( GL_COLOR_ARRAY );
  50. glDisableClientState( GL_NORMAL_ARRAY );
  51. glEnableClientState( GL_VERTEX_ARRAY );
  52. glVertexPointer( 3, GL_FLOAT, 0, vertexPointer );
  53. glEnable( GL_BLEND );
  54. glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
  55. glDrawArrays( GL_TRIANGLES, 0, 4 * 3 );
  56. glDisable( GL_BLEND );
  57. glDisableClientState( GL_VERTEX_ARRAY );
  58. }
  59. void EDA_3D_CANVAS::render_pivot( float t, float aScale )
  60. {
  61. wxASSERT( aScale >= 0.0f );
  62. wxASSERT( t >= 0.0f );
  63. if( t > 1.0f )
  64. t = 1.0f;
  65. const SFVEC3F &lookAtPos = m_camera.GetLookAtPos_T1();
  66. glDisable( GL_LIGHTING );
  67. glDisable( GL_DEPTH_TEST );
  68. glDisable( GL_CULL_FACE );
  69. // Set projection and modelview matrixes
  70. glMatrixMode( GL_PROJECTION );
  71. glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
  72. glMatrixMode( GL_MODELVIEW );
  73. glLoadIdentity();
  74. glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
  75. glEnable( GL_COLOR_MATERIAL );
  76. glColor4f( 0.0f, 1.0f, 0.0f, 0.75f - t * 0.75f );
  77. // Translate to the look at position
  78. glTranslatef( lookAtPos.x, lookAtPos.y, lookAtPos.z );
  79. glScalef( aScale, aScale, aScale );
  80. pivot_render_triangles( t * 0.5f );
  81. t = t * 0.80f;
  82. glScalef( 1.0f - t, 1.0f - t, 1.0f - t );
  83. glColor4f( 0.0f, 1.0f, 0.0f, 0.8f - t );
  84. glPushMatrix();
  85. glRotatef( t * 90.0f, 0.0f, 0.0f, 1.0f );
  86. pivot_render_triangles( t * 0.5f );
  87. glPopMatrix();
  88. glPushMatrix();
  89. glRotatef( -t * 90.0f, 0.0f, 0.0f, 1.0f );
  90. pivot_render_triangles( t * 0.5f );
  91. glPopMatrix();
  92. }
  93. void EDA_3D_CANVAS::render3dmousePivot( float aScale )
  94. {
  95. wxASSERT( aScale >= 0.0f );
  96. glDisable( GL_LIGHTING );
  97. glDisable( GL_DEPTH_TEST );
  98. glDisable( GL_CULL_FACE );
  99. // Set projection and modelview matrixes
  100. glMatrixMode( GL_PROJECTION );
  101. glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
  102. glMatrixMode( GL_MODELVIEW );
  103. glLoadIdentity();
  104. glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
  105. glEnable( GL_COLOR_MATERIAL );
  106. glColor4f( 0.0f, 0.667f, 0.902f, 0.75f );
  107. // Translate to the look at position
  108. glTranslatef( m_3dmousePivotPos.x, m_3dmousePivotPos.y, m_3dmousePivotPos.z );
  109. glPointSize( 16.0f );
  110. glEnable( GL_POINT_SMOOTH );
  111. glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
  112. glEnable( GL_BLEND );
  113. glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
  114. glScalef( aScale, aScale, aScale );
  115. // Draw a point at the look at position.
  116. glBegin( GL_POINTS );
  117. glVertex3f( 0, 0, 0 );
  118. glEnd();
  119. glDisable( GL_BLEND );
  120. glDisable( GL_POINT_SMOOTH );
  121. }