KiCad PCB EDA Suite
eda_3d_canvas_pivot.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) 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 "../common_ogl/openGL_includes.h"
31 #include "../common_ogl/ogl_utils.h"
32 #include "eda_3d_canvas.h"
33 
34 
35 static void pivot_render_triangles( float t )
36 {
37  wxASSERT( t >= 0.0f );
38 
39  SFVEC3F vertexPointer[12];
40 
41  const float u = 1.0f / 6.0f;
42 
43  vertexPointer[0] = SFVEC3F( (-3.0f + t) * u, -2.0f * u, 0.0f );
44  vertexPointer[1] = SFVEC3F( (-3.0f + t) * u, 2.0f * u, 0.0f );
45  vertexPointer[2] = SFVEC3F( (-1.0f + t) * u, 0.0f * u, 0.0f );
46 
47  vertexPointer[3] = SFVEC3F( -2.0f * u, (-3.0f + t) * u, 0.0f );
48  vertexPointer[4] = SFVEC3F( 2.0f * u, (-3.0f + t) * u, 0.0f );
49  vertexPointer[5] = SFVEC3F( 0.0f * u, (-1.0f + t) * u, 0.0f );
50 
51  vertexPointer[6] = SFVEC3F( (3.0f - t) * u, -2.0f * u, 0.0f );
52  vertexPointer[7] = SFVEC3F( (3.0f - t) * u, 2.0f * u, 0.0f );
53  vertexPointer[8] = SFVEC3F( (1.0f - t) * u, 0.0f * u, 0.0f );
54 
55  vertexPointer[9] = SFVEC3F( 2.0f * u, (3.0f - t) * u, 0.0f );
56  vertexPointer[10] = SFVEC3F( -2.0f * u, (3.0f - t) * u, 0.0f );
57  vertexPointer[11] = SFVEC3F( 0.0f * u, (1.0f - t) * u, 0.0f );
58 
59  glDisableClientState( GL_TEXTURE_COORD_ARRAY );
60  glDisableClientState( GL_COLOR_ARRAY );
61  glDisableClientState( GL_NORMAL_ARRAY );
62  glEnableClientState( GL_VERTEX_ARRAY );
63  glVertexPointer( 3, GL_FLOAT, 0, vertexPointer );
64 
65  glEnable( GL_BLEND );
66  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
67 
68  glDrawArrays( GL_TRIANGLES, 0, 4 * 3 );
69 
70  glDisable( GL_BLEND );
71 
72  glDisableClientState( GL_VERTEX_ARRAY );
73 }
74 
75 
76 void EDA_3D_CANVAS::render_pivot( float t , float aScale )
77 {
78  wxASSERT( aScale >= 0.0f );
79  wxASSERT( t >= 0.0f );
80 
81  if( t > 1.0f )
82  t = 1.0f;
83 
84  const SFVEC3F &lookAtPos = m_settings.CameraGet().GetLookAtPos_T1();
85 
86  glDisable( GL_LIGHTING );
87  glDisable( GL_DEPTH_TEST );
88  glDisable( GL_CULL_FACE );
89 
90  // Set projection and modelview matrixes
91  // /////////////////////////////////////////////////////////////////////////
92  glMatrixMode( GL_PROJECTION );
93  glLoadMatrixf( glm::value_ptr( m_settings.CameraGet().GetProjectionMatrix() ) );
94 
95  glMatrixMode( GL_MODELVIEW );
96  glLoadIdentity();
97  glLoadMatrixf( glm::value_ptr( m_settings.CameraGet().GetViewMatrix() ) );
98 
99  glEnable( GL_COLOR_MATERIAL );
100  glColor4f( 0.0f, 1.0f, 0.0f, 0.75f - t * 0.75f );
101 
102  // Translate to the look at position
103  glTranslatef( lookAtPos.x, lookAtPos.y, lookAtPos.z );
104 
105  glScalef( aScale, aScale, aScale );
106 
107  pivot_render_triangles( t * 0.5f );
108 
109  t = t * 0.80f;
110  glScalef( 1.0f - t, 1.0f - t, 1.0f - t );
111  glColor4f( 0.0f, 1.0f, 0.0f, 0.8f - t );
112 
113  glPushMatrix();
114  glRotatef( t * 90.0f, 0.0f, 0.0f, 1.0f );
115  pivot_render_triangles( t * 0.5f );
116  glPopMatrix();
117 
118  glPushMatrix();
119  glRotatef( -t * 90.0f, 0.0f, 0.0f, 1.0f );
120  pivot_render_triangles( t * 0.5f );
121  glPopMatrix();
122 }
CINFO3D_VISU & m_settings
Stores all pre-computed 3D information and visualization settings to render the board.
const glm::mat4 & GetProjectionMatrix() const
Definition: ccamera.cpp:359
const glm::mat4 & GetViewMatrix() const
Definition: ccamera.cpp:389
const SFVEC3F & GetLookAtPos_T1() const
Definition: ccamera.h:129
CCAMERA & CameraGet() const
CameraGet - get current camera in use.
Definition: cinfo3d_visu.h:210
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
static void pivot_render_triangles(float t)
void render_pivot(float t, float aScale)
render_pivot - render the pivot cursor