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 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#ifndef CAMERA_H
27#define CAMERA_H
28
29#include <gal/gal.h>
31#include <wx/gdicmn.h> // for wxSize
32#include <vector>
33#include <3d_enums.h>
34
36{
37 ORTHO = 0,
39};
40
46{
58 float nw, nh, fw, fh;
59
61 nc( { 0.0, 0.0, 0.0 } ),
62 fc( { 0.0, 0.0, 0.0 } ),
63 ntl( { 0.0, 0.0, 0.0 } ),
64 ntr( { 0.0, 0.0, 0.0 } ),
65 nbl( { 0.0, 0.0, 0.0 } ),
66 nbr( { 0.0, 0.0, 0.0 } ),
67 ftl( { 0.0, 0.0, 0.0 } ),
68 ftr( { 0.0, 0.0, 0.0 } ),
69 fbl( { 0.0, 0.0, 0.0 } ),
70 fbr( { 0.0, 0.0, 0.0 } ),
71 nearD( 0.0 ),
72 farD( 0.0 ),
73 ratio( 1.0 ),
74 angle( 0.0 ),
75 tang( 0.0 ),
76 nw( 0.0 ),
77 nh( 0.0 ),
78 fw( 0.0 ),
79 fh( 0.0 )
80 {
81 }
82};
83
84
86{
88 EASING_IN_OUT, // Quadratic
90};
91
92
99{
100public:
101 static const float DEFAULT_MIN_ZOOM;
102 static const float DEFAULT_MAX_ZOOM;
103
109 explicit CAMERA( float aInitialDistance );
110 explicit CAMERA( SFVEC3F aInitPos, SFVEC3F aLookat, PROJECTION_TYPE aProjectionType );
111
112 virtual ~CAMERA()
113 {
114 }
115
121 glm::mat4 GetRotationMatrix() const;
122
123 const glm::mat4& GetViewMatrix() const;
124 const glm::mat4& GetViewMatrix_Inv() const;
125
126 const glm::mat4& GetProjectionMatrix() const;
127 const glm::mat4& GetProjectionMatrixInv() const;
128
129 const SFVEC3F& GetRight() const { return m_right; }
130 const SFVEC3F& GetUp() const { return m_up; }
131 const SFVEC3F& GetDir() const { return m_dir; }
132 const SFVEC3F& GetPos() const { return m_pos; }
133 const SFVEC2F& GetFocalLen() const { return m_focalLen; }
134 float GetNear() const { return m_frustum.nearD; }
135 float GetFar() const { return m_frustum.farD; }
136 const CAMERA_FRUSTUM& GetFrustum() const { return m_frustum; }
137 const SFVEC3F& GetLookAtPos() const { return m_lookat_pos; }
138
145 void SetRotationMatrix( const glm::mat4& aRotation );
146
154 void SetViewMatrix( glm::mat4 aViewMatrix );
155
156 void SetBoardLookAtPos( const SFVEC3F& aBoardPos );
157
158 void SetLookAtPos_T1( const SFVEC3F& aLookAtPos )
159 {
160 m_lookat_pos_t1 = aLookAtPos;
161 }
162
163 const SFVEC3F& GetLookAtPos_T1() const { return m_lookat_pos_t1; }
164
165 const SFVEC3F& GetCameraPos() const { return m_camera_pos; }
166 const SFVEC3F& GetCameraInitPos() const { return m_camera_pos_init; }
167
168 float GetCameraMinDimension() const;
169
173 virtual void Drag( const wxPoint& aNewMousePosition ) = 0;
174
175 virtual void Pan( const wxPoint& aNewMousePosition ) = 0;
176
177 virtual void Pan( const SFVEC3F& aDeltaOffsetInc ) = 0;
178
179 virtual void Pan_T1( const SFVEC3F& aDeltaOffsetInc ) = 0;
180
184 virtual void Reset();
185 virtual void Reset_T1();
186
187 void ResetXYpos();
188 void ResetXYpos_T1();
189
193 const wxPoint& GetCurMousePosition() { return m_lastPosition; }
194
198 void SetCurMousePosition( const wxPoint& aPosition );
199
200 void ToggleProjection();
202 void SetProjection( PROJECTION_TYPE aProjection ) { m_projectionType = aProjection; }
203
209 bool SetCurWindowSize( const wxSize& aSize );
210
211 void ZoomReset();
212
213 bool Zoom( float aFactor );
214
215 bool Zoom_T1( float aFactor );
216
217 float GetZoom() const { return m_zoom; }
218
219 float GetMinZoom() { return m_minZoom; }
220 void SetMinZoom( float minZoom )
221 {
222 m_minZoom = minZoom;
223 zoomChanged();
224 }
225
226 float GetMaxZoom() { return m_maxZoom; }
227 void SetMaxZoom( float maxZoom )
228 {
229 m_maxZoom = maxZoom;
230 zoomChanged();
231 }
232
233 bool ViewCommand_T1( VIEW3D_TYPE aRequestedView );
234
238 void RotateScreen( float aAngleInRadians );
239
240 void RotateX( float aAngleInRadians );
241 void RotateY( float aAngleInRadians );
242 void RotateZ( float aAngleInRadians );
243
244 void RotateX_T1( float aAngleInRadians );
245 void RotateY_T1( float aAngleInRadians );
246 void RotateZ_T1( float aAngleInRadians );
247
251 virtual void SetT0_and_T1_current_T();
252
258 virtual void Interpolate( float t );
259
261 {
262 m_interpolation_mode = aInterpolateMode;
263 }
264
268 bool ParametersChanged();
269
274
282 void MakeRay( const SFVEC2I& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
283
292 void MakeRay( const SFVEC2F& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
293
300 void MakeRayAtCurrentMousePosition( SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
301
305 void Update() { updateFrustum(); }
306
307protected:
308 void zoomChanged();
309 void rebuildProjection();
310 void updateFrustum();
311 void updateViewMatrix();
312
313 void updateRotationMatrix();
314
318 float m_zoom;
321
327
332
337
340 glm::mat4 m_viewMatrix;
345
347
352
354
359
364
368
370
374 std::vector< float > m_scr_nX;
375 std::vector< float > m_scr_nY;
376
381 std::vector< SFVEC3F > m_right_nX;
382 std::vector< SFVEC3F > m_up_nY;
383
388
396 static const wxChar* m_logTrace;
397};
398
399#endif // CAMERA_H
declared enumerations and flags
VIEW3D_TYPE
Definition 3d_enums.h:74
CAMERA_INTERPOLATION
Definition camera.h:86
PROJECTION_TYPE
Definition camera.h:36
Generic cubic Bezier representation.
const SFVEC3F & GetRight() const
Definition camera.h:129
float m_zoom_t0
Definition camera.h:319
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition camera.h:387
glm::mat4 m_projectionMatrixInv
Definition camera.h:343
const CAMERA_FRUSTUM & GetFrustum() const
Definition camera.h:136
SFVEC3F m_lookat_pos
Definition camera.h:360
bool ParametersChangedQuery() const
Definition camera.h:273
void SetMinZoom(float minZoom)
Definition camera.h:220
void SetProjection(PROJECTION_TYPE aProjection)
Definition camera.h:202
SFVEC3F m_camera_pos_t0
Definition camera.h:357
const SFVEC3F & GetPos() const
Definition camera.h:132
float GetMaxZoom()
Definition camera.h:226
virtual void Pan(const wxPoint &aNewMousePosition)=0
SFVEC3F m_right
Definition camera.h:348
float GetNear() const
Definition camera.h:134
glm::mat4 m_projectionMatrix
Definition camera.h:342
CAMERA_INTERPOLATION m_interpolation_mode
Definition camera.h:369
SFVEC3F m_rotate_aux_t1
Definition camera.h:367
wxPoint m_lastPosition
The last mouse position in the screen.
Definition camera.h:336
void ResetXYpos()
Definition camera.cpp:488
PROJECTION_TYPE GetProjection()
Definition camera.h:201
static const float DEFAULT_MIN_ZOOM
Definition camera.h:101
SFVEC3F m_rotate_aux_t0
Definition camera.h:366
virtual void Reset_T1()
Definition camera.cpp:157
static const float DEFAULT_MAX_ZOOM
Definition camera.h:102
virtual void Pan_T1(const SFVEC3F &aDeltaOffsetInc)=0
const SFVEC3F & GetUp() const
Definition camera.h:130
SFVEC3F m_dir
Definition camera.h:350
virtual ~CAMERA()
Definition camera.h:112
virtual void Drag(const wxPoint &aNewMousePosition)=0
Calculate a new mouse drag position.
void SetInterpolateMode(CAMERA_INTERPOLATION aInterpolateMode)
Definition camera.h:260
float GetZoom() const
Definition camera.h:217
SFVEC3F m_camera_pos_init
Definition camera.h:355
CAMERA(float aInitialDistance)
Initialize a camera.
Definition camera.cpp:50
void ResetXYpos_T1()
Definition camera.cpp:499
float m_minZoom
Possible 3D zoom range.
Definition camera.h:325
float GetFar() const
Definition camera.h:135
virtual void Pan(const SFVEC3F &aDeltaOffsetInc)=0
float m_maxZoom
Definition camera.h:326
const SFVEC3F & GetLookAtPos() const
Definition camera.h:137
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:381
float m_zoom_t1
Definition camera.h:320
float GetMinZoom()
Definition camera.h:219
SFVEC3F m_lookat_pos_t1
Definition camera.h:362
CAMERA_FRUSTUM m_frustum
Definition camera.h:346
void updateFrustum()
Definition camera.cpp:345
SFVEC3F m_lookat_pos_t0
Definition camera.h:361
const SFVEC2F & GetFocalLen() const
Definition camera.h:133
SFVEC3F m_camera_pos
Definition camera.h:356
PROJECTION_TYPE m_projectionType
Definition camera.h:344
SFVEC3F m_pos
Definition camera.h:351
SFVEC2I m_windowSize
The window size that this camera is working.
Definition camera.h:331
SFVEC2F m_focalLen
Definition camera.h:353
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:374
void SetLookAtPos_T1(const SFVEC3F &aLookAtPos)
Definition camera.h:158
glm::mat4 m_viewMatrixInverse
Definition camera.h:341
const SFVEC3F & GetLookAtPos_T1() const
Definition camera.h:163
const wxPoint & GetCurMousePosition()
Get the current mouse position.
Definition camera.h:193
const SFVEC3F & GetCameraPos() const
Definition camera.h:165
SFVEC3F m_up
Definition camera.h:349
const SFVEC3F & GetDir() const
Definition camera.h:131
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition camera.h:365
glm::mat4 m_rotationMatrixAux
Definition camera.h:339
glm::mat4 m_rotationMatrix
Definition camera.h:338
std::vector< float > m_scr_nY
Definition camera.h:375
glm::mat4 m_viewMatrix
Definition camera.h:340
void SetMaxZoom(float maxZoom)
Definition camera.h:227
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center).
Definition camera.h:363
const SFVEC3F & GetCameraInitPos() const
Definition camera.h:166
std::vector< SFVEC3F > m_up_nY
Definition camera.h:382
SFVEC3F m_camera_pos_t1
Definition camera.h:358
float m_zoom
3D zoom value – Z-distance is scaled by it
Definition camera.h:318
void Update()
Update the camera.
Definition camera.h:305
void zoomChanged()
Definition camera.cpp:193
void Reset() override
#define GAL_API
Definition gal.h:27
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Definition camera.h:396
Frustum is a implementation based on a tutorial by http://www.lighthouse3d.com/tutorials/view-frustum...
Definition camera.h:46
SFVEC3F ntr
Near Top Right.
Definition camera.h:50
SFVEC3F ntl
Near Top Left.
Definition camera.h:49
SFVEC3F fc
Definition camera.h:48
float angle
Definition camera.h:57
float ratio
Definition camera.h:57
SFVEC3F ftl
Far Top Left.
Definition camera.h:53
SFVEC3F fbr
Far Bottom Right.
Definition camera.h:56
float farD
Definition camera.h:57
SFVEC3F nbl
Near Bottom Left.
Definition camera.h:51
SFVEC3F nc
Definition camera.h:47
SFVEC3F nbr
Near Bottom Right.
Definition camera.h:52
SFVEC3F fbl
Far Bottom Left.
Definition camera.h:55
float tang
Definition camera.h:57
float nearD
Definition camera.h:57
SFVEC3F ftr
Far Top Right.
Definition camera.h:54
glm::ivec2 SFVEC2I
Definition xv3d_types.h:35
glm::vec2 SFVEC2F
Definition xv3d_types.h:38
glm::vec3 SFVEC3F
Definition xv3d_types.h:40