KiCad PCB EDA Suite
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-2020 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 "../3d_rendering/raytracing/ray.h"
34#include <wx/gdicmn.h> // for wxSize
35#include <vector>
36
38{
39 ORTHO = 0,
41};
42
48{
60 float nw, nh, fw, fh;
61};
62
63
65{
66 LINEAR,
67 EASING_IN_OUT, // Quadratic
68 BEZIER,
69};
70
71
77class CAMERA
78{
79public:
85 explicit CAMERA( float aInitialDistance );
86
87 virtual ~CAMERA()
88 {
89 }
90
96 glm::mat4 GetRotationMatrix() const;
97
98 const glm::mat4& GetViewMatrix() const;
99 const glm::mat4& GetViewMatrix_Inv() const;
100
101 const glm::mat4& GetProjectionMatrix() const;
102 const glm::mat4& GetProjectionMatrixInv() const;
103
104 const SFVEC3F& GetRight() const { return m_right; }
105 const SFVEC3F& GetUp() const { return m_up; }
106 const SFVEC3F& GetDir() const { return m_dir; }
107 const SFVEC3F& GetPos() const { return m_pos; }
108 const SFVEC2F& GetFocalLen() const { return m_focalLen; }
109 float GetNear() const { return m_frustum.nearD; }
110 float GetFar() const { return m_frustum.farD; }
111 const CAMERA_FRUSTUM& GetFrustum() const { return m_frustum; }
112 const SFVEC3F& GetLookAtPos() const { return m_lookat_pos; }
113
120 void SetRotationMatrix( const glm::mat4& aRotation );
121
129 void SetViewMatrix( glm::mat4 aViewMatrix );
130
131 void SetBoardLookAtPos( const SFVEC3F& aBoardPos );
132
133 void SetLookAtPos_T1( const SFVEC3F& aLookAtPos )
134 {
135 m_lookat_pos_t1 = aLookAtPos;
136 }
137
138 const SFVEC3F& GetLookAtPos_T1() const { return m_lookat_pos_t1; }
139
140 const SFVEC3F& GetCameraPos() const { return m_camera_pos; }
141 const SFVEC3F& GetCameraInitPos() const { return m_camera_pos_init; }
142
143 float GetCameraMinDimension() const;
144
148 virtual void Drag( const wxPoint& aNewMousePosition ) = 0;
149
150 virtual void Pan( const wxPoint& aNewMousePosition ) = 0;
151
152 virtual void Pan( const SFVEC3F& aDeltaOffsetInc ) = 0;
153
154 virtual void Pan_T1( const SFVEC3F& aDeltaOffsetInc ) = 0;
155
159 virtual void Reset();
160 virtual void Reset_T1();
161
162 void ResetXYpos();
163 void ResetXYpos_T1();
164
168 const wxPoint& GetCurMousePosition() { return m_lastPosition; }
169
173 void SetCurMousePosition( const wxPoint& aPosition );
174
175 void ToggleProjection();
177 void SetProjection( PROJECTION_TYPE aProjection ) { m_projectionType = aProjection; }
178
184 bool SetCurWindowSize( const wxSize& aSize );
185
186 void ZoomReset();
187
188 bool Zoom( float aFactor );
189
190 bool Zoom_T1( float aFactor );
191
192 float GetZoom() const { return m_zoom; }
193
194 float GetMinZoom() { return m_minZoom; }
195 void SetMinZoom( float minZoom )
196 {
197 m_minZoom = minZoom;
198 zoomChanged();
199 }
200
201 float GetMaxZoom() { return m_maxZoom; }
202 void SetMaxZoom( float maxZoom )
203 {
204 m_maxZoom = maxZoom;
205 zoomChanged();
206 }
207
208 void RotateX( float aAngleInRadians );
209 void RotateY( float aAngleInRadians );
210 void RotateZ( float aAngleInRadians );
211
212 void RotateX_T1( float aAngleInRadians );
213 void RotateY_T1( float aAngleInRadians );
214 void RotateZ_T1( float aAngleInRadians );
215
219 virtual void SetT0_and_T1_current_T();
220
226 virtual void Interpolate( float t );
227
229 {
230 m_interpolation_mode = aInterpolateMode;
231 }
232
236 bool ParametersChanged();
237
242
250 void MakeRay( const SFVEC2I& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
251
260 void MakeRay( const SFVEC2F& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
261
268 void MakeRayAtCurrentMousePosition( SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
269
273 void Update() { updateFrustum(); }
274
275protected:
276 void zoomChanged();
277 void rebuildProjection();
278 void updateFrustum();
279 void updateViewMatrix();
280
282
286 float m_zoom;
289
295
300
305
308 glm::mat4 m_viewMatrix;
313
315
320
322
327
332
336
338
342 std::vector< float > m_scr_nX;
343 std::vector< float > m_scr_nY;
344
349 std::vector< SFVEC3F > m_right_nX;
350 std::vector< SFVEC3F > m_up_nY;
351
356
364 static const wxChar* m_logTrace;
365};
366
367#endif // CAMERA_H
CAMERA_INTERPOLATION
Definition: camera.h:65
PROJECTION_TYPE
Definition: camera.h:38
A class used to derive camera objects from.
Definition: camera.h:78
glm::mat4 GetRotationMatrix() const
Get the rotation matrix to be applied in a transformation camera.
Definition: camera.cpp:183
const SFVEC3F & GetRight() const
Definition: camera.h:104
float m_zoom_t0
Definition: camera.h:287
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:355
void RotateY(float aAngleInRadians)
Definition: camera.cpp:599
glm::mat4 m_projectionMatrixInv
Definition: camera.h:311
void RotateX(float aAngleInRadians)
Definition: camera.cpp:592
const CAMERA_FRUSTUM & GetFrustum() const
Definition: camera.h:111
SFVEC3F m_lookat_pos
Definition: camera.h:328
const glm::mat4 & GetProjectionMatrix() const
Definition: camera.cpp:415
bool ParametersChangedQuery() const
Definition: camera.h:241
void SetMinZoom(float minZoom)
Definition: camera.h:195
void SetBoardLookAtPos(const SFVEC3F &aBoardPos)
Definition: camera.cpp:124
void SetProjection(PROJECTION_TYPE aProjection)
Definition: camera.h:177
bool Zoom(float aFactor)
Definition: camera.cpp:539
SFVEC3F m_camera_pos_t0
Definition: camera.h:325
const SFVEC3F & GetPos() const
Definition: camera.h:107
float GetMaxZoom()
Definition: camera.h:201
void RotateY_T1(float aAngleInRadians)
Definition: camera.cpp:619
virtual void Pan(const wxPoint &aNewMousePosition)=0
virtual void Reset()
Reset the camera to initial state.
Definition: camera.cpp:71
SFVEC3F m_right
Definition: camera.h:316
float GetNear() const
Definition: camera.h:109
glm::mat4 m_projectionMatrix
Definition: camera.h:310
CAMERA_INTERPOLATION m_interpolation_mode
Definition: camera.h:337
SFVEC3F m_rotate_aux_t1
Definition: camera.h:335
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: camera.h:304
void ZoomReset()
Definition: camera.cpp:528
void ResetXYpos()
Definition: camera.cpp:433
const glm::mat4 & GetViewMatrix_Inv() const
Definition: camera.cpp:489
PROJECTION_TYPE GetProjection()
Definition: camera.h:176
bool Zoom_T1(float aFactor)
Definition: camera.cpp:570
void updateRotationMatrix()
Definition: camera.cpp:162
SFVEC3F m_rotate_aux_t0
Definition: camera.h:334
virtual void Reset_T1()
Definition: camera.cpp:103
void MakeRay(const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
Make a ray based on a windows screen position.
Definition: camera.cpp:349
virtual void Pan_T1(const SFVEC3F &aDeltaOffsetInc)=0
virtual void Interpolate(float t)
It will update the matrix to interpolate between T0 and T1 values.
Definition: camera.cpp:645
const SFVEC3F & GetUp() const
Definition: camera.h:105
SFVEC3F m_dir
Definition: camera.h:318
virtual ~CAMERA()
Definition: camera.h:87
virtual void Drag(const wxPoint &aNewMousePosition)=0
Calculate a new mouse drag position.
bool SetCurWindowSize(const wxSize &aSize)
Update the windows size of the camera.
Definition: camera.cpp:512
void SetInterpolateMode(CAMERA_INTERPOLATION aInterpolateMode)
Definition: camera.h:228
float GetZoom() const
Definition: camera.h:192
SFVEC3F m_camera_pos_init
Definition: camera.h:323
CAMERA(float aInitialDistance)
Initialize a camera.
Definition: camera.cpp:54
const glm::mat4 & GetProjectionMatrixInv() const
Definition: camera.cpp:421
void ResetXYpos_T1()
Definition: camera.cpp:444
float m_minZoom
Possible 3D zoom range.
Definition: camera.h:293
float GetCameraMinDimension() const
Definition: camera.cpp:427
float GetFar() const
Definition: camera.h:110
virtual void Pan(const SFVEC3F &aDeltaOffsetInc)=0
float m_maxZoom
Definition: camera.h:294
const SFVEC3F & GetLookAtPos() const
Definition: camera.h:112
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:349
void rebuildProjection()
Definition: camera.cpp:197
float m_zoom_t1
Definition: camera.h:288
float GetMinZoom()
Definition: camera.h:194
SFVEC3F m_lookat_pos_t1
Definition: camera.h:330
CAMERA_FRUSTUM m_frustum
Definition: camera.h:314
void updateFrustum()
Definition: camera.cpp:290
SFVEC3F m_lookat_pos_t0
Definition: camera.h:329
void RotateZ(float aAngleInRadians)
Definition: camera.cpp:606
const SFVEC2F & GetFocalLen() const
Definition: camera.h:108
virtual void SetT0_and_T1_current_T()
This will set T0 and T1 with the current values.
Definition: camera.cpp:631
SFVEC3F m_camera_pos
Definition: camera.h:324
PROJECTION_TYPE m_projectionType
Definition: camera.h:312
SFVEC3F m_pos
Definition: camera.h:319
void ToggleProjection()
Definition: camera.cpp:501
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:299
void MakeRayAtCurrentMousePosition(SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
Make a ray based on the latest mouse position.
Definition: camera.cpp:403
SFVEC2F m_focalLen
Definition: camera.h:321
void updateViewMatrix()
Definition: camera.cpp:154
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:342
void RotateX_T1(float aAngleInRadians)
Definition: camera.cpp:613
const glm::mat4 & GetViewMatrix() const
Definition: camera.cpp:451
void SetLookAtPos_T1(const SFVEC3F &aLookAtPos)
Definition: camera.h:133
glm::mat4 m_viewMatrixInverse
Definition: camera.h:309
const SFVEC3F & GetLookAtPos_T1() const
Definition: camera.h:138
const wxPoint & GetCurMousePosition()
Get the current mouse position.
Definition: camera.h:168
const SFVEC3F & GetCameraPos() const
Definition: camera.h:140
SFVEC3F m_up
Definition: camera.h:317
const SFVEC3F & GetDir() const
Definition: camera.h:106
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:333
glm::mat4 m_rotationMatrixAux
Definition: camera.h:307
glm::mat4 m_rotationMatrix
Definition: camera.h:306
std::vector< float > m_scr_nY
Definition: camera.h:343
void SetViewMatrix(glm::mat4 aViewMatrix)
Set the affine matrix to be applied to a transformation camera.
Definition: camera.cpp:457
void RotateZ_T1(float aAngleInRadians)
Definition: camera.cpp:625
glm::mat4 m_viewMatrix
Definition: camera.h:308
void SetMaxZoom(float maxZoom)
Definition: camera.h:202
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center).
Definition: camera.h:331
const SFVEC3F & GetCameraInitPos() const
Definition: camera.h:141
std::vector< SFVEC3F > m_up_nY
Definition: camera.h:350
bool ParametersChanged()
Definition: camera.cpp:663
void SetRotationMatrix(const glm::mat4 &aRotation)
Set the rotation matrix to be applied in a transformation camera, without making any new calculations...
Definition: camera.cpp:189
SFVEC3F m_camera_pos_t1
Definition: camera.h:326
float m_zoom
3D zoom value – Z-distance is scaled by it
Definition: camera.h:286
void Update()
Update the camera.
Definition: camera.h:273
void zoomChanged()
Definition: camera.cpp:139
void SetCurMousePosition(const wxPoint &aPosition)
Update the current mouse position without make any new calculations on camera.
Definition: camera.cpp:495
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Definition: camera.h:364
Frustum is a implementation based on a tutorial by http://www.lighthouse3d.com/tutorials/view-frustum...
Definition: camera.h:48
SFVEC3F ntr
Near Top Right.
Definition: camera.h:52
SFVEC3F ntl
Near Top Left.
Definition: camera.h:51
SFVEC3F fc
Definition: camera.h:50
float angle
Definition: camera.h:59
float ratio
Definition: camera.h:59
float fh
Definition: camera.h:60
float nh
Definition: camera.h:60
SFVEC3F ftl
Far Top Left.
Definition: camera.h:55
SFVEC3F fbr
Far Bottom Right.
Definition: camera.h:58
float fw
Definition: camera.h:60
float farD
Definition: camera.h:59
SFVEC3F nbl
Near Bottom Left.
Definition: camera.h:53
SFVEC3F nc
Definition: camera.h:49
SFVEC3F nbr
Near Bottom Right.
Definition: camera.h:54
float nw
Definition: camera.h:60
SFVEC3F fbl
Far Bottom Left.
Definition: camera.h:57
float tang
Definition: camera.h:59
float nearD
Definition: camera.h:59
SFVEC3F ftr
Far Top Right.
Definition: camera.h:56
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44