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 (C) 1992-2020 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
35static 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
76void 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_camera.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 glMatrixMode( GL_PROJECTION );
92 glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
93
94 glMatrixMode( GL_MODELVIEW );
95 glLoadIdentity();
96 glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
97
98 glEnable( GL_COLOR_MATERIAL );
99 glColor4f( 0.0f, 1.0f, 0.0f, 0.75f - t * 0.75f );
100
101 // Translate to the look at position
102 glTranslatef( lookAtPos.x, lookAtPos.y, lookAtPos.z );
103
104 glScalef( aScale, aScale, aScale );
105 pivot_render_triangles( t * 0.5f );
106
107 t = t * 0.80f;
108 glScalef( 1.0f - t, 1.0f - t, 1.0f - t );
109 glColor4f( 0.0f, 1.0f, 0.0f, 0.8f - t );
110
111 glPushMatrix();
112 glRotatef( t * 90.0f, 0.0f, 0.0f, 1.0f );
113 pivot_render_triangles( t * 0.5f );
114 glPopMatrix();
115
116 glPushMatrix();
117 glRotatef( -t * 90.0f, 0.0f, 0.0f, 1.0f );
118 pivot_render_triangles( t * 0.5f );
119 glPopMatrix();
120}
121
122
124{
125 wxASSERT( aScale >= 0.0f );
126
127 glDisable( GL_LIGHTING );
128 glDisable( GL_DEPTH_TEST );
129 glDisable( GL_CULL_FACE );
130
131 // Set projection and modelview matrixes
132 glMatrixMode( GL_PROJECTION );
133 glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
134
135 glMatrixMode( GL_MODELVIEW );
136 glLoadIdentity();
137 glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
138
139 glEnable( GL_COLOR_MATERIAL );
140 glColor4f( 0.0f, 0.667f, 0.902f, 0.75f );
141
142 // Translate to the look at position
144
145 glPointSize( 16.0f );
146 glEnable( GL_POINT_SMOOTH );
147 glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
148
149 glEnable( GL_BLEND );
150 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
151
152 glScalef( aScale, aScale, aScale );
153
154 // Draw a point at the look at position.
155 glBegin( GL_POINTS );
156 glVertex3f( 0, 0, 0 );
157 glEnd();
158
159 glDisable( GL_BLEND );
160 glDisable( GL_POINT_SMOOTH );
161}
const glm::mat4 & GetProjectionMatrix() const
Definition: camera.cpp:473
const glm::mat4 & GetViewMatrix() const
Definition: camera.cpp:509
const SFVEC3F & GetLookAtPos_T1() const
Definition: camera.h:167
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)
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44