KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[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, 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
29
30#include <kicad_gl/kiglu.h> // Must be included first
31
33#include "eda_3d_canvas.h"
34
35
36static void pivot_render_triangles( float t )
37{
38 wxASSERT( t >= 0.0f );
39
40 SFVEC3F vertexPointer[12];
41
42 const float u = 1.0f / 6.0f;
43
44 vertexPointer[0] = SFVEC3F( ( -3.0f + t ) * u, -2.0f * u, 0.0f );
45 vertexPointer[1] = SFVEC3F( ( -3.0f + t ) * u, 2.0f * u, 0.0f );
46 vertexPointer[2] = SFVEC3F( ( -1.0f + t ) * u, 0.0f * u, 0.0f );
47
48 vertexPointer[3] = SFVEC3F( -2.0f * u, ( -3.0f + t ) * u, 0.0f );
49 vertexPointer[4] = SFVEC3F( 2.0f * u, ( -3.0f + t ) * u, 0.0f );
50 vertexPointer[5] = SFVEC3F( 0.0f * u, ( -1.0f + t ) * u, 0.0f );
51
52 vertexPointer[6] = SFVEC3F( ( 3.0f - t ) * u, -2.0f * u, 0.0f );
53 vertexPointer[7] = SFVEC3F( ( 3.0f - t ) * u, 2.0f * u, 0.0f );
54 vertexPointer[8] = SFVEC3F( ( 1.0f - t ) * u, 0.0f * u, 0.0f );
55
56 vertexPointer[9] = SFVEC3F( 2.0f * u, ( 3.0f - t ) * u, 0.0f );
57 vertexPointer[10] = SFVEC3F( -2.0f * u, ( 3.0f - t ) * u, 0.0f );
58 vertexPointer[11] = SFVEC3F( 0.0f * u, ( 1.0f - t ) * u, 0.0f );
59
60 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
61 glDisableClientState( GL_COLOR_ARRAY );
62 glDisableClientState( GL_NORMAL_ARRAY );
63 glEnableClientState( GL_VERTEX_ARRAY );
64 glVertexPointer( 3, GL_FLOAT, 0, vertexPointer );
65
66 glEnable( GL_BLEND );
67 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
68
69 glDrawArrays( GL_TRIANGLES, 0, 4 * 3 );
70
71 glDisable( GL_BLEND );
72
73 glDisableClientState( GL_VERTEX_ARRAY );
74}
75
76
77void EDA_3D_CANVAS::render_pivot( float t, float aScale )
78{
79 wxASSERT( aScale >= 0.0f );
80 wxASSERT( t >= 0.0f );
81
82 if( t > 1.0f )
83 t = 1.0f;
84
85 const SFVEC3F &lookAtPos = m_camera.GetLookAtPos_T1();
86
87 glDisable( GL_LIGHTING );
88 glDisable( GL_DEPTH_TEST );
89 glDisable( GL_CULL_FACE );
90
91 // Set projection and modelview matrixes
92 glMatrixMode( GL_PROJECTION );
93 glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
94
95 glMatrixMode( GL_MODELVIEW );
96 glLoadIdentity();
97 glLoadMatrixf( glm::value_ptr( m_camera.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 pivot_render_triangles( t * 0.5f );
107
108 t = t * 0.80f;
109 glScalef( 1.0f - t, 1.0f - t, 1.0f - t );
110 glColor4f( 0.0f, 1.0f, 0.0f, 0.8f - t );
111
112 glPushMatrix();
113 glRotatef( t * 90.0f, 0.0f, 0.0f, 1.0f );
114 pivot_render_triangles( t * 0.5f );
115 glPopMatrix();
116
117 glPushMatrix();
118 glRotatef( -t * 90.0f, 0.0f, 0.0f, 1.0f );
119 pivot_render_triangles( t * 0.5f );
120 glPopMatrix();
121}
122
123
125{
126 wxASSERT( aScale >= 0.0f );
127
128 glDisable( GL_LIGHTING );
129 glDisable( GL_DEPTH_TEST );
130 glDisable( GL_CULL_FACE );
131
132 // Set projection and modelview matrixes
133 glMatrixMode( GL_PROJECTION );
134 glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
135
136 glMatrixMode( GL_MODELVIEW );
137 glLoadIdentity();
138 glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
139
140 glEnable( GL_COLOR_MATERIAL );
141 glColor4f( 0.0f, 0.667f, 0.902f, 0.75f );
142
143 // Translate to the look at position
145
146 glPointSize( 16.0f );
147 glEnable( GL_POINT_SMOOTH );
148 glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
149
150 glEnable( GL_BLEND );
151 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
152
153 glScalef( aScale, aScale, aScale );
154
155 // Draw a point at the look at position.
156 glBegin( GL_POINTS );
157 glVertex3f( 0, 0, 0 );
158 glEnd();
159
160 glDisable( GL_BLEND );
161 glDisable( GL_POINT_SMOOTH );
162}
SFVEC3F m_3dmousePivotPos
void render3dmousePivot(float aScale)
Render the 3dmouse pivot cursor.
void render_pivot(float t, float aScale)
Render the pivot cursor.
static void pivot_render_triangles(float t)
Define generic OpenGL functions that are common to any OpenGL target.
glm::vec3 SFVEC3F
Definition xv3d_types.h:44