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
35
41{
53 float nw, nh, fw, fh;
54
56 nc( { 0.0, 0.0, 0.0 } ),
57 fc( { 0.0, 0.0, 0.0 } ),
58 ntl( { 0.0, 0.0, 0.0 } ),
59 ntr( { 0.0, 0.0, 0.0 } ),
60 nbl( { 0.0, 0.0, 0.0 } ),
61 nbr( { 0.0, 0.0, 0.0 } ),
62 ftl( { 0.0, 0.0, 0.0 } ),
63 ftr( { 0.0, 0.0, 0.0 } ),
64 fbl( { 0.0, 0.0, 0.0 } ),
65 fbr( { 0.0, 0.0, 0.0 } ),
66 nearD( 0.0 ),
67 farD( 0.0 ),
68 ratio( 1.0 ),
69 angle( 0.0 ),
70 tang( 0.0 ),
71 nw( 0.0 ),
72 nh( 0.0 ),
73 fw( 0.0 ),
74 fh( 0.0 )
75 {
76 }
77};
78
79
81{
83 EASING_IN_OUT, // Quadratic
85};
86
87
94{
95public:
96 static const float DEFAULT_MIN_ZOOM;
97 static const float DEFAULT_MAX_ZOOM;
98
104 explicit CAMERA( float aInitialDistance );
105 explicit CAMERA( SFVEC3F aInitPos, SFVEC3F aLookat, PROJECTION_TYPE aProjectionType );
106
107 virtual ~CAMERA()
108 {
109 }
110
116 glm::mat4 GetRotationMatrix() const;
117
118 const glm::mat4& GetViewMatrix() const;
119 const glm::mat4& GetViewMatrix_Inv() const;
120
121 const glm::mat4& GetProjectionMatrix() const;
122 const glm::mat4& GetProjectionMatrixInv() const;
123
124 const SFVEC3F& GetRight() const { return m_right; }
125 const SFVEC3F& GetUp() const { return m_up; }
126 const SFVEC3F& GetDir() const { return m_dir; }
127 const SFVEC3F& GetPos() const { return m_pos; }
128 const SFVEC2F& GetFocalLen() const { return m_focalLen; }
129 float GetNear() const { return m_frustum.nearD; }
130 float GetFar() const { return m_frustum.farD; }
131 const CAMERA_FRUSTUM& GetFrustum() const { return m_frustum; }
132 const SFVEC3F& GetLookAtPos() const { return m_lookat_pos; }
133
140 void SetRotationMatrix( const glm::mat4& aRotation );
141
149 void SetViewMatrix( glm::mat4 aViewMatrix );
150
151 void SetBoardLookAtPos( const SFVEC3F& aBoardPos );
152
153 void SetLookAtPos_T1( const SFVEC3F& aLookAtPos )
154 {
155 m_lookat_pos_t1 = aLookAtPos;
156 }
157
158 const SFVEC3F& GetLookAtPos_T1() const { return m_lookat_pos_t1; }
159
160 const SFVEC3F& GetCameraPos() const { return m_camera_pos; }
161 const SFVEC3F& GetCameraInitPos() const { return m_camera_pos_init; }
162
163 float GetCameraMinDimension() const;
164
168 virtual void Drag( const wxPoint& aNewMousePosition ) = 0;
169
170 virtual void Pan( const wxPoint& aNewMousePosition ) = 0;
171
172 virtual void Pan( const SFVEC3F& aDeltaOffsetInc ) = 0;
173
174 virtual void Pan_T1( const SFVEC3F& aDeltaOffsetInc ) = 0;
175
179 virtual void Reset();
180 virtual void Reset_T1();
181
182 void ResetXYpos();
183 void ResetXYpos_T1();
184
188 const wxPoint& GetCurMousePosition() { return m_lastPosition; }
189
193 void SetCurMousePosition( const wxPoint& aPosition );
194
195 void ToggleProjection();
197 void SetProjection( PROJECTION_TYPE aProjection ) { m_projectionType = aProjection; }
198
204 bool SetCurWindowSize( const wxSize& aSize );
205
206 void ZoomReset();
207
208 bool Zoom( float aFactor );
209
210 bool Zoom_T1( float aFactor );
211
212 float GetZoom() const { return m_zoom; }
213
214 float GetMinZoom() { return m_minZoom; }
215 void SetMinZoom( float minZoom )
216 {
217 m_minZoom = minZoom;
218 zoomChanged();
219 }
220
221 float GetMaxZoom() { return m_maxZoom; }
222 void SetMaxZoom( float maxZoom )
223 {
224 m_maxZoom = maxZoom;
225 zoomChanged();
226 }
227
228 bool ViewCommand_T1( VIEW3D_TYPE aRequestedView );
229
233 void RotateScreen( float aAngleInRadians );
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
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
declared enumerations and flags
VIEW3D_TYPE
Definition 3d_enums.h:81
PROJECTION_TYPE
Camera projection types.
Definition 3d_enums.h:50
CAMERA_INTERPOLATION
Definition camera.h:81
Generic cubic Bezier representation.
const SFVEC3F & GetRight() const
Definition camera.h:124
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:131
SFVEC3F m_lookat_pos
Definition camera.h:355
bool ParametersChangedQuery() const
Definition camera.h:268
void SetMinZoom(float minZoom)
Definition camera.h:215
void SetProjection(PROJECTION_TYPE aProjection)
Definition camera.h:197
SFVEC3F m_camera_pos_t0
Definition camera.h:352
const SFVEC3F & GetPos() const
Definition camera.h:127
float GetMaxZoom()
Definition camera.h:221
virtual void Pan(const wxPoint &aNewMousePosition)=0
SFVEC3F m_right
Definition camera.h:343
float GetNear() const
Definition camera.h:129
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
void ResetXYpos()
Definition camera.cpp:488
PROJECTION_TYPE GetProjection()
Definition camera.h:196
static const float DEFAULT_MIN_ZOOM
Definition camera.h:96
SFVEC3F m_rotate_aux_t0
Definition camera.h:361
virtual void Reset_T1()
Definition camera.cpp:157
static const float DEFAULT_MAX_ZOOM
Definition camera.h:97
virtual void Pan_T1(const SFVEC3F &aDeltaOffsetInc)=0
const SFVEC3F & GetUp() const
Definition camera.h:125
SFVEC3F m_dir
Definition camera.h:345
virtual ~CAMERA()
Definition camera.h:107
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:212
SFVEC3F m_camera_pos_init
Definition camera.h:350
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:320
float GetFar() const
Definition camera.h:130
virtual void Pan(const SFVEC3F &aDeltaOffsetInc)=0
float m_maxZoom
Definition camera.h:321
const SFVEC3F & GetLookAtPos() const
Definition camera.h:132
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:214
SFVEC3F m_lookat_pos_t1
Definition camera.h:357
CAMERA_FRUSTUM m_frustum
Definition camera.h:341
void updateFrustum()
Definition camera.cpp:345
SFVEC3F m_lookat_pos_t0
Definition camera.h:356
const SFVEC2F & GetFocalLen() const
Definition camera.h:128
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:153
glm::mat4 m_viewMatrixInverse
Definition camera.h:336
const SFVEC3F & GetLookAtPos_T1() const
Definition camera.h:158
const wxPoint & GetCurMousePosition()
Get the current mouse position.
Definition camera.h:188
const SFVEC3F & GetCameraPos() const
Definition camera.h:160
SFVEC3F m_up
Definition camera.h:344
const SFVEC3F & GetDir() const
Definition camera.h:126
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:222
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center).
Definition camera.h:358
const SFVEC3F & GetCameraInitPos() const
Definition camera.h:161
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 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:391
Frustum is a implementation based on a tutorial by http://www.lighthouse3d.com/tutorials/view-frustum...
Definition camera.h:41
SFVEC3F ntr
Near Top Right.
Definition camera.h:45
SFVEC3F ntl
Near Top Left.
Definition camera.h:44
SFVEC3F fc
Definition camera.h:43
float angle
Definition camera.h:52
float ratio
Definition camera.h:52
SFVEC3F ftl
Far Top Left.
Definition camera.h:48
SFVEC3F fbr
Far Bottom Right.
Definition camera.h:51
float farD
Definition camera.h:52
SFVEC3F nbl
Near Bottom Left.
Definition camera.h:46
SFVEC3F nc
Definition camera.h:42
SFVEC3F nbr
Near Bottom Right.
Definition camera.h:47
SFVEC3F fbl
Far Bottom Left.
Definition camera.h:50
float tang
Definition camera.h:52
float nearD
Definition camera.h:52
SFVEC3F ftr
Far Top Right.
Definition camera.h:49
glm::ivec2 SFVEC2I
Definition xv3d_types.h:35
glm::vec2 SFVEC2F
Definition xv3d_types.h:38
glm::vec3 SFVEC3F
Definition xv3d_types.h:40