KiCad PCB EDA Suite
CAMERA Class Referenceabstract

A class used to derive camera objects from. More...

#include <camera.h>

Inheritance diagram for CAMERA:
TRACK_BALL

Public Member Functions

 CAMERA (float aRangeScale)
 Initialize a camera. More...
 
virtual ~CAMERA ()
 
const glm::mat4 GetRotationMatrix () const
 Get the rotation matrix to be applied in a transformation camera. More...
 
const glm::mat4 & GetViewMatrix () const
 
const glm::mat4 & GetViewMatrix_Inv () const
 
const glm::mat4 & GetProjectionMatrix () const
 
const glm::mat4 & GetProjectionMatrixInv () const
 
const SFVEC3FGetRight () const
 
const SFVEC3FGetUp () const
 
const SFVEC3FGetDir () const
 
const SFVEC3FGetPos () const
 
const SFVEC2FGetFocalLen () const
 
float GetNear () const
 
float GetFar () const
 
void SetBoardLookAtPos (const SFVEC3F &aBoardPos)
 
virtual void SetLookAtPos (const SFVEC3F &aLookAtPos)=0
 
void SetLookAtPos_T1 (const SFVEC3F &aLookAtPos)
 
const SFVEC3FGetLookAtPos_T1 () const
 
const SFVEC3FGetCameraPos () const
 
virtual void Drag (const wxPoint &aNewMousePosition)=0
 Calculate a new mouse drag position. More...
 
virtual void Pan (const wxPoint &aNewMousePosition)=0
 
virtual void Pan (const SFVEC3F &aDeltaOffsetInc)=0
 
virtual void Pan_T1 (const SFVEC3F &aDeltaOffsetInc)=0
 
virtual void Reset ()
 Reset the camera to initial state. More...
 
virtual void Reset_T1 ()
 
void ResetXYpos ()
 
void ResetXYpos_T1 ()
 
void SetCurMousePosition (const wxPoint &aPosition)
 Update the current mouse position without make any new calculations on camera. More...
 
void ToggleProjection ()
 
PROJECTION_TYPE GetProjection ()
 
bool SetCurWindowSize (const wxSize &aSize)
 Update the windows size of the camera. More...
 
void ZoomReset ()
 
bool Zoom (float aFactor)
 
bool Zoom_T1 (float aFactor)
 
float ZoomGet () const
 
void RotateX (float aAngleInRadians)
 
void RotateY (float aAngleInRadians)
 
void RotateZ (float aAngleInRadians)
 
void RotateX_T1 (float aAngleInRadians)
 
void RotateY_T1 (float aAngleInRadians)
 
void RotateZ_T1 (float aAngleInRadians)
 
virtual void SetT0_and_T1_current_T ()
 This will set T0 and T1 with the current values. More...
 
virtual void Interpolate (float t)
 It will update the matrix to interpolate between T0 and T1 values. More...
 
void SetInterpolateMode (CAMERA_INTERPOLATION aInterpolateMode)
 
bool ParametersChanged ()
 
bool ParametersChangedQuery () const
 
void MakeRay (const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
 Make a ray based on a windows screen position. More...
 
void MakeRay (const SFVEC2F &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
 Make a ray based on a windows screen position, it will interpolate based on the aWindowPos. More...
 
void MakeRayAtCurrrentMousePosition (SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
 Make a ray based on the latest mouse position. More...
 

Protected Member Functions

void rebuildProjection ()
 
void updateFrustum ()
 
void updateViewMatrix ()
 
void updateRotationMatrix ()
 

Protected Attributes

float m_range_scale
 The nominal range expected to be used in the camera. More...
 
float m_zoom
 3D zoom value (Min 0.0 ... More...
 
float m_zoom_t0
 
float m_zoom_t1
 
SFVEC2I m_windowSize
 The window size that this camera is working. More...
 
wxPoint m_lastPosition
 The last mouse position in the screen. More...
 
glm::mat4 m_rotationMatrix
 
glm::mat4 m_rotationMatrixAux
 
glm::mat4 m_viewMatrix
 
glm::mat4 m_viewMatrixInverse
 
glm::mat4 m_projectionMatrix
 
glm::mat4 m_projectionMatrixInv
 
PROJECTION_TYPE m_projectionType
 
CAMERA_FRUSTUM m_frustum
 
SFVEC3F m_right
 
SFVEC3F m_up
 
SFVEC3F m_dir
 
SFVEC3F m_pos
 
SFVEC2F m_focalLen
 
SFVEC3F m_camera_pos_init
 
SFVEC3F m_camera_pos
 
SFVEC3F m_camera_pos_t0
 
SFVEC3F m_camera_pos_t1
 
SFVEC3F m_lookat_pos
 
SFVEC3F m_lookat_pos_t0
 
SFVEC3F m_lookat_pos_t1
 
SFVEC3F m_board_lookat_pos_init
 Default boardlookat position (the board center). More...
 
SFVEC3F m_rotate_aux
 Stores the rotation angle auxiliary. More...
 
SFVEC3F m_rotate_aux_t0
 
SFVEC3F m_rotate_aux_t1
 
CAMERA_INTERPOLATION m_interpolation_mode
 
std::vector< float > m_scr_nX
 Precalc values array used to calc ray for each pixel (constant for the same window size). More...
 
std::vector< float > m_scr_nY
 
std::vector< SFVEC3Fm_right_nX
 Precalc values array used to calc ray for each pixel, for X and Y axis of each new camera position. More...
 
std::vector< SFVEC3Fm_up_nY
 
bool m_parametersChanged
 Set to true if any of the parameters in the camera was changed. More...
 

Static Protected Attributes

static const wxChar * m_logTrace = wxT( "KI_TRACE_CAMERA" )
 Trace mask used to enable or disable the trace output of this class. More...
 

Detailed Description

A class used to derive camera objects from.

It must be derived by other classes to implement a real camera object.

Definition at line 77 of file camera.h.

Constructor & Destructor Documentation

◆ CAMERA()

CAMERA::CAMERA ( float  aRangeScale)
explicit

Initialize a camera.

Parameters
aRangeScaleit will be expected that the board will have a -aRangeScale/2 to +aRangeScale/2. It will initialize the Z position with aRangeScale.

Definition at line 54 of file camera.cpp.

55 {
56  wxLogTrace( m_logTrace, wxT( "CAMERA::CAMERA" ) );
57 
58  m_range_scale = aRangeScale;
59  m_camera_pos_init = SFVEC3F( 0.0f, 0.0f, -(aRangeScale * 2.0f ) );
61  m_windowSize = SFVEC2I( 0, 0 );
64 
65  Reset();
66 }
virtual void Reset()
Reset the camera to initial state.
Definition: camera.cpp:69
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
SFVEC3F m_camera_pos_init
Definition: camera.h:287
PROJECTION_TYPE m_projectionType
Definition: camera.h:276
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:263
CAMERA_INTERPOLATION m_interpolation_mode
Definition: camera.h:301
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center).
Definition: camera.h:295
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Definition: camera.h:328
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
float m_range_scale
The nominal range expected to be used in the camera.
Definition: camera.h:251

References BEZIER, m_board_lookat_pos_init, m_camera_pos_init, m_interpolation_mode, m_logTrace, m_projectionType, m_range_scale, m_windowSize, PERSPECTIVE, and Reset().

◆ ~CAMERA()

virtual CAMERA::~CAMERA ( )
inlinevirtual

Definition at line 89 of file camera.h.

90  {
91  }

Member Function Documentation

◆ Drag()

virtual void CAMERA::Drag ( const wxPoint &  aNewMousePosition)
pure virtual

Calculate a new mouse drag position.

Implemented in TRACK_BALL.

Referenced by EDA_3D_CANVAS::OnMouseMove().

◆ GetCameraPos()

const SFVEC3F& CAMERA::GetCameraPos ( ) const
inline

Definition at line 132 of file camera.h.

132 { return m_camera_pos; }
SFVEC3F m_camera_pos
Definition: camera.h:288

References m_camera_pos.

Referenced by EDA_3D_CANVAS::DisplayStatus().

◆ GetDir()

const SFVEC3F& CAMERA::GetDir ( ) const
inline

Definition at line 108 of file camera.h.

108 { return m_dir; }
SFVEC3F m_dir
Definition: camera.h:282

References m_dir.

Referenced by RENDER_3D_RAYTRACE::Redraw(), and RENDER_3D_RAYTRACE::render().

◆ GetFar()

float CAMERA::GetFar ( ) const
inline

Definition at line 112 of file camera.h.

112 { return m_frustum.farD; }
float farD
Definition: camera.h:59
CAMERA_FRUSTUM m_frustum
Definition: camera.h:278

References CAMERA_FRUSTUM::farD, and m_frustum.

◆ GetFocalLen()

const SFVEC2F& CAMERA::GetFocalLen ( ) const
inline

Definition at line 110 of file camera.h.

110 { return m_focalLen; }
SFVEC2F m_focalLen
Definition: camera.h:285

References m_focalLen.

◆ GetLookAtPos_T1()

const SFVEC3F& CAMERA::GetLookAtPos_T1 ( ) const
inline

Definition at line 130 of file camera.h.

130 { return m_lookat_pos_t1; }
SFVEC3F m_lookat_pos_t1
Definition: camera.h:294

References m_lookat_pos_t1.

Referenced by EDA_3D_CANVAS::render_pivot().

◆ GetNear()

float CAMERA::GetNear ( ) const
inline

Definition at line 111 of file camera.h.

111 { return m_frustum.nearD; }
float nearD
Definition: camera.h:59
CAMERA_FRUSTUM m_frustum
Definition: camera.h:278

References m_frustum, and CAMERA_FRUSTUM::nearD.

◆ GetPos()

const SFVEC3F& CAMERA::GetPos ( ) const
inline

Definition at line 109 of file camera.h.

109 { return m_pos; }
SFVEC3F m_pos
Definition: camera.h:283

References m_pos.

Referenced by RENDER_3D_LEGACY::Redraw(), and RENDER_3D_LEGACY::renderSolderMaskLayer().

◆ GetProjection()

PROJECTION_TYPE CAMERA::GetProjection ( )
inline

Definition at line 160 of file camera.h.

160 { return m_projectionType; }
PROJECTION_TYPE m_projectionType
Definition: camera.h:276

References m_projectionType.

Referenced by EDA_3D_VIEWER::setupUIConditions().

◆ GetProjectionMatrix()

const glm::mat4 & CAMERA::GetProjectionMatrix ( ) const

Definition at line 376 of file camera.cpp.

377 {
378  return m_projectionMatrix;
379 }
glm::mat4 m_projectionMatrix
Definition: camera.h:274

References m_projectionMatrix.

Referenced by C3D_MODEL_VIEWER::OnPaint(), RENDER_3D_LEGACY::Redraw(), and EDA_3D_CANVAS::render_pivot().

◆ GetProjectionMatrixInv()

const glm::mat4 & CAMERA::GetProjectionMatrixInv ( ) const

Definition at line 382 of file camera.cpp.

383 {
384  return m_projectionMatrixInv;
385 }
glm::mat4 m_projectionMatrixInv
Definition: camera.h:275

References m_projectionMatrixInv.

◆ GetRight()

const SFVEC3F& CAMERA::GetRight ( ) const
inline

Definition at line 106 of file camera.h.

106 { return m_right; }
SFVEC3F m_right
Definition: camera.h:280

References m_right.

◆ GetRotationMatrix()

const glm::mat4 CAMERA::GetRotationMatrix ( ) const

Get the rotation matrix to be applied in a transformation camera.

Returns
the rotation matrix of the camera

Definition at line 151 of file camera.cpp.

152 {
154 }
glm::mat4 m_rotationMatrix
Definition: camera.h:270
glm::mat4 m_rotationMatrixAux
Definition: camera.h:271

References m_rotationMatrix, and m_rotationMatrixAux.

Referenced by C3D_MODEL_VIEWER::OnPaint(), and RENDER_3D_LEGACY::render3dArrows().

◆ GetUp()

const SFVEC3F& CAMERA::GetUp ( ) const
inline

Definition at line 107 of file camera.h.

107 { return m_up; }
SFVEC3F m_up
Definition: camera.h:281

References m_up.

◆ GetViewMatrix()

const glm::mat4 & CAMERA::GetViewMatrix ( ) const

Definition at line 406 of file camera.cpp.

407 {
408  return m_viewMatrix;
409 }
glm::mat4 m_viewMatrix
Definition: camera.h:272

References m_viewMatrix.

Referenced by C3D_MODEL_VIEWER::OnPaint(), RENDER_3D_LEGACY::Redraw(), and EDA_3D_CANVAS::render_pivot().

◆ GetViewMatrix_Inv()

const glm::mat4 & CAMERA::GetViewMatrix_Inv ( ) const

Definition at line 412 of file camera.cpp.

413 {
414  return m_viewMatrixInverse;
415 }
glm::mat4 m_viewMatrixInverse
Definition: camera.h:273

References m_viewMatrixInverse.

◆ Interpolate()

void CAMERA::Interpolate ( float  t)
virtual

It will update the matrix to interpolate between T0 and T1 values.

Parameters
tthe interpolation time, between 0.0f and 1.0f (it will clamp if >1).

Reimplemented in TRACK_BALL.

Definition at line 563 of file camera.cpp.

564 {
565  wxASSERT( t >= 0.0f );
566 
567  const float t0 = 1.0f - t;
568 
572  m_zoom = m_zoom_t0 * t0 + m_zoom_t1 * t;
573 
574  m_parametersChanged = true;
575 
578 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:297
float m_zoom
3D zoom value (Min 0.0 ...
Definition: camera.h:256
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:319
SFVEC3F m_lookat_pos_t0
Definition: camera.h:293
SFVEC3F m_lookat_pos_t1
Definition: camera.h:294
float m_zoom_t1
Definition: camera.h:258
SFVEC3F m_rotate_aux_t1
Definition: camera.h:299
void rebuildProjection()
Definition: camera.cpp:157
SFVEC3F m_camera_pos_t0
Definition: camera.h:289
void updateRotationMatrix()
Definition: camera.cpp:130
float m_zoom_t0
Definition: camera.h:257
SFVEC3F m_camera_pos_t1
Definition: camera.h:290
SFVEC3F m_lookat_pos
Definition: camera.h:292
SFVEC3F m_camera_pos
Definition: camera.h:288
SFVEC3F m_rotate_aux_t0
Definition: camera.h:298

References m_camera_pos, m_camera_pos_t0, m_camera_pos_t1, m_lookat_pos, m_lookat_pos_t0, m_lookat_pos_t1, m_parametersChanged, m_rotate_aux, m_rotate_aux_t0, m_rotate_aux_t1, m_zoom, m_zoom_t0, m_zoom_t1, rebuildProjection(), and updateRotationMatrix().

Referenced by EDA_3D_CANVAS::DoRePaint(), TRACK_BALL::Interpolate(), and EDA_3D_CANVAS::request_start_moving_camera().

◆ MakeRay() [1/2]

void CAMERA::MakeRay ( const SFVEC2I aWindowPos,
SFVEC3F aOutOrigin,
SFVEC3F aOutDirection 
) const

Make a ray based on a windows screen position.

Parameters
aWindowPosthe windows buffer position.
aOutOriginout origin position of the ray.
aOutDirectionout direction

Definition at line 308 of file camera.cpp.

310 {
311  wxASSERT( aWindowPos.x < m_windowSize.x );
312  wxASSERT( aWindowPos.y < m_windowSize.y );
313 
314  const SFVEC3F up_plus_right = m_up_nY[aWindowPos.y] + m_right_nX[aWindowPos.x];
315 
316  switch( m_projectionType )
317  {
318  default:
320  aOutOrigin = up_plus_right + m_frustum.nc;
321  aOutDirection = glm::normalize( aOutOrigin - m_pos );
322  break;
323 
325  aOutOrigin = up_plus_right * 0.5f + m_frustum.nc;
326  aOutDirection = -m_dir + SFVEC3F( FLT_EPSILON );
327  break;
328  }
329 }
SFVEC3F m_dir
Definition: camera.h:282
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:313
SFVEC3F m_pos
Definition: camera.h:283
PROJECTION_TYPE m_projectionType
Definition: camera.h:276
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:263
std::vector< SFVEC3F > m_up_nY
Definition: camera.h:314
CAMERA_FRUSTUM m_frustum
Definition: camera.h:278
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F nc
Definition: camera.h:49

References m_dir, m_frustum, m_pos, m_projectionType, m_right_nX, m_up_nY, m_windowSize, CAMERA_FRUSTUM::nc, ORTHO, and PERSPECTIVE.

Referenced by MakeRayAtCurrrentMousePosition(), RAYPACKET::RAYPACKET(), RAYPACKET_InitRays(), and RAYPACKET_InitRays_with2DDisplacement().

◆ MakeRay() [2/2]

void CAMERA::MakeRay ( const SFVEC2F aWindowPos,
SFVEC3F aOutOrigin,
SFVEC3F aOutDirection 
) const

Make a ray based on a windows screen position, it will interpolate based on the aWindowPos.

Parameters
aWindowPosthe windows buffer position (float value).
aOutOriginout origin position of the ray.
aOutDirectionout direction.

Definition at line 332 of file camera.cpp.

334 {
335  wxASSERT( aWindowPos.x < (float)m_windowSize.x );
336  wxASSERT( aWindowPos.y < (float)m_windowSize.y );
337 
338  const SFVEC2F floorWinPos_f = glm::floor( aWindowPos );
339  const SFVEC2I floorWinPos_i = (SFVEC2I)floorWinPos_f;
340  const SFVEC2F relativeWinPos = aWindowPos - floorWinPos_f;
341 
342  // Note: size of vectors m_up and m_right are m_windowSize + 1
343  const SFVEC3F up_plus_right = m_up_nY[floorWinPos_i.y] * (1.0f - relativeWinPos.y) +
344  m_up_nY[floorWinPos_i.y + 1] * relativeWinPos.y +
345  m_right_nX[floorWinPos_i.x] * (1.0f - relativeWinPos.x) +
346  m_right_nX[floorWinPos_i.x + 1] * relativeWinPos.x;
347 
348  switch( m_projectionType )
349  {
350  default:
352  aOutOrigin = up_plus_right + m_frustum.nc;
353  aOutDirection = glm::normalize( aOutOrigin - m_pos );
354  break;
355 
357  aOutOrigin = up_plus_right * 0.5f + m_frustum.nc;
358  aOutDirection = -m_dir + SFVEC3F( FLT_EPSILON );
359  break;
360  }
361 }
SFVEC3F m_dir
Definition: camera.h:282
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
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:313
SFVEC3F m_pos
Definition: camera.h:283
PROJECTION_TYPE m_projectionType
Definition: camera.h:276
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:263
std::vector< SFVEC3F > m_up_nY
Definition: camera.h:314
CAMERA_FRUSTUM m_frustum
Definition: camera.h:278
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F nc
Definition: camera.h:49

References m_dir, m_frustum, m_pos, m_projectionType, m_right_nX, m_up_nY, m_windowSize, CAMERA_FRUSTUM::nc, ORTHO, and PERSPECTIVE.

◆ MakeRayAtCurrrentMousePosition()

void CAMERA::MakeRayAtCurrrentMousePosition ( SFVEC3F aOutOrigin,
SFVEC3F aOutDirection 
) const

Make a ray based on the latest mouse position.

Parameters
aOutOriginout origin position of the ray.
aOutDirectionout direction.

Definition at line 364 of file camera.cpp.

365 {
366  const SFVEC2I windowPos = SFVEC2I( m_lastPosition.x, m_windowSize.y - m_lastPosition.y );
367 
368  if( ( 0 < windowPos.x ) && ( windowPos.x < m_windowSize.x ) &&
369  ( 0 < windowPos.y ) && ( windowPos.y < m_windowSize.y ) )
370  {
371  MakeRay( windowPos, aOutOrigin, aOutDirection );
372  }
373 }
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: camera.h:268
void MakeRay(const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
Make a ray based on a windows screen position.
Definition: camera.cpp:308
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:263

References m_lastPosition, m_windowSize, and MakeRay().

Referenced by EDA_3D_CANVAS::getRayAtCurrrentMousePosition().

◆ Pan() [1/2]

virtual void CAMERA::Pan ( const wxPoint &  aNewMousePosition)
pure virtual

◆ Pan() [2/2]

virtual void CAMERA::Pan ( const SFVEC3F aDeltaOffsetInc)
pure virtual

Implemented in TRACK_BALL.

◆ Pan_T1()

virtual void CAMERA::Pan_T1 ( const SFVEC3F aDeltaOffsetInc)
pure virtual

Implemented in TRACK_BALL.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ ParametersChanged()

bool CAMERA::ParametersChanged ( )
Returns
true if some of the parameters in camera was changed, it will reset the flag.

Definition at line 581 of file camera.cpp.

582 {
583  const bool parametersChanged = m_parametersChanged;
584 
585  m_parametersChanged = false;
586 
587  return parametersChanged;
588 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:319

References m_parametersChanged.

Referenced by EDA_3D_CANVAS::DoRePaint(), and RENDER_3D_RAYTRACE::Redraw().

◆ ParametersChangedQuery()

bool CAMERA::ParametersChangedQuery ( ) const
inline
Returns
true if some of the parameters in camera was changed, it will NOT reset the flag.

Definition at line 210 of file camera.h.

210 { return m_parametersChanged; }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:319

References m_parametersChanged.

◆ rebuildProjection()

void CAMERA::rebuildProjection ( )
protected

Definition at line 157 of file camera.cpp.

158 {
159  if( ( m_windowSize.x == 0 ) || ( m_windowSize.y == 0 ) )
160  return;
161 
162  m_frustum.ratio = (float) m_windowSize.x / (float)m_windowSize.y;
163 
164  // Consider that we can render double the length multiplied by the 2/sqrt(2)
165  m_frustum.farD = glm::length( m_camera_pos_init ) * 2.0f * ( 2.0f * sqrtf( 2.0f ) );
166 
167  switch( m_projectionType )
168  {
169  default:
171 
172  m_frustum.nearD = 0.10f;
173 
174  // Ratio width / height of the window display
175  m_frustum.angle = 45.0f * m_zoom;
176 
177  m_projectionMatrix = glm::perspective( glm::radians( m_frustum.angle ), m_frustum.ratio,
179 
180  m_projectionMatrixInv = glm::inverse( m_projectionMatrix );
181 
182  m_frustum.tang = glm::tan( glm::radians( m_frustum.angle ) * 0.5f );
183 
184  m_focalLen.x = ( (float)m_windowSize.y / (float)m_windowSize.x ) / m_frustum.tang;
185  m_focalLen.y = 1.0f / m_frustum.tang;
186 
191  break;
192 
194 
195  m_frustum.nearD = -m_frustum.farD; // Use a symmetrical clip plane for ortho projection
196 
197  // This formula was found by trial and error
198  const float orthoReductionFactor = glm::length( m_camera_pos_init ) *
199  m_zoom * m_zoom * 0.5f;
200 
201  // Initialize Projection Matrix for Orthographic View
202  m_projectionMatrix = glm::ortho( -m_frustum.ratio * orthoReductionFactor,
203  m_frustum.ratio * orthoReductionFactor,
204  -orthoReductionFactor,
205  orthoReductionFactor,
207 
208  m_projectionMatrixInv = glm::inverse( m_projectionMatrix );
209 
210  m_frustum.nw = orthoReductionFactor * 2.0f * m_frustum.ratio;
211  m_frustum.nh = orthoReductionFactor * 2.0f;
214 
215  break;
216  }
217 
218  if( ( m_windowSize.x > 0 ) && ( m_windowSize.y > 0 ) )
219  {
220  m_scr_nX.resize( m_windowSize.x + 1 );
221  m_scr_nY.resize( m_windowSize.y + 1 );
222 
223  // Precalc X values for camera -> ray generation
224  for( unsigned int x = 0; x < (unsigned int)m_windowSize.x + 1; ++x )
225  {
226  // Converts 0.0 .. 1.0
227  const float xNormalizedDeviceCoordinates = ( ( (float)x + 0.5f ) /
228  (m_windowSize.x - 0.0f) );
229 
230  // Converts -1.0 .. 1.0
231  m_scr_nX[x] = 2.0f * xNormalizedDeviceCoordinates - 1.0f;
232  }
233 
234  // Precalc Y values for camera -> ray generation
235  for( unsigned int y = 0; y < (unsigned int)m_windowSize.y + 1 ; ++y )
236  {
237  // Converts 0.0 .. 1.0
238  const float yNormalizedDeviceCoordinates = ( ( (float)y + 0.5f ) /
239  (m_windowSize.y - 0.0f) );
240 
241  // Converts -1.0 .. 1.0
242  m_scr_nY[y] = 2.0f * yNormalizedDeviceCoordinates - 1.0f;
243  }
244 
245  updateFrustum();
246  }
247 }
float m_zoom
3D zoom value (Min 0.0 ...
Definition: camera.h:256
float ratio
Definition: camera.h:59
SFVEC2F m_focalLen
Definition: camera.h:285
float nw
Definition: camera.h:60
float fw
Definition: camera.h:60
float tang
Definition: camera.h:59
float fh
Definition: camera.h:60
SFVEC3F m_camera_pos_init
Definition: camera.h:287
PROJECTION_TYPE m_projectionType
Definition: camera.h:276
float farD
Definition: camera.h:59
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:263
glm::mat4 m_projectionMatrix
Definition: camera.h:274
float nearD
Definition: camera.h:59
void updateFrustum()
Definition: camera.cpp:250
CAMERA_FRUSTUM m_frustum
Definition: camera.h:278
std::vector< float > m_scr_nY
Definition: camera.h:307
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:306
glm::mat4 m_projectionMatrixInv
Definition: camera.h:275
float nh
Definition: camera.h:60
float angle
Definition: camera.h:59

References CAMERA_FRUSTUM::angle, CAMERA_FRUSTUM::farD, CAMERA_FRUSTUM::fh, CAMERA_FRUSTUM::fw, m_camera_pos_init, m_focalLen, m_frustum, m_projectionMatrix, m_projectionMatrixInv, m_projectionType, m_scr_nX, m_scr_nY, m_windowSize, m_zoom, CAMERA_FRUSTUM::nearD, CAMERA_FRUSTUM::nh, CAMERA_FRUSTUM::nw, ORTHO, PERSPECTIVE, CAMERA_FRUSTUM::ratio, CAMERA_FRUSTUM::tang, and updateFrustum().

Referenced by Interpolate(), Reset(), SetCurWindowSize(), ToggleProjection(), Zoom(), and ZoomReset().

◆ Reset()

void CAMERA::Reset ( )
virtual

Reset the camera to initial state.

Reimplemented in TRACK_BALL.

Definition at line 69 of file camera.cpp.

70 {
71  m_parametersChanged = true;
72  m_projectionMatrix = glm::mat4( 1.0f );
73  m_projectionMatrixInv = glm::mat4( 1.0f );
74  m_rotationMatrix = glm::mat4( 1.0f );
75  m_rotationMatrixAux = glm::mat4( 1.0f );
76  m_lastPosition = wxPoint( 0, 0 );
77 
78  m_zoom = 1.0f;
79  m_zoom_t0 = 1.0f;
80  m_zoom_t1 = 1.0f;
87 
88  m_rotate_aux = SFVEC3F( 0.0f );
89  m_rotate_aux_t0 = SFVEC3F( 0.0f );
90  m_rotate_aux_t1 = SFVEC3F( 0.0f );
91 
94  m_viewMatrixInverse = glm::inverse( m_viewMatrix );
95  m_scr_nX.clear();
96  m_scr_nY.clear();
98 }
glm::mat4 m_viewMatrixInverse
Definition: camera.h:273
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:297
float m_zoom
3D zoom value (Min 0.0 ...
Definition: camera.h:256
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:319
SFVEC3F m_lookat_pos_t0
Definition: camera.h:293
SFVEC3F m_lookat_pos_t1
Definition: camera.h:294
float m_zoom_t1
Definition: camera.h:258
SFVEC3F m_rotate_aux_t1
Definition: camera.h:299
glm::mat4 m_viewMatrix
Definition: camera.h:272
SFVEC3F m_camera_pos_init
Definition: camera.h:287
void rebuildProjection()
Definition: camera.cpp:157
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: camera.h:268
SFVEC3F m_camera_pos_t0
Definition: camera.h:289
void updateRotationMatrix()
Definition: camera.cpp:130
void updateViewMatrix()
Definition: camera.cpp:122
float m_zoom_t0
Definition: camera.h:257
glm::mat4 m_rotationMatrix
Definition: camera.h:270
SFVEC3F m_camera_pos_t1
Definition: camera.h:290
SFVEC3F m_lookat_pos
Definition: camera.h:292
glm::mat4 m_projectionMatrix
Definition: camera.h:274
SFVEC3F m_camera_pos
Definition: camera.h:288
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center).
Definition: camera.h:295
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
glm::mat4 m_rotationMatrixAux
Definition: camera.h:271
std::vector< float > m_scr_nY
Definition: camera.h:307
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:306
glm::mat4 m_projectionMatrixInv
Definition: camera.h:275
SFVEC3F m_rotate_aux_t0
Definition: camera.h:298

References m_board_lookat_pos_init, m_camera_pos, m_camera_pos_init, m_camera_pos_t0, m_camera_pos_t1, m_lastPosition, m_lookat_pos, m_lookat_pos_t0, m_lookat_pos_t1, m_parametersChanged, m_projectionMatrix, m_projectionMatrixInv, m_rotate_aux, m_rotate_aux_t0, m_rotate_aux_t1, m_rotationMatrix, m_rotationMatrixAux, m_scr_nX, m_scr_nY, m_viewMatrix, m_viewMatrixInverse, m_zoom, m_zoom_t0, m_zoom_t1, rebuildProjection(), updateRotationMatrix(), and updateViewMatrix().

Referenced by CAMERA(), and TRACK_BALL::Reset().

◆ Reset_T1()

void CAMERA::Reset_T1 ( )
virtual

Reimplemented in TRACK_BALL.

Definition at line 101 of file camera.cpp.

102 {
104  m_zoom_t1 = 1.0f;
105  m_rotate_aux_t1 = SFVEC3F( 0.0f );
107 
108  // Since 0 = 2pi, we want to reset the angle to be the closest
109  // one to where we currently are. That ensures that we rotate
110  // the board around the smallest distance getting there.
111  if( m_rotate_aux_t0.x > M_PI )
112  m_rotate_aux_t1.x = static_cast<float>( 2.0f * M_PI );
113 
114  if( m_rotate_aux_t0.y > M_PI )
115  m_rotate_aux_t1.y = static_cast<float>( 2.0f * M_PI );
116 
117  if( m_rotate_aux_t0.z > M_PI )
118  m_rotate_aux_t1.z = static_cast<float>( 2.0f * M_PI );
119 }
SFVEC3F m_lookat_pos_t1
Definition: camera.h:294
float m_zoom_t1
Definition: camera.h:258
SFVEC3F m_rotate_aux_t1
Definition: camera.h:299
SFVEC3F m_camera_pos_init
Definition: camera.h:287
SFVEC3F m_camera_pos_t1
Definition: camera.h:290
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center).
Definition: camera.h:295
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F m_rotate_aux_t0
Definition: camera.h:298

References m_board_lookat_pos_init, m_camera_pos_init, m_camera_pos_t1, m_lookat_pos_t1, m_rotate_aux_t0, m_rotate_aux_t1, and m_zoom_t1.

Referenced by TRACK_BALL::Reset_T1(), and EDA_3D_CANVAS::SetView3D().

◆ ResetXYpos()

void CAMERA::ResetXYpos ( )

Definition at line 388 of file camera.cpp.

389 {
390  m_parametersChanged = true;
391  m_camera_pos.x = 0.0f;
392  m_camera_pos.y = 0.0f;
393 
395  updateFrustum();
396 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:319
void updateViewMatrix()
Definition: camera.cpp:122
SFVEC3F m_camera_pos
Definition: camera.h:288
void updateFrustum()
Definition: camera.cpp:250

References m_camera_pos, m_parametersChanged, updateFrustum(), and updateViewMatrix().

◆ ResetXYpos_T1()

void CAMERA::ResetXYpos_T1 ( )

Definition at line 399 of file camera.cpp.

400 {
401  m_camera_pos_t1.x = 0.0f;
402  m_camera_pos_t1.y = 0.0f;
403 }
SFVEC3F m_camera_pos_t1
Definition: camera.h:290

References m_camera_pos_t1.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ RotateX()

void CAMERA::RotateX ( float  aAngleInRadians)

Definition at line 510 of file camera.cpp.

511 {
512  m_rotate_aux.x += aAngleInRadians;
514 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:297
void updateRotationMatrix()
Definition: camera.cpp:130

References m_rotate_aux, and updateRotationMatrix().

Referenced by EDA_3D_CONTROLLER::RotateView().

◆ RotateX_T1()

void CAMERA::RotateX_T1 ( float  aAngleInRadians)

Definition at line 531 of file camera.cpp.

532 {
533  m_rotate_aux_t1.x += aAngleInRadians;
534 }
SFVEC3F m_rotate_aux_t1
Definition: camera.h:299

References m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ RotateY()

void CAMERA::RotateY ( float  aAngleInRadians)

Definition at line 517 of file camera.cpp.

518 {
519  m_rotate_aux.y += aAngleInRadians;
521 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:297
void updateRotationMatrix()
Definition: camera.cpp:130

References m_rotate_aux, and updateRotationMatrix().

Referenced by EDA_3D_CONTROLLER::RotateView().

◆ RotateY_T1()

void CAMERA::RotateY_T1 ( float  aAngleInRadians)

Definition at line 537 of file camera.cpp.

538 {
539  m_rotate_aux_t1.y += aAngleInRadians;
540 }
SFVEC3F m_rotate_aux_t1
Definition: camera.h:299

References m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ RotateZ()

void CAMERA::RotateZ ( float  aAngleInRadians)

Definition at line 524 of file camera.cpp.

525 {
526  m_rotate_aux.z += aAngleInRadians;
528 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:297
void updateRotationMatrix()
Definition: camera.cpp:130

References m_rotate_aux, and updateRotationMatrix().

Referenced by EDA_3D_CONTROLLER::RotateView().

◆ RotateZ_T1()

void CAMERA::RotateZ_T1 ( float  aAngleInRadians)

Definition at line 543 of file camera.cpp.

544 {
545  m_rotate_aux_t1.z += aAngleInRadians;
546 }
SFVEC3F m_rotate_aux_t1
Definition: camera.h:299

References m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ SetBoardLookAtPos()

void CAMERA::SetBoardLookAtPos ( const SFVEC3F aBoardPos)
inline

Definition at line 114 of file camera.h.

115  {
116  if( m_board_lookat_pos_init != aBoardPos )
117  {
118  m_board_lookat_pos_init = aBoardPos;
119  SetLookAtPos( aBoardPos );
120  }
121  }
virtual void SetLookAtPos(const SFVEC3F &aLookAtPos)=0
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center).
Definition: camera.h:295

References m_board_lookat_pos_init, and SetLookAtPos().

Referenced by RENDER_3D_RAYTRACE::Reload(), and RENDER_3D_LEGACY::reload().

◆ SetCurMousePosition()

void CAMERA::SetCurMousePosition ( const wxPoint &  aPosition)

Update the current mouse position without make any new calculations on camera.

Definition at line 418 of file camera.cpp.

419 {
420  m_lastPosition = aNewMousePosition;
421 }
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: camera.h:268

References m_lastPosition.

Referenced by C3D_MODEL_VIEWER::OnMouseMove(), EDA_3D_CANVAS::OnMouseMove(), C3D_MODEL_VIEWER::OnMouseWheel(), and EDA_3D_CANVAS::OnMouseWheel().

◆ SetCurWindowSize()

bool CAMERA::SetCurWindowSize ( const wxSize &  aSize)

Update the windows size of the camera.

Returns
true if the windows size changed since last time.

Definition at line 435 of file camera.cpp.

436 {
437  const SFVEC2I newSize = SFVEC2I( aSize.x, aSize.y );
438 
439  if( m_windowSize != newSize )
440  {
441  m_windowSize = newSize;
443 
444  return true;
445  }
446 
447  return false;
448 }
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
void rebuildProjection()
Definition: camera.cpp:157
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:263

References m_windowSize, and rebuildProjection().

Referenced by EDA_3D_CANVAS::DoRePaint(), C3D_MODEL_VIEWER::OnMouseMove(), EDA_3D_CANVAS::OnMouseMove(), and C3D_MODEL_VIEWER::OnPaint().

◆ SetInterpolateMode()

void CAMERA::SetInterpolateMode ( CAMERA_INTERPOLATION  aInterpolateMode)
inline

Definition at line 197 of file camera.h.

198  {
199  m_interpolation_mode = aInterpolateMode;
200  }
CAMERA_INTERPOLATION m_interpolation_mode
Definition: camera.h:301

References m_interpolation_mode.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position(), and EDA_3D_CANVAS::SetView3D().

◆ SetLookAtPos()

virtual void CAMERA::SetLookAtPos ( const SFVEC3F aLookAtPos)
pure virtual

Implemented in TRACK_BALL.

Referenced by SetBoardLookAtPos().

◆ SetLookAtPos_T1()

void CAMERA::SetLookAtPos_T1 ( const SFVEC3F aLookAtPos)
inline

Definition at line 125 of file camera.h.

126  {
127  m_lookat_pos_t1 = aLookAtPos;
128  }
SFVEC3F m_lookat_pos_t1
Definition: camera.h:294

References m_lookat_pos_t1.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ SetT0_and_T1_current_T()

void CAMERA::SetT0_and_T1_current_T ( )
virtual

This will set T0 and T1 with the current values.

Reimplemented in TRACK_BALL.

Definition at line 549 of file camera.cpp.

550 {
554  m_zoom_t0 = m_zoom;
555 
559  m_zoom_t1 = m_zoom;
560 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:297
float m_zoom
3D zoom value (Min 0.0 ...
Definition: camera.h:256
SFVEC3F m_lookat_pos_t0
Definition: camera.h:293
SFVEC3F m_lookat_pos_t1
Definition: camera.h:294
float m_zoom_t1
Definition: camera.h:258
SFVEC3F m_rotate_aux_t1
Definition: camera.h:299
SFVEC3F m_camera_pos_t0
Definition: camera.h:289
float m_zoom_t0
Definition: camera.h:257
SFVEC3F m_camera_pos_t1
Definition: camera.h:290
SFVEC3F m_lookat_pos
Definition: camera.h:292
SFVEC3F m_camera_pos
Definition: camera.h:288
SFVEC3F m_rotate_aux_t0
Definition: camera.h:298

References m_camera_pos, m_camera_pos_t0, m_camera_pos_t1, m_lookat_pos, m_lookat_pos_t0, m_lookat_pos_t1, m_rotate_aux, m_rotate_aux_t0, m_rotate_aux_t1, m_zoom, m_zoom_t0, and m_zoom_t1.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position(), TRACK_BALL::SetT0_and_T1_current_T(), and EDA_3D_CANVAS::SetView3D().

◆ ToggleProjection()

void CAMERA::ToggleProjection ( )

◆ updateFrustum()

void CAMERA::updateFrustum ( )
protected

Definition at line 250 of file camera.cpp.

251 {
252  // Update matrix and vectors
253  m_viewMatrixInverse = glm::inverse( m_viewMatrix );
254 
255  m_right = glm::normalize( SFVEC3F( m_viewMatrixInverse *
256  glm::vec4( SFVEC3F( 1.0, 0.0, 0.0 ), 0.0 ) ) );
257 
258  m_up = glm::normalize( SFVEC3F( m_viewMatrixInverse *
259  glm::vec4( SFVEC3F( 0.0, 1.0, 0.0 ), 0.0 ) ) );
260 
261  m_dir = glm::normalize( SFVEC3F( m_viewMatrixInverse *
262  glm::vec4( SFVEC3F( 0.0, 0.0, 1.0 ), 0.0 ) ) );
263 
264  m_pos = SFVEC3F( m_viewMatrixInverse * glm::vec4( SFVEC3F( 0.0, 0.0, 0.0 ), 1.0 ) );
265 
266  /*
267  * Frustum is a implementation based on a tutorial by
268  * http://www.lighthouse3d.com/tutorials/view-frustum-culling/
269  */
270 
271  // compute the centers of the near and far planes
274 
275  // compute the 4 corners of the frustum on the near plane
280 
281  // compute the 4 corners of the frustum on the far plane
286 
287  if( ( m_windowSize.x > 0 ) && ( m_windowSize.y > 0 ) )
288  {
289  // Reserve size for precalc values
290  m_right_nX.resize( m_windowSize.x + 1 );
291  m_up_nY.resize( m_windowSize.y + 1 );
292 
293  // Precalc X values for camera -> ray generation
294  const SFVEC3F right_nw = m_right * m_frustum.nw;
295 
296  for( unsigned int x = 0; x < ( (unsigned int) m_windowSize.x + 1 ); ++x )
297  m_right_nX[x] = right_nw * m_scr_nX[x];
298 
299  // Precalc Y values for camera -> ray generation
300  const SFVEC3F up_nh = m_up * m_frustum.nh;
301 
302  for( unsigned int y = 0; y < ( (unsigned int) m_windowSize.y + 1 ); ++y )
303  m_up_nY[y] = up_nh * m_scr_nY[y];
304  }
305 }
SFVEC3F fbl
Far Bottom Left.
Definition: camera.h:57
SFVEC3F fc
Definition: camera.h:50
glm::mat4 m_viewMatrixInverse
Definition: camera.h:273
SFVEC3F ftl
Far Top Left.
Definition: camera.h:55
SFVEC3F m_dir
Definition: camera.h:282
SFVEC3F nbr
Near Bottom Right.
Definition: camera.h:54
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:313
glm::mat4 m_viewMatrix
Definition: camera.h:272
float nw
Definition: camera.h:60
SFVEC3F m_up
Definition: camera.h:281
float fw
Definition: camera.h:60
SFVEC3F fbr
Far Bottom Right.
Definition: camera.h:58
float fh
Definition: camera.h:60
SFVEC3F m_pos
Definition: camera.h:283
SFVEC3F nbl
Near Bottom Left.
Definition: camera.h:53
float farD
Definition: camera.h:59
SFVEC3F m_right
Definition: camera.h:280
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:263
float nearD
Definition: camera.h:59
std::vector< SFVEC3F > m_up_nY
Definition: camera.h:314
CAMERA_FRUSTUM m_frustum
Definition: camera.h:278
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F ntl
Near Top Left.
Definition: camera.h:51
SFVEC3F ntr
Near Top Right.
Definition: camera.h:52
std::vector< float > m_scr_nY
Definition: camera.h:307
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:306
SFVEC3F nc
Definition: camera.h:49
float nh
Definition: camera.h:60
SFVEC3F ftr
Far Top Right.
Definition: camera.h:56

References CAMERA_FRUSTUM::farD, CAMERA_FRUSTUM::fbl, CAMERA_FRUSTUM::fbr, CAMERA_FRUSTUM::fc, CAMERA_FRUSTUM::fh, CAMERA_FRUSTUM::ftl, CAMERA_FRUSTUM::ftr, CAMERA_FRUSTUM::fw, m_dir, m_frustum, m_pos, m_right, m_right_nX, m_scr_nX, m_scr_nY, m_up, m_up_nY, m_viewMatrix, m_viewMatrixInverse, m_windowSize, CAMERA_FRUSTUM::nbl, CAMERA_FRUSTUM::nbr, CAMERA_FRUSTUM::nc, CAMERA_FRUSTUM::nearD, CAMERA_FRUSTUM::nh, CAMERA_FRUSTUM::ntl, CAMERA_FRUSTUM::ntr, and CAMERA_FRUSTUM::nw.

Referenced by TRACK_BALL::Drag(), TRACK_BALL::Pan(), rebuildProjection(), ResetXYpos(), TRACK_BALL::SetLookAtPos(), and updateRotationMatrix().

◆ updateRotationMatrix()

void CAMERA::updateRotationMatrix ( )
protected

Definition at line 130 of file camera.cpp.

131 {
132  m_rotationMatrixAux = glm::rotate( glm::mat4( 1.0f ), m_rotate_aux.x,
133  SFVEC3F( 1.0f, 0.0f, 0.0f ) );
135 
137  SFVEC3F( 0.0f, 1.0f, 0.0f ) );
139 
141  SFVEC3F( 0.0f, 0.0f, 1.0f ) );
143 
144  m_parametersChanged = true;
145 
147  updateFrustum();
148 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:297
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:319
void normalise2PI(float &aAngle)
Definition: camera.cpp:34
void updateViewMatrix()
Definition: camera.cpp:122
void updateFrustum()
Definition: camera.cpp:250
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
glm::mat4 m_rotationMatrixAux
Definition: camera.h:271

References m_parametersChanged, m_rotate_aux, m_rotationMatrixAux, normalise2PI(), updateFrustum(), and updateViewMatrix().

Referenced by Interpolate(), Reset(), RotateX(), RotateY(), and RotateZ().

◆ updateViewMatrix()

void CAMERA::updateViewMatrix ( )
protected

Definition at line 122 of file camera.cpp.

123 {
124  m_viewMatrix = glm::translate( glm::mat4( 1.0f ), m_camera_pos ) *
126  glm::translate( glm::mat4( 1.0f ), -m_lookat_pos );
127 }
glm::mat4 m_viewMatrix
Definition: camera.h:272
glm::mat4 m_rotationMatrix
Definition: camera.h:270
SFVEC3F m_lookat_pos
Definition: camera.h:292
SFVEC3F m_camera_pos
Definition: camera.h:288
glm::mat4 m_rotationMatrixAux
Definition: camera.h:271

References m_camera_pos, m_lookat_pos, m_rotationMatrix, m_rotationMatrixAux, and m_viewMatrix.

Referenced by TRACK_BALL::Drag(), TRACK_BALL::Pan(), Reset(), ResetXYpos(), TRACK_BALL::SetLookAtPos(), updateRotationMatrix(), Zoom(), and ZoomReset().

◆ Zoom()

bool CAMERA::Zoom ( float  aFactor)

Definition at line 461 of file camera.cpp.

462 {
463  if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 )
464  || aFactor == 1 )
465  return false;
466 
467  m_zoom /= aFactor;
468 
469  if( m_zoom <= MIN_ZOOM )
470  m_zoom = MIN_ZOOM;
471 
472  if( m_zoom >= MAX_ZOOM )
473  m_zoom = MAX_ZOOM;
474 
476 
479 
480  return true;
481 }
#define MIN_ZOOM
Definition: camera.cpp:50
float m_zoom
3D zoom value (Min 0.0 ...
Definition: camera.h:256
#define MAX_ZOOM
Definition: camera.cpp:51
SFVEC3F m_camera_pos_init
Definition: camera.h:287
void rebuildProjection()
Definition: camera.cpp:157
void updateViewMatrix()
Definition: camera.cpp:122
SFVEC3F m_camera_pos
Definition: camera.h:288

References m_camera_pos, m_camera_pos_init, m_zoom, MAX_ZOOM, MIN_ZOOM, rebuildProjection(), and updateViewMatrix().

Referenced by C3D_MODEL_VIEWER::OnMouseWheel(), and EDA_3D_CANVAS::OnMouseWheel().

◆ Zoom_T1()

bool CAMERA::Zoom_T1 ( float  aFactor)

Definition at line 484 of file camera.cpp.

485 {
486  if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 )
487  || aFactor == 1 )
488  return false;
489 
490  m_zoom_t1 = m_zoom / aFactor;
491 
492  if( m_zoom_t1 < MIN_ZOOM )
494 
495  if( m_zoom_t1 > MAX_ZOOM )
497 
499 
500  return true;
501 }
#define MIN_ZOOM
Definition: camera.cpp:50
float m_zoom
3D zoom value (Min 0.0 ...
Definition: camera.h:256
#define MAX_ZOOM
Definition: camera.cpp:51
float m_zoom_t1
Definition: camera.h:258
SFVEC3F m_camera_pos_init
Definition: camera.h:287
SFVEC3F m_camera_pos_t1
Definition: camera.h:290

References m_camera_pos_init, m_camera_pos_t1, m_zoom, m_zoom_t1, MAX_ZOOM, and MIN_ZOOM.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ ZoomGet()

float CAMERA::ZoomGet ( ) const

Definition at line 504 of file camera.cpp.

505 {
506  return m_zoom;
507 }
float m_zoom
3D zoom value (Min 0.0 ...
Definition: camera.h:256

References m_zoom.

Referenced by EDA_3D_CANVAS::DoRePaint(), EDA_3D_CANVAS::OnMouseWheel(), and EDA_3D_CANVAS::SetView3D().

◆ ZoomReset()

void CAMERA::ZoomReset ( )

Definition at line 451 of file camera.cpp.

452 {
453  m_zoom = 1.0f;
454 
456 
459 }
float m_zoom
3D zoom value (Min 0.0 ...
Definition: camera.h:256
SFVEC3F m_camera_pos_init
Definition: camera.h:287
void rebuildProjection()
Definition: camera.cpp:157
void updateViewMatrix()
Definition: camera.cpp:122
SFVEC3F m_camera_pos
Definition: camera.h:288

References m_camera_pos, m_camera_pos_init, m_zoom, rebuildProjection(), and updateViewMatrix().

Member Data Documentation

◆ m_board_lookat_pos_init

SFVEC3F CAMERA::m_board_lookat_pos_init
protected

Default boardlookat position (the board center).

Definition at line 295 of file camera.h.

Referenced by CAMERA(), Reset(), Reset_T1(), and SetBoardLookAtPos().

◆ m_camera_pos

◆ m_camera_pos_init

SFVEC3F CAMERA::m_camera_pos_init
protected

Definition at line 287 of file camera.h.

Referenced by CAMERA(), rebuildProjection(), Reset(), Reset_T1(), Zoom(), Zoom_T1(), and ZoomReset().

◆ m_camera_pos_t0

SFVEC3F CAMERA::m_camera_pos_t0
protected

Definition at line 289 of file camera.h.

Referenced by Interpolate(), Reset(), and SetT0_and_T1_current_T().

◆ m_camera_pos_t1

SFVEC3F CAMERA::m_camera_pos_t1
protected

◆ m_dir

SFVEC3F CAMERA::m_dir
protected

Definition at line 282 of file camera.h.

Referenced by GetDir(), MakeRay(), and updateFrustum().

◆ m_focalLen

SFVEC2F CAMERA::m_focalLen
protected

Definition at line 285 of file camera.h.

Referenced by GetFocalLen(), and rebuildProjection().

◆ m_frustum

CAMERA_FRUSTUM CAMERA::m_frustum
protected

Definition at line 278 of file camera.h.

Referenced by GetFar(), GetNear(), MakeRay(), TRACK_BALL::Pan(), rebuildProjection(), and updateFrustum().

◆ m_interpolation_mode

CAMERA_INTERPOLATION CAMERA::m_interpolation_mode
protected

Definition at line 301 of file camera.h.

Referenced by CAMERA(), TRACK_BALL::Interpolate(), and SetInterpolateMode().

◆ m_lastPosition

wxPoint CAMERA::m_lastPosition
protected

The last mouse position in the screen.

Definition at line 268 of file camera.h.

Referenced by TRACK_BALL::Drag(), MakeRayAtCurrrentMousePosition(), TRACK_BALL::Pan(), Reset(), and SetCurMousePosition().

◆ m_lookat_pos

SFVEC3F CAMERA::m_lookat_pos
protected

◆ m_lookat_pos_t0

SFVEC3F CAMERA::m_lookat_pos_t0
protected

Definition at line 293 of file camera.h.

Referenced by Interpolate(), Reset(), and SetT0_and_T1_current_T().

◆ m_lookat_pos_t1

SFVEC3F CAMERA::m_lookat_pos_t1
protected

◆ m_parametersChanged

bool CAMERA::m_parametersChanged
protected

Set to true if any of the parameters in the camera was changed.

Definition at line 319 of file camera.h.

Referenced by TRACK_BALL::Drag(), Interpolate(), TRACK_BALL::Pan(), ParametersChanged(), ParametersChangedQuery(), Reset(), ResetXYpos(), TRACK_BALL::SetLookAtPos(), and updateRotationMatrix().

◆ m_pos

SFVEC3F CAMERA::m_pos
protected

Definition at line 283 of file camera.h.

Referenced by GetPos(), MakeRay(), and updateFrustum().

◆ m_projectionMatrix

glm::mat4 CAMERA::m_projectionMatrix
protected

Definition at line 274 of file camera.h.

Referenced by GetProjectionMatrix(), rebuildProjection(), and Reset().

◆ m_projectionMatrixInv

glm::mat4 CAMERA::m_projectionMatrixInv
protected

Definition at line 275 of file camera.h.

Referenced by GetProjectionMatrixInv(), rebuildProjection(), and Reset().

◆ m_projectionType

PROJECTION_TYPE CAMERA::m_projectionType
protected

◆ m_range_scale

float CAMERA::m_range_scale
protected

The nominal range expected to be used in the camera.

It will be used to initialize the Z position

Definition at line 251 of file camera.h.

Referenced by CAMERA().

◆ m_right

SFVEC3F CAMERA::m_right
protected

Definition at line 280 of file camera.h.

Referenced by GetRight(), and updateFrustum().

◆ m_right_nX

std::vector< SFVEC3F > CAMERA::m_right_nX
protected

Precalc values array used to calc ray for each pixel, for X and Y axis of each new camera position.

Definition at line 313 of file camera.h.

Referenced by MakeRay(), and updateFrustum().

◆ m_rotate_aux

SFVEC3F CAMERA::m_rotate_aux
protected

Stores the rotation angle auxiliary.

Definition at line 297 of file camera.h.

Referenced by Interpolate(), Reset(), RotateX(), RotateY(), RotateZ(), SetT0_and_T1_current_T(), and updateRotationMatrix().

◆ m_rotate_aux_t0

SFVEC3F CAMERA::m_rotate_aux_t0
protected

Definition at line 298 of file camera.h.

Referenced by Interpolate(), Reset(), Reset_T1(), and SetT0_and_T1_current_T().

◆ m_rotate_aux_t1

SFVEC3F CAMERA::m_rotate_aux_t1
protected

◆ m_rotationMatrix

glm::mat4 CAMERA::m_rotationMatrix
protected

◆ m_rotationMatrixAux

glm::mat4 CAMERA::m_rotationMatrixAux
protected

Definition at line 271 of file camera.h.

Referenced by GetRotationMatrix(), Reset(), updateRotationMatrix(), and updateViewMatrix().

◆ m_scr_nX

std::vector< float > CAMERA::m_scr_nX
protected

Precalc values array used to calc ray for each pixel (constant for the same window size).

Definition at line 306 of file camera.h.

Referenced by rebuildProjection(), Reset(), and updateFrustum().

◆ m_scr_nY

std::vector< float > CAMERA::m_scr_nY
protected

Definition at line 307 of file camera.h.

Referenced by rebuildProjection(), Reset(), and updateFrustum().

◆ m_up

SFVEC3F CAMERA::m_up
protected

Definition at line 281 of file camera.h.

Referenced by GetUp(), and updateFrustum().

◆ m_up_nY

std::vector< SFVEC3F > CAMERA::m_up_nY
protected

Definition at line 314 of file camera.h.

Referenced by MakeRay(), and updateFrustum().

◆ m_viewMatrix

glm::mat4 CAMERA::m_viewMatrix
protected

Definition at line 272 of file camera.h.

Referenced by GetViewMatrix(), Reset(), updateFrustum(), and updateViewMatrix().

◆ m_viewMatrixInverse

glm::mat4 CAMERA::m_viewMatrixInverse
protected

Definition at line 273 of file camera.h.

Referenced by GetViewMatrix_Inv(), Reset(), and updateFrustum().

◆ m_windowSize

SFVEC2I CAMERA::m_windowSize
protected

The window size that this camera is working.

Definition at line 263 of file camera.h.

Referenced by CAMERA(), TRACK_BALL::Drag(), MakeRay(), MakeRayAtCurrrentMousePosition(), TRACK_BALL::Pan(), rebuildProjection(), SetCurWindowSize(), and updateFrustum().

◆ m_zoom

float CAMERA::m_zoom
protected

3D zoom value (Min 0.0 ...

Max 1.0)

Definition at line 256 of file camera.h.

Referenced by Interpolate(), rebuildProjection(), Reset(), SetT0_and_T1_current_T(), Zoom(), Zoom_T1(), ZoomGet(), and ZoomReset().

◆ m_zoom_t0

float CAMERA::m_zoom_t0
protected

Definition at line 257 of file camera.h.

Referenced by Interpolate(), Reset(), and SetT0_and_T1_current_T().

◆ m_zoom_t1

float CAMERA::m_zoom_t1
protected

Definition at line 258 of file camera.h.

Referenced by Interpolate(), Reset(), Reset_T1(), SetT0_and_T1_current_T(), and Zoom_T1().


The documentation for this class was generated from the following files: