KiCad PCB EDA Suite
Loading...
Searching...
No Matches
camera.h
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) 2015-2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2015-2023 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#ifndef CAMERA_H
31#define CAMERA_H
32
33#include <gal/gal.h>
35#include <wx/gdicmn.h> // for wxSize
36#include <vector>
37
39{
40 ORTHO = 0,
42};
43
49{
61 float nw, nh, fw, fh;
62
64 nc( { 0.0, 0.0, 0.0 } ),
65 fc( { 0.0, 0.0, 0.0 } ),
66 ntl( { 0.0, 0.0, 0.0 } ),
67 ntr( { 0.0, 0.0, 0.0 } ),
68 nbl( { 0.0, 0.0, 0.0 } ),
69 nbr( { 0.0, 0.0, 0.0 } ),
70 ftl( { 0.0, 0.0, 0.0 } ),
71 ftr( { 0.0, 0.0, 0.0 } ),
72 fbl( { 0.0, 0.0, 0.0 } ),
73 fbr( { 0.0, 0.0, 0.0 } ),
74 nearD( 0.0 ),
75 farD( 0.0 ),
76 ratio( 1.0 ),
77 angle( 0.0 ),
78 tang( 0.0 ),
79 nw( 0.0 ),
80 nh( 0.0 ),
81 fw( 0.0 ),
82 fh( 0.0 )
83 {
84 }
85};
86
87
89{
90 LINEAR,
91 EASING_IN_OUT, // Quadratic
92 BEZIER,
93};
94
95
102{
103public:
104 static const float DEFAULT_MIN_ZOOM;
105 static const float DEFAULT_MAX_ZOOM;
106
112 explicit CAMERA( float aInitialDistance );
113
114 virtual ~CAMERA()
115 {
116 }
117
123 glm::mat4 GetRotationMatrix() const;
124
125 const glm::mat4& GetViewMatrix() const;
126 const glm::mat4& GetViewMatrix_Inv() const;
127
128 const glm::mat4& GetProjectionMatrix() const;
129 const glm::mat4& GetProjectionMatrixInv() const;
130
131 const SFVEC3F& GetRight() const { return m_right; }
132 const SFVEC3F& GetUp() const { return m_up; }
133 const SFVEC3F& GetDir() const { return m_dir; }
134 const SFVEC3F& GetPos() const { return m_pos; }
135 const SFVEC2F& GetFocalLen() const { return m_focalLen; }
136 float GetNear() const { return m_frustum.nearD; }
137 float GetFar() const { return m_frustum.farD; }
138 const CAMERA_FRUSTUM& GetFrustum() const { return m_frustum; }
139 const SFVEC3F& GetLookAtPos() const { return m_lookat_pos; }
140
147 void SetRotationMatrix( const glm::mat4& aRotation );
148
156 void SetViewMatrix( glm::mat4 aViewMatrix );
157
158 void SetBoardLookAtPos( const SFVEC3F& aBoardPos );
159
160 void SetLookAtPos_T1( const SFVEC3F& aLookAtPos )
161 {
162 m_lookat_pos_t1 = aLookAtPos;
163 }
164
165 const SFVEC3F& GetLookAtPos_T1() const { return m_lookat_pos_t1; }
166
167 const SFVEC3F& GetCameraPos() const { return m_camera_pos; }
168 const SFVEC3F& GetCameraInitPos() const { return m_camera_pos_init; }
169
170 float GetCameraMinDimension() const;
171
175 virtual void Drag( const wxPoint& aNewMousePosition ) = 0;
176
177 virtual void Pan( const wxPoint& aNewMousePosition ) = 0;
178
179 virtual void Pan( const SFVEC3F& aDeltaOffsetInc ) = 0;
180
181 virtual void Pan_T1( const SFVEC3F& aDeltaOffsetInc ) = 0;
182
186 virtual void Reset();
187 virtual void Reset_T1();
188
189 void ResetXYpos();
190 void ResetXYpos_T1();
191
195 const wxPoint& GetCurMousePosition() { return m_lastPosition; }
196
200 void SetCurMousePosition( const wxPoint& aPosition );
201
202 void ToggleProjection();
203 PROJECTION_TYPE GetProjection() { return m_projectionType; }
204 void SetProjection( PROJECTION_TYPE aProjection ) { m_projectionType = aProjection; }
205
211 bool SetCurWindowSize( const wxSize& aSize );
212
213 void ZoomReset();
214
215 bool Zoom( float aFactor );
216
217 bool Zoom_T1( float aFactor );
218
219 float GetZoom() const { return m_zoom; }
220
221 float GetMinZoom() { return m_minZoom; }
222 void SetMinZoom( float minZoom )
223 {
224 m_minZoom = minZoom;
225 zoomChanged();
226 }
227
228 float GetMaxZoom() { return m_maxZoom; }
229 void SetMaxZoom( float maxZoom )
230 {
231 m_maxZoom = maxZoom;
232 zoomChanged();
233 }
234
235 void RotateX( float aAngleInRadians );
236 void RotateY( float aAngleInRadians );
237 void RotateZ( float aAngleInRadians );
238
239 void RotateX_T1( float aAngleInRadians );
240 void RotateY_T1( float aAngleInRadians );
241 void RotateZ_T1( float aAngleInRadians );
242
246 virtual void SetT0_and_T1_current_T();
247
253 virtual void Interpolate( float t );
254
256 {
257 m_interpolation_mode = aInterpolateMode;
258 }
259
263 bool ParametersChanged();
264
268 bool ParametersChangedQuery() const { return m_parametersChanged; }
269
277 void MakeRay( const SFVEC2I& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
278
287 void MakeRay( const SFVEC2F& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
288
295 void MakeRayAtCurrentMousePosition( SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
296
300 void Update() { updateFrustum(); }
301
302protected:
303 void zoomChanged();
304 void rebuildProjection();
305 void updateFrustum();
306 void updateViewMatrix();
307
308 void updateRotationMatrix();
309
313 float m_zoom;
316
322
327
332
335 glm::mat4 m_viewMatrix;
340
342
347
349
354
359
363
365
369 std::vector< float > m_scr_nX;
370 std::vector< float > m_scr_nY;
371
376 std::vector< SFVEC3F > m_right_nX;
377 std::vector< SFVEC3F > m_up_nY;
378
383
391 static const wxChar* m_logTrace;
392};
393
394#endif // CAMERA_H
CAMERA_INTERPOLATION
Definition: camera.h:89
PROJECTION_TYPE
Definition: camera.h:39
A class used to derive camera objects from.
Definition: camera.h:102
const SFVEC3F & GetRight() const
Definition: camera.h:131
float m_zoom_t0
Definition: camera.h:314
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:382
glm::mat4 m_projectionMatrixInv
Definition: camera.h:338
const CAMERA_FRUSTUM & GetFrustum() const
Definition: camera.h:138
SFVEC3F m_lookat_pos
Definition: camera.h:355
bool ParametersChangedQuery() const
Definition: camera.h:268
void SetMinZoom(float minZoom)
Definition: camera.h:222
void SetProjection(PROJECTION_TYPE aProjection)
Definition: camera.h:204
SFVEC3F m_camera_pos_t0
Definition: camera.h:352
const SFVEC3F & GetPos() const
Definition: camera.h:134
float GetMaxZoom()
Definition: camera.h:228
virtual void Pan(const wxPoint &aNewMousePosition)=0
SFVEC3F m_right
Definition: camera.h:343
float GetNear() const
Definition: camera.h:136
glm::mat4 m_projectionMatrix
Definition: camera.h:337
CAMERA_INTERPOLATION m_interpolation_mode
Definition: camera.h:364
SFVEC3F m_rotate_aux_t1
Definition: camera.h:362
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: camera.h:331
PROJECTION_TYPE GetProjection()
Definition: camera.h:203
static const float DEFAULT_MIN_ZOOM
Definition: camera.h:104
SFVEC3F m_rotate_aux_t0
Definition: camera.h:361
static const float DEFAULT_MAX_ZOOM
Definition: camera.h:105
virtual void Pan_T1(const SFVEC3F &aDeltaOffsetInc)=0
const SFVEC3F & GetUp() const
Definition: camera.h:132
SFVEC3F m_dir
Definition: camera.h:345
virtual ~CAMERA()
Definition: camera.h:114
virtual void Drag(const wxPoint &aNewMousePosition)=0
Calculate a new mouse drag position.
void SetInterpolateMode(CAMERA_INTERPOLATION aInterpolateMode)
Definition: camera.h:255
float GetZoom() const
Definition: camera.h:219
SFVEC3F m_camera_pos_init
Definition: camera.h:350
float m_minZoom
Possible 3D zoom range.
Definition: camera.h:320
float GetFar() const
Definition: camera.h:137
virtual void Pan(const SFVEC3F &aDeltaOffsetInc)=0
float m_maxZoom
Definition: camera.h:321
const SFVEC3F & GetLookAtPos() const
Definition: camera.h:139
std::vector< SFVEC3F > m_right_nX
Precalc values array used to calc ray for each pixel, for X and Y axis of each new camera position.
Definition: camera.h:376
float m_zoom_t1
Definition: camera.h:315
float GetMinZoom()
Definition: camera.h:221
SFVEC3F m_lookat_pos_t1
Definition: camera.h:357
CAMERA_FRUSTUM m_frustum
Definition: camera.h:341
SFVEC3F m_lookat_pos_t0
Definition: camera.h:356
const SFVEC2F & GetFocalLen() const
Definition: camera.h:135
SFVEC3F m_camera_pos
Definition: camera.h:351
PROJECTION_TYPE m_projectionType
Definition: camera.h:339
SFVEC3F m_pos
Definition: camera.h:346
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:326
SFVEC2F m_focalLen
Definition: camera.h:348
std::vector< float > m_scr_nX
Precalc values array used to calc ray for each pixel (constant for the same window size).
Definition: camera.h:369
void SetLookAtPos_T1(const SFVEC3F &aLookAtPos)
Definition: camera.h:160
glm::mat4 m_viewMatrixInverse
Definition: camera.h:336
const SFVEC3F & GetLookAtPos_T1() const
Definition: camera.h:165
const wxPoint & GetCurMousePosition()
Get the current mouse position.
Definition: camera.h:195
const SFVEC3F & GetCameraPos() const
Definition: camera.h:167
SFVEC3F m_up
Definition: camera.h:344
const SFVEC3F & GetDir() const
Definition: camera.h:133
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:360
glm::mat4 m_rotationMatrixAux
Definition: camera.h:334
glm::mat4 m_rotationMatrix
Definition: camera.h:333
std::vector< float > m_scr_nY
Definition: camera.h:370
glm::mat4 m_viewMatrix
Definition: camera.h:335
void SetMaxZoom(float maxZoom)
Definition: camera.h:229
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center).
Definition: camera.h:358
const SFVEC3F & GetCameraInitPos() const
Definition: camera.h:168
std::vector< SFVEC3F > m_up_nY
Definition: camera.h:377
SFVEC3F m_camera_pos_t1
Definition: camera.h:353
float m_zoom
3D zoom value – Z-distance is scaled by it
Definition: camera.h:313
void Update()
Update the camera.
Definition: camera.h:300
void Reset() override
#define GAL_API
Definition: gal.h:28
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Definition: camera.h:391
Frustum is a implementation based on a tutorial by http://www.lighthouse3d.com/tutorials/view-frustum...
Definition: camera.h:49
SFVEC3F ntr
Near Top Right.
Definition: camera.h:53
SFVEC3F ntl
Near Top Left.
Definition: camera.h:52
SFVEC3F fc
Definition: camera.h:51
float angle
Definition: camera.h:60
float ratio
Definition: camera.h:60
CAMERA_FRUSTUM()
Definition: camera.h:63
float fh
Definition: camera.h:61
float nh
Definition: camera.h:61
SFVEC3F ftl
Far Top Left.
Definition: camera.h:56
SFVEC3F fbr
Far Bottom Right.
Definition: camera.h:59
float fw
Definition: camera.h:61
float farD
Definition: camera.h:60
SFVEC3F nbl
Near Bottom Left.
Definition: camera.h:54
SFVEC3F nc
Definition: camera.h:50
SFVEC3F nbr
Near Bottom Right.
Definition: camera.h:55
float nw
Definition: camera.h:61
SFVEC3F fbl
Far Bottom Left.
Definition: camera.h:58
float tang
Definition: camera.h:60
float nearD
Definition: camera.h:60
SFVEC3F ftr
Far Top Right.
Definition: camera.h:57
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44