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-2024 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#include <3d_enums.h>
38
40{
41 ORTHO = 0,
43};
44
50{
62 float nw, nh, fw, fh;
63
65 nc( { 0.0, 0.0, 0.0 } ),
66 fc( { 0.0, 0.0, 0.0 } ),
67 ntl( { 0.0, 0.0, 0.0 } ),
68 ntr( { 0.0, 0.0, 0.0 } ),
69 nbl( { 0.0, 0.0, 0.0 } ),
70 nbr( { 0.0, 0.0, 0.0 } ),
71 ftl( { 0.0, 0.0, 0.0 } ),
72 ftr( { 0.0, 0.0, 0.0 } ),
73 fbl( { 0.0, 0.0, 0.0 } ),
74 fbr( { 0.0, 0.0, 0.0 } ),
75 nearD( 0.0 ),
76 farD( 0.0 ),
77 ratio( 1.0 ),
78 angle( 0.0 ),
79 tang( 0.0 ),
80 nw( 0.0 ),
81 nh( 0.0 ),
82 fw( 0.0 ),
83 fh( 0.0 )
84 {
85 }
86};
87
88
90{
91 LINEAR,
92 EASING_IN_OUT, // Quadratic
93 BEZIER,
94};
95
96
103{
104public:
105 static const float DEFAULT_MIN_ZOOM;
106 static const float DEFAULT_MAX_ZOOM;
107
113 explicit CAMERA( float aInitialDistance );
114 explicit CAMERA( SFVEC3F aInitPos, SFVEC3F aLookat, PROJECTION_TYPE aProjectionType );
115
116 virtual ~CAMERA()
117 {
118 }
119
125 glm::mat4 GetRotationMatrix() const;
126
127 const glm::mat4& GetViewMatrix() const;
128 const glm::mat4& GetViewMatrix_Inv() const;
129
130 const glm::mat4& GetProjectionMatrix() const;
131 const glm::mat4& GetProjectionMatrixInv() const;
132
133 const SFVEC3F& GetRight() const { return m_right; }
134 const SFVEC3F& GetUp() const { return m_up; }
135 const SFVEC3F& GetDir() const { return m_dir; }
136 const SFVEC3F& GetPos() const { return m_pos; }
137 const SFVEC2F& GetFocalLen() const { return m_focalLen; }
138 float GetNear() const { return m_frustum.nearD; }
139 float GetFar() const { return m_frustum.farD; }
140 const CAMERA_FRUSTUM& GetFrustum() const { return m_frustum; }
141 const SFVEC3F& GetLookAtPos() const { return m_lookat_pos; }
142
149 void SetRotationMatrix( const glm::mat4& aRotation );
150
158 void SetViewMatrix( glm::mat4 aViewMatrix );
159
160 void SetBoardLookAtPos( const SFVEC3F& aBoardPos );
161
162 void SetLookAtPos_T1( const SFVEC3F& aLookAtPos )
163 {
164 m_lookat_pos_t1 = aLookAtPos;
165 }
166
167 const SFVEC3F& GetLookAtPos_T1() const { return m_lookat_pos_t1; }
168
169 const SFVEC3F& GetCameraPos() const { return m_camera_pos; }
170 const SFVEC3F& GetCameraInitPos() const { return m_camera_pos_init; }
171
172 float GetCameraMinDimension() const;
173
177 virtual void Drag( const wxPoint& aNewMousePosition ) = 0;
178
179 virtual void Pan( const wxPoint& aNewMousePosition ) = 0;
180
181 virtual void Pan( const SFVEC3F& aDeltaOffsetInc ) = 0;
182
183 virtual void Pan_T1( const SFVEC3F& aDeltaOffsetInc ) = 0;
184
188 virtual void Reset();
189 virtual void Reset_T1();
190
191 void ResetXYpos();
192 void ResetXYpos_T1();
193
197 const wxPoint& GetCurMousePosition() { return m_lastPosition; }
198
202 void SetCurMousePosition( const wxPoint& aPosition );
203
204 void ToggleProjection();
205 PROJECTION_TYPE GetProjection() { return m_projectionType; }
206 void SetProjection( PROJECTION_TYPE aProjection ) { m_projectionType = aProjection; }
207
213 bool SetCurWindowSize( const wxSize& aSize );
214
215 void ZoomReset();
216
217 bool Zoom( float aFactor );
218
219 bool Zoom_T1( float aFactor );
220
221 float GetZoom() const { return m_zoom; }
222
223 float GetMinZoom() { return m_minZoom; }
224 void SetMinZoom( float minZoom )
225 {
226 m_minZoom = minZoom;
227 zoomChanged();
228 }
229
230 float GetMaxZoom() { return m_maxZoom; }
231 void SetMaxZoom( float maxZoom )
232 {
233 m_maxZoom = maxZoom;
234 zoomChanged();
235 }
236
237 bool ViewCommand_T1( VIEW3D_TYPE aRequestedView );
238
242 void RotateScreen( float aAngleInRadians );
243
244 void RotateX( float aAngleInRadians );
245 void RotateY( float aAngleInRadians );
246 void RotateZ( float aAngleInRadians );
247
248 void RotateX_T1( float aAngleInRadians );
249 void RotateY_T1( float aAngleInRadians );
250 void RotateZ_T1( float aAngleInRadians );
251
255 virtual void SetT0_and_T1_current_T();
256
262 virtual void Interpolate( float t );
263
265 {
266 m_interpolation_mode = aInterpolateMode;
267 }
268
272 bool ParametersChanged();
273
277 bool ParametersChangedQuery() const { return m_parametersChanged; }
278
286 void MakeRay( const SFVEC2I& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
287
296 void MakeRay( const SFVEC2F& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
297
304 void MakeRayAtCurrentMousePosition( SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
305
309 void Update() { updateFrustum(); }
310
311protected:
312 void zoomChanged();
313 void rebuildProjection();
314 void updateFrustum();
315 void updateViewMatrix();
316
317 void updateRotationMatrix();
318
322 float m_zoom;
325
331
336
341
344 glm::mat4 m_viewMatrix;
349
351
356
358
363
368
372
374
378 std::vector< float > m_scr_nX;
379 std::vector< float > m_scr_nY;
380
385 std::vector< SFVEC3F > m_right_nX;
386 std::vector< SFVEC3F > m_up_nY;
387
392
400 static const wxChar* m_logTrace;
401};
402
403#endif // CAMERA_H
declared enumerations and flags
VIEW3D_TYPE
Definition: 3d_enums.h:78
CAMERA_INTERPOLATION
Definition: camera.h:90
PROJECTION_TYPE
Definition: camera.h:40
A class used to derive camera objects from.
Definition: camera.h:103
const SFVEC3F & GetRight() const
Definition: camera.h:133
float m_zoom_t0
Definition: camera.h:323
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:391
glm::mat4 m_projectionMatrixInv
Definition: camera.h:347
const CAMERA_FRUSTUM & GetFrustum() const
Definition: camera.h:140
SFVEC3F m_lookat_pos
Definition: camera.h:364
bool ParametersChangedQuery() const
Definition: camera.h:277
void SetMinZoom(float minZoom)
Definition: camera.h:224
void SetProjection(PROJECTION_TYPE aProjection)
Definition: camera.h:206
SFVEC3F m_camera_pos_t0
Definition: camera.h:361
const SFVEC3F & GetPos() const
Definition: camera.h:136
float GetMaxZoom()
Definition: camera.h:230
virtual void Pan(const wxPoint &aNewMousePosition)=0
SFVEC3F m_right
Definition: camera.h:352
float GetNear() const
Definition: camera.h:138
glm::mat4 m_projectionMatrix
Definition: camera.h:346
CAMERA_INTERPOLATION m_interpolation_mode
Definition: camera.h:373
SFVEC3F m_rotate_aux_t1
Definition: camera.h:371
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: camera.h:340
PROJECTION_TYPE GetProjection()
Definition: camera.h:205
static const float DEFAULT_MIN_ZOOM
Definition: camera.h:105
SFVEC3F m_rotate_aux_t0
Definition: camera.h:370
static const float DEFAULT_MAX_ZOOM
Definition: camera.h:106
virtual void Pan_T1(const SFVEC3F &aDeltaOffsetInc)=0
const SFVEC3F & GetUp() const
Definition: camera.h:134
SFVEC3F m_dir
Definition: camera.h:354
virtual ~CAMERA()
Definition: camera.h:116
virtual void Drag(const wxPoint &aNewMousePosition)=0
Calculate a new mouse drag position.
void SetInterpolateMode(CAMERA_INTERPOLATION aInterpolateMode)
Definition: camera.h:264
float GetZoom() const
Definition: camera.h:221
SFVEC3F m_camera_pos_init
Definition: camera.h:359
float m_minZoom
Possible 3D zoom range.
Definition: camera.h:329
float GetFar() const
Definition: camera.h:139
virtual void Pan(const SFVEC3F &aDeltaOffsetInc)=0
float m_maxZoom
Definition: camera.h:330
const SFVEC3F & GetLookAtPos() const
Definition: camera.h:141
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:385
float m_zoom_t1
Definition: camera.h:324
float GetMinZoom()
Definition: camera.h:223
SFVEC3F m_lookat_pos_t1
Definition: camera.h:366
CAMERA_FRUSTUM m_frustum
Definition: camera.h:350
SFVEC3F m_lookat_pos_t0
Definition: camera.h:365
const SFVEC2F & GetFocalLen() const
Definition: camera.h:137
SFVEC3F m_camera_pos
Definition: camera.h:360
PROJECTION_TYPE m_projectionType
Definition: camera.h:348
SFVEC3F m_pos
Definition: camera.h:355
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:335
SFVEC2F m_focalLen
Definition: camera.h:357
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:378
void SetLookAtPos_T1(const SFVEC3F &aLookAtPos)
Definition: camera.h:162
glm::mat4 m_viewMatrixInverse
Definition: camera.h:345
const SFVEC3F & GetLookAtPos_T1() const
Definition: camera.h:167
const wxPoint & GetCurMousePosition()
Get the current mouse position.
Definition: camera.h:197
const SFVEC3F & GetCameraPos() const
Definition: camera.h:169
SFVEC3F m_up
Definition: camera.h:353
const SFVEC3F & GetDir() const
Definition: camera.h:135
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:369
glm::mat4 m_rotationMatrixAux
Definition: camera.h:343
glm::mat4 m_rotationMatrix
Definition: camera.h:342
std::vector< float > m_scr_nY
Definition: camera.h:379
glm::mat4 m_viewMatrix
Definition: camera.h:344
void SetMaxZoom(float maxZoom)
Definition: camera.h:231
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center).
Definition: camera.h:367
const SFVEC3F & GetCameraInitPos() const
Definition: camera.h:170
std::vector< SFVEC3F > m_up_nY
Definition: camera.h:386
SFVEC3F m_camera_pos_t1
Definition: camera.h:362
float m_zoom
3D zoom value – Z-distance is scaled by it
Definition: camera.h:322
void Update()
Update the camera.
Definition: camera.h:309
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:400
Frustum is a implementation based on a tutorial by http://www.lighthouse3d.com/tutorials/view-frustum...
Definition: camera.h:50
SFVEC3F ntr
Near Top Right.
Definition: camera.h:54
SFVEC3F ntl
Near Top Left.
Definition: camera.h:53
SFVEC3F fc
Definition: camera.h:52
float angle
Definition: camera.h:61
float ratio
Definition: camera.h:61
CAMERA_FRUSTUM()
Definition: camera.h:64
float fh
Definition: camera.h:62
float nh
Definition: camera.h:62
SFVEC3F ftl
Far Top Left.
Definition: camera.h:57
SFVEC3F fbr
Far Bottom Right.
Definition: camera.h:60
float fw
Definition: camera.h:62
float farD
Definition: camera.h:61
SFVEC3F nbl
Near Bottom Left.
Definition: camera.h:55
SFVEC3F nc
Definition: camera.h:51
SFVEC3F nbr
Near Bottom Right.
Definition: camera.h:56
float nw
Definition: camera.h:62
SFVEC3F fbl
Far Bottom Left.
Definition: camera.h:59
float tang
Definition: camera.h:61
float nearD
Definition: camera.h:61
SFVEC3F ftr
Far Top Right.
Definition: camera.h:58
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44