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, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#include <kicad_gl/kiglu.h> // Must be included first
27
29#include "eda_3d_canvas.h"
30
31
32static void pivot_render_triangles( float t )
33{
34 wxASSERT( t >= 0.0f );
35
36 SFVEC3F vertexPointer[12];
37
38 const float u = 1.0f / 6.0f;
39
40 vertexPointer[0] = SFVEC3F( ( -3.0f + t ) * u, -2.0f * u, 0.0f );
41 vertexPointer[1] = SFVEC3F( ( -3.0f + t ) * u, 2.0f * u, 0.0f );
42 vertexPointer[2] = SFVEC3F( ( -1.0f + t ) * u, 0.0f * u, 0.0f );
43
44 vertexPointer[3] = SFVEC3F( -2.0f * u, ( -3.0f + t ) * u, 0.0f );
45 vertexPointer[4] = SFVEC3F( 2.0f * u, ( -3.0f + t ) * u, 0.0f );
46 vertexPointer[5] = SFVEC3F( 0.0f * u, ( -1.0f + t ) * u, 0.0f );
47
48 vertexPointer[6] = SFVEC3F( ( 3.0f - t ) * u, -2.0f * u, 0.0f );
49 vertexPointer[7] = SFVEC3F( ( 3.0f - t ) * u, 2.0f * u, 0.0f );
50 vertexPointer[8] = SFVEC3F( ( 1.0f - t ) * u, 0.0f * u, 0.0f );
51
52 vertexPointer[9] = SFVEC3F( 2.0f * u, ( 3.0f - t ) * u, 0.0f );
53 vertexPointer[10] = SFVEC3F( -2.0f * u, ( 3.0f - t ) * u, 0.0f );
54 vertexPointer[11] = SFVEC3F( 0.0f * u, ( 1.0f - t ) * u, 0.0f );
55
56 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
57 glDisableClientState( GL_COLOR_ARRAY );
58 glDisableClientState( GL_NORMAL_ARRAY );
59 glEnableClientState( GL_VERTEX_ARRAY );
60 glVertexPointer( 3, GL_FLOAT, 0, vertexPointer );
61
62 glEnable( GL_BLEND );
63 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
64
65 glDrawArrays( GL_TRIANGLES, 0, 4 * 3 );
66
67 glDisable( GL_BLEND );
68
69 glDisableClientState( GL_VERTEX_ARRAY );
70}
71
72
73void EDA_3D_CANVAS::render_pivot( float t, float aScale )
74{
75 wxASSERT( aScale >= 0.0f );
76 wxASSERT( t >= 0.0f );
77
78 if( t > 1.0f )
79 t = 1.0f;
80
81 const SFVEC3F &lookAtPos = m_camera.GetLookAtPos_T1();
82
83 glDisable( GL_LIGHTING );
84 glDisable( GL_DEPTH_TEST );
85 glDisable( GL_CULL_FACE );
86
87 // Set projection and modelview matrixes
88 glMatrixMode( GL_PROJECTION );
89 glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
90
91 glMatrixMode( GL_MODELVIEW );
92 glLoadIdentity();
93 glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
94
95 glEnable( GL_COLOR_MATERIAL );
96 glColor4f( 0.0f, 1.0f, 0.0f, 0.75f - t * 0.75f );
97
98 // Translate to the look at position
99 glTranslatef( lookAtPos.x, lookAtPos.y, lookAtPos.z );
100
101 glScalef( aScale, aScale, aScale );
102 pivot_render_triangles( t * 0.5f );
103
104 t = t * 0.80f;
105 glScalef( 1.0f - t, 1.0f - t, 1.0f - t );
106 glColor4f( 0.0f, 1.0f, 0.0f, 0.8f - t );
107
108 glPushMatrix();
109 glRotatef( t * 90.0f, 0.0f, 0.0f, 1.0f );
110 pivot_render_triangles( t * 0.5f );
111 glPopMatrix();
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
119
121{
122 wxASSERT( aScale >= 0.0f );
123
124 glDisable( GL_LIGHTING );
125 glDisable( GL_DEPTH_TEST );
126 glDisable( GL_CULL_FACE );
127
128 // Set projection and modelview matrixes
129 glMatrixMode( GL_PROJECTION );
130 glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
131
132 glMatrixMode( GL_MODELVIEW );
133 glLoadIdentity();
134 glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
135
136 glEnable( GL_COLOR_MATERIAL );
137 glColor4f( 0.0f, 0.667f, 0.902f, 0.75f );
138
139 // Translate to the look at position
141
142 glPointSize( 16.0f );
143 glEnable( GL_POINT_SMOOTH );
144 glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
145
146 glEnable( GL_BLEND );
147 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
148
149 glScalef( aScale, aScale, aScale );
150
151 // Draw a point at the look at position.
152 glBegin( GL_POINTS );
153 glVertex3f( 0, 0, 0 );
154 glEnd();
155
156 glDisable( GL_BLEND );
157 glDisable( GL_POINT_SMOOTH );
158}
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:40