KiCad PCB EDA Suite
CCAMERA Class Referenceabstract

Class CCAMERA is a virtual class used to derive CCAMERA objects from. More...

#include <ccamera.h>

Inheritance diagram for CCAMERA:
CTRACK_BALL

Public Member Functions

 CCAMERA (float aRangeScale)
 CCAMERA initialize a camera. More...
 
virtual ~CCAMERA ()
 
const glm::mat4 GetRotationMatrix () const
 Function GetRotationMatrix 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)
 It updates the current mouse position without make any new recalculations on camera. More...
 
void ToggleProjection ()
 
PROJECTION_TYPE GetProjection ()
 
bool SetCurWindowSize (const wxSize &aSize)
 SetCurWindowSize - 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 ()
 SetT0_and_T1_current_T - This will set T0 and T1 with the current values. More...
 
virtual void Interpolate (float t)
 Interpolate - It will update the matrix to interpolate between T0 and T1 values. More...
 
void SetInterpolateMode (CAMERA_INTERPOLATION aInterpolateMode)
 
bool ParametersChanged ()
 Function ParametersChanged. More...
 
bool ParametersChangedQuery () const
 Function ParametersChangedQuery. More...
 
void MakeRay (const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
 MakeRay - Make a ray based on a windows screen position. More...
 
void MakeRay (const SFVEC2F &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
 MakeRay - Make a ray based on a windows screen position, it will interpolate based on the float aWindowPos. More...
 
void MakeRayAtCurrrentMousePosition (SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
 MakeRayAtCurrrentMousePosition - 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
 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
 
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 auxiliar. 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_CCAMERA" )
 Trace mask used to enable or disable the trace output of this class. More...
 

Detailed Description

Class CCAMERA is a virtual class used to derive CCAMERA objects from.

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

Definition at line 79 of file ccamera.h.

Constructor & Destructor Documentation

◆ CCAMERA()

CCAMERA::CCAMERA ( float  aRangeScale)
explicit

CCAMERA initialize a camera.

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

Definition at line 56 of file ccamera.cpp.

57 {
58  wxLogTrace( m_logTrace, wxT( "CCAMERA::CCAMERA" ) );
59 
60  m_range_scale = aRangeScale;
61  m_camera_pos_init = SFVEC3F( 0.0f, 0.0f, -(aRangeScale * 2.0f ) );
63  m_windowSize = SFVEC2I( 0, 0 );
66 
67  Reset();
68 }
virtual void Reset()
Reset the camera to initial state.
Definition: ccamera.cpp:71
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Definition: ccamera.h:332
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center)
Definition: ccamera.h:298
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
float m_range_scale
m_range_scale - the nominal range expected to be used in the camera.
Definition: ccamera.h:254
SFVEC3F m_camera_pos_init
Definition: ccamera.h:290
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266
CAMERA_INTERPOLATION m_interpolation_mode
Definition: ccamera.h:304
PROJECTION_TYPE m_projectionType
Definition: ccamera.h:279

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().

◆ ~CCAMERA()

virtual CCAMERA::~CCAMERA ( )
inlinevirtual

Definition at line 92 of file ccamera.h.

93  {
94  }

Member Function Documentation

◆ Drag()

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

Calculate a new mouse drag position.

Implemented in CTRACK_BALL.

Referenced by EDA_3D_CANVAS::OnMouseMove().

◆ GetCameraPos()

const SFVEC3F& CCAMERA::GetCameraPos ( ) const
inline

Definition at line 134 of file ccamera.h.

134 { return m_camera_pos; }
SFVEC3F m_camera_pos
Definition: ccamera.h:291

References m_camera_pos.

Referenced by EDA_3D_CANVAS::DisplayStatus().

◆ GetDir()

const SFVEC3F& CCAMERA::GetDir ( ) const
inline

Definition at line 112 of file ccamera.h.

112 { return m_dir; }
SFVEC3F m_dir
Definition: ccamera.h:285

References m_dir.

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

◆ GetFar()

float CCAMERA::GetFar ( ) const
inline

Definition at line 116 of file ccamera.h.

116 { return m_frustum.farD; }
float farD
Definition: ccamera.h:60
FRUSTUM m_frustum
Definition: ccamera.h:281

References FRUSTUM::farD, and m_frustum.

◆ GetFocalLen()

const SFVEC2F& CCAMERA::GetFocalLen ( ) const
inline

Definition at line 114 of file ccamera.h.

114 { return m_focalLen; }
SFVEC2F m_focalLen
Definition: ccamera.h:288

References m_focalLen.

◆ GetLookAtPos_T1()

const SFVEC3F& CCAMERA::GetLookAtPos_T1 ( ) const
inline

Definition at line 132 of file ccamera.h.

132 { return m_lookat_pos_t1; }
SFVEC3F m_lookat_pos_t1
Definition: ccamera.h:297

References m_lookat_pos_t1.

Referenced by EDA_3D_CANVAS::render_pivot().

◆ GetNear()

float CCAMERA::GetNear ( ) const
inline

Definition at line 115 of file ccamera.h.

115 { return m_frustum.nearD; }
float nearD
Definition: ccamera.h:60
FRUSTUM m_frustum
Definition: ccamera.h:281

References m_frustum, and FRUSTUM::nearD.

◆ GetPos()

const SFVEC3F& CCAMERA::GetPos ( ) const
inline

Definition at line 113 of file ccamera.h.

113 { return m_pos; }
SFVEC3F m_pos
Definition: ccamera.h:286

References m_pos.

Referenced by C3D_RENDER_OGL_LEGACY::Redraw(), and C3D_RENDER_OGL_LEGACY::render_solder_mask_layer().

◆ GetProjection()

PROJECTION_TYPE CCAMERA::GetProjection ( )
inline

Definition at line 164 of file ccamera.h.

164 { return m_projectionType; }
PROJECTION_TYPE m_projectionType
Definition: ccamera.h:279

References m_projectionType.

Referenced by EDA_3D_VIEWER::setupUIConditions().

◆ GetProjectionMatrix()

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

Definition at line 393 of file ccamera.cpp.

394 {
395  return m_projectionMatrix;
396 }
glm::mat4 m_projectionMatrix
Definition: ccamera.h:277

References m_projectionMatrix.

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

◆ GetProjectionMatrixInv()

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

Definition at line 399 of file ccamera.cpp.

400 {
401  return m_projectionMatrixInv;
402 }
glm::mat4 m_projectionMatrixInv
Definition: ccamera.h:278

References m_projectionMatrixInv.

◆ GetRight()

const SFVEC3F& CCAMERA::GetRight ( ) const
inline

Definition at line 110 of file ccamera.h.

110 { return m_right; }
SFVEC3F m_right
Definition: ccamera.h:283

References m_right.

◆ GetRotationMatrix()

const glm::mat4 CCAMERA::GetRotationMatrix ( ) const

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

Returns
the rotation matrix of the camera

Definition at line 157 of file ccamera.cpp.

158 {
160 }
glm::mat4 m_rotationMatrix
Definition: ccamera.h:273
glm::mat4 m_rotationMatrixAux
Definition: ccamera.h:274

References m_rotationMatrix, and m_rotationMatrixAux.

Referenced by C3D_MODEL_VIEWER::OnPaint(), and C3D_RENDER_OGL_LEGACY::render_3D_arrows().

◆ GetUp()

const SFVEC3F& CCAMERA::GetUp ( ) const
inline

Definition at line 111 of file ccamera.h.

111 { return m_up; }
SFVEC3F m_up
Definition: ccamera.h:284

References m_up.

◆ GetViewMatrix()

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

Definition at line 423 of file ccamera.cpp.

424 {
425  return m_viewMatrix;
426 }
glm::mat4 m_viewMatrix
Definition: ccamera.h:275

References m_viewMatrix.

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

◆ GetViewMatrix_Inv()

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

Definition at line 429 of file ccamera.cpp.

430 {
431  return m_viewMatrixInverse;
432 }
glm::mat4 m_viewMatrixInverse
Definition: ccamera.h:276

References m_viewMatrixInverse.

◆ Interpolate()

void CCAMERA::Interpolate ( float  t)
virtual

Interpolate - 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 CTRACK_BALL.

Definition at line 573 of file ccamera.cpp.

574 {
575  wxASSERT( t >= 0.0f );
576 
577  const float t0 = 1.0f - t;
578 
582  m_zoom = m_zoom_t0 * t0 + m_zoom_t1 * t;
583 
584  m_parametersChanged = true;
585 
588 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: ccamera.h:324
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
SFVEC3F m_camera_pos_t1
Definition: ccamera.h:293
float m_zoom_t0
Definition: ccamera.h:260
SFVEC3F m_lookat_pos_t1
Definition: ccamera.h:297
SFVEC3F m_lookat_pos_t0
Definition: ccamera.h:296
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302
void updateRotationMatrix()
Definition: ccamera.cpp:133
SFVEC3F m_camera_pos
Definition: ccamera.h:291
SFVEC3F m_camera_pos_t0
Definition: ccamera.h:292
void rebuildProjection()
Definition: ccamera.cpp:163
float m_zoom_t1
Definition: ccamera.h:261
SFVEC3F m_rotate_aux_t0
Definition: ccamera.h:301
SFVEC3F m_lookat_pos
Definition: ccamera.h:295

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(), CTRACK_BALL::Interpolate(), and EDA_3D_CANVAS::request_start_moving_camera().

◆ MakeRay() [1/2]

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

MakeRay - 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 322 of file ccamera.cpp.

325 {
326  wxASSERT( aWindowPos.x < m_windowSize.x );
327  wxASSERT( aWindowPos.y < m_windowSize.y );
328 
329  const SFVEC3F up_plus_right = m_up_nY[aWindowPos.y] +
330  m_right_nX[aWindowPos.x];
331 
332  switch( m_projectionType )
333  {
334  default:
336  aOutOrigin = up_plus_right + m_frustum.nc;
337  aOutDirection = glm::normalize( aOutOrigin - m_pos );
338  break;
339 
341  aOutOrigin = up_plus_right * 0.5f + m_frustum.nc;
342  aOutDirection = -m_dir + SFVEC3F( FLT_EPSILON );
343  break;
344  }
345 }
SFVEC3F m_dir
Definition: ccamera.h:285
std::vector< SFVEC3F > m_up_nY
Definition: ccamera.h:318
SFVEC3F m_pos
Definition: ccamera.h:286
FRUSTUM m_frustum
Definition: ccamera.h:281
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: ccamera.h:317
SFVEC3F nc
Definition: ccamera.h:50
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266
PROJECTION_TYPE m_projectionType
Definition: ccamera.h:279

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

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

◆ MakeRay() [2/2]

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

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

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

Definition at line 348 of file ccamera.cpp.

349 {
350  wxASSERT( aWindowPos.x < (float)m_windowSize.x );
351  wxASSERT( aWindowPos.y < (float)m_windowSize.y );
352 
353  const SFVEC2F floorWinPos_f = glm::floor( aWindowPos );
354  const SFVEC2I floorWinPos_i = (SFVEC2I)floorWinPos_f;
355  const SFVEC2F relativeWinPos = aWindowPos - floorWinPos_f;
356 
357  // Note: size of vectors m_up and m_right are m_windowSize + 1
358  const SFVEC3F up_plus_right = m_up_nY[floorWinPos_i.y] * (1.0f - relativeWinPos.y) +
359  m_up_nY[floorWinPos_i.y + 1] * relativeWinPos.y +
360  m_right_nX[floorWinPos_i.x] * (1.0f - relativeWinPos.x) +
361  m_right_nX[floorWinPos_i.x + 1] * relativeWinPos.x;
362 
363  switch( m_projectionType )
364  {
365  default:
367  aOutOrigin = up_plus_right + m_frustum.nc;
368  aOutDirection = glm::normalize( aOutOrigin - m_pos );
369  break;
370 
372  aOutOrigin = up_plus_right * 0.5f + m_frustum.nc;
373  aOutDirection = -m_dir + SFVEC3F( FLT_EPSILON );
374  break;
375  }
376 }
SFVEC3F m_dir
Definition: ccamera.h:285
std::vector< SFVEC3F > m_up_nY
Definition: ccamera.h:318
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
SFVEC3F m_pos
Definition: ccamera.h:286
FRUSTUM m_frustum
Definition: ccamera.h:281
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: ccamera.h:317
SFVEC3F nc
Definition: ccamera.h:50
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266
PROJECTION_TYPE m_projectionType
Definition: ccamera.h:279

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

◆ MakeRayAtCurrrentMousePosition()

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

MakeRayAtCurrrentMousePosition - Make a ray based on the latest mouse position.

Parameters
aOutOriginout origin position of the ray
aOutDirectionout direction

Definition at line 379 of file ccamera.cpp.

381 {
382  const SFVEC2I windowPos = SFVEC2I( m_lastPosition.x,
384 
385  if( ( 0 < windowPos.x ) && ( windowPos.x < m_windowSize.x ) &&
386  ( 0 < windowPos.y ) && ( windowPos.y < m_windowSize.y ) )
387  {
388  MakeRay( windowPos, aOutOrigin, aOutDirection );
389  }
390 }
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: ccamera.h:271
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266
void MakeRay(const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
MakeRay - Make a ray based on a windows screen position.
Definition: ccamera.cpp:322

References m_lastPosition, m_windowSize, and MakeRay().

Referenced by EDA_3D_CANVAS::getRayAtCurrrentMousePosition().

◆ Pan() [1/2]

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

◆ Pan() [2/2]

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

Implemented in CTRACK_BALL.

◆ Pan_T1()

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

Implemented in CTRACK_BALL.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ ParametersChanged()

bool CCAMERA::ParametersChanged ( )

Function ParametersChanged.

Returns
true if some of the parameters in camera was changed, it will reset the flag

Definition at line 591 of file ccamera.cpp.

592 {
593  const bool parametersChanged = m_parametersChanged;
594 
595  m_parametersChanged = false;
596 
597  return parametersChanged;
598 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: ccamera.h:324

References m_parametersChanged.

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

◆ ParametersChangedQuery()

bool CCAMERA::ParametersChangedQuery ( ) const
inline

Function ParametersChangedQuery.

Returns
true if some of the parameters in camera was changed, it will NOT reset the flag

Definition at line 217 of file ccamera.h.

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

References m_parametersChanged.

◆ rebuildProjection()

void CCAMERA::rebuildProjection ( )
protected

Definition at line 163 of file ccamera.cpp.

164 {
165  if( (m_windowSize.x == 0) ||
166  (m_windowSize.y == 0) )
167  return;
168 
169  m_frustum.ratio = (float) m_windowSize.x / (float)m_windowSize.y;
170 
171  // Consider that we can render double the length multiplied by the 2/sqrt(2)
172  //
173  m_frustum.farD = glm::length( m_camera_pos_init ) * 2.0f * ( 2.0f * sqrtf( 2.0f ) );
174 
175  switch( m_projectionType )
176  {
177  default:
179 
180  m_frustum.nearD = 0.10f;
181 
182  // Ratio width / height of the window display
183  m_frustum.angle = 45.0f * m_zoom;
184 
185 
186  m_projectionMatrix = glm::perspective( glm::radians( m_frustum.angle ),
189  m_frustum.farD );
190 
191  m_projectionMatrixInv = glm::inverse( m_projectionMatrix );
192 
193  m_frustum.tang = glm::tan( glm::radians( m_frustum.angle ) * 0.5f );
194 
195  m_focalLen.x = ( (float)m_windowSize.y / (float)m_windowSize.x ) / m_frustum.tang;
196  m_focalLen.y = 1.0f / m_frustum.tang;
197 
202  break;
203 
205 
206  m_frustum.nearD = -m_frustum.farD; // Use a symmetrical clip plane for ortho projection
207 
208  // This formula was found by trial and error
209  const float orthoReductionFactor = glm::length( m_camera_pos_init ) *
210  m_zoom * m_zoom * 0.5f;
211 
212  // Initialize Projection Matrix for Ortographic View
213  m_projectionMatrix = glm::ortho( -m_frustum.ratio * orthoReductionFactor,
214  m_frustum.ratio * orthoReductionFactor,
215  -orthoReductionFactor,
216  orthoReductionFactor,
218 
219  m_projectionMatrixInv = glm::inverse( m_projectionMatrix );
220 
221  m_frustum.nw = orthoReductionFactor * 2.0f * m_frustum.ratio;
222  m_frustum.nh = orthoReductionFactor * 2.0f;
225 
226  break;
227  }
228 
229  if ( (m_windowSize.x > 0) &&
230  (m_windowSize.y > 0) )
231  {
232  m_scr_nX.resize( m_windowSize.x + 1 );
233  m_scr_nY.resize( m_windowSize.y + 1 );
234 
235  // Precalc X values for camera -> ray generation
236  for( unsigned int x = 0; x < (unsigned int)m_windowSize.x + 1; ++x )
237  {
238  // Converts 0.0 .. 1.0
239  const float xNormalizedDeviceCoordinates = ( ( (float)x + 0.5f ) /
240  (m_windowSize.x - 0.0f) );
241 
242  // Converts -1.0 .. 1.0
243  m_scr_nX[x] = 2.0f * xNormalizedDeviceCoordinates - 1.0f;
244  }
245 
246  // Precalc Y values for camera -> ray generation
247  for( unsigned int y = 0; y < (unsigned int)m_windowSize.y + 1 ; ++y )
248  {
249  // Converts 0.0 .. 1.0
250  const float yNormalizedDeviceCoordinates = ( ( (float)y + 0.5f ) /
251  (m_windowSize.y - 0.0f) );
252 
253  // Converts -1.0 .. 1.0
254  m_scr_nY[y] = 2.0f * yNormalizedDeviceCoordinates - 1.0f;
255  }
256 
257  updateFrustum();
258  }
259 }
float farD
Definition: ccamera.h:60
void updateFrustum()
Definition: ccamera.cpp:262
float nearD
Definition: ccamera.h:60
float nw
Definition: ccamera.h:61
std::vector< float > m_scr_nY
Definition: ccamera.h:311
std::vector< float > m_scr_nX
Precalc values array used to calc ray for each pixel (constant for the same window size)
Definition: ccamera.h:310
float tang
Definition: ccamera.h:60
float fw
Definition: ccamera.h:61
SFVEC2F m_focalLen
Definition: ccamera.h:288
float angle
Definition: ccamera.h:60
FRUSTUM m_frustum
Definition: ccamera.h:281
glm::mat4 m_projectionMatrix
Definition: ccamera.h:277
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259
SFVEC3F m_camera_pos_init
Definition: ccamera.h:290
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266
float fh
Definition: ccamera.h:61
float nh
Definition: ccamera.h:61
float ratio
Definition: ccamera.h:60
glm::mat4 m_projectionMatrixInv
Definition: ccamera.h:278
PROJECTION_TYPE m_projectionType
Definition: ccamera.h:279

References FRUSTUM::angle, FRUSTUM::farD, FRUSTUM::fh, 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, FRUSTUM::nearD, FRUSTUM::nh, FRUSTUM::nw, ORTHO, PERSPECTIVE, FRUSTUM::ratio, FRUSTUM::tang, and updateFrustum().

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

◆ Reset()

void CCAMERA::Reset ( )
virtual

Reset the camera to initial state.

Reimplemented in CTRACK_BALL.

Definition at line 71 of file ccamera.cpp.

72 {
73  m_parametersChanged = true;
74  m_projectionMatrix = glm::mat4( 1.0f );
75  m_projectionMatrixInv = glm::mat4( 1.0f );
76  m_rotationMatrix = glm::mat4( 1.0f );
77  m_rotationMatrixAux = glm::mat4( 1.0f );
78  m_lastPosition = wxPoint( 0, 0 );
79 
80  m_zoom = 1.0f;
81  m_zoom_t0 = 1.0f;
82  m_zoom_t1 = 1.0f;
89 
90  m_rotate_aux = SFVEC3F( 0.0f );
91  m_rotate_aux_t0 = SFVEC3F( 0.0f );
92  m_rotate_aux_t1 = SFVEC3F( 0.0f );
93 
96  m_viewMatrixInverse = glm::inverse( m_viewMatrix );
97  m_scr_nX.clear();
98  m_scr_nY.clear();
100 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: ccamera.h:324
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center)
Definition: ccamera.h:298
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
glm::mat4 m_viewMatrixInverse
Definition: ccamera.h:276
std::vector< float > m_scr_nY
Definition: ccamera.h:311
std::vector< float > m_scr_nX
Precalc values array used to calc ray for each pixel (constant for the same window size)
Definition: ccamera.h:310
void updateViewMatrix()
Definition: ccamera.cpp:125
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: ccamera.h:271
SFVEC3F m_camera_pos_t1
Definition: ccamera.h:293
float m_zoom_t0
Definition: ccamera.h:260
SFVEC3F m_lookat_pos_t1
Definition: ccamera.h:297
SFVEC3F m_lookat_pos_t0
Definition: ccamera.h:296
glm::mat4 m_rotationMatrix
Definition: ccamera.h:273
glm::mat4 m_projectionMatrix
Definition: ccamera.h:277
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302
void updateRotationMatrix()
Definition: ccamera.cpp:133
SFVEC3F m_camera_pos_init
Definition: ccamera.h:290
SFVEC3F m_camera_pos
Definition: ccamera.h:291
SFVEC3F m_camera_pos_t0
Definition: ccamera.h:292
void rebuildProjection()
Definition: ccamera.cpp:163
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
float m_zoom_t1
Definition: ccamera.h:261
SFVEC3F m_rotate_aux_t0
Definition: ccamera.h:301
glm::mat4 m_rotationMatrixAux
Definition: ccamera.h:274
glm::mat4 m_viewMatrix
Definition: ccamera.h:275
glm::mat4 m_projectionMatrixInv
Definition: ccamera.h:278
SFVEC3F m_lookat_pos
Definition: ccamera.h:295

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 CCAMERA(), and CTRACK_BALL::Reset().

◆ Reset_T1()

void CCAMERA::Reset_T1 ( )
virtual

Reimplemented in CTRACK_BALL.

Definition at line 103 of file ccamera.cpp.

104 {
106  m_zoom_t1 = 1.0f;
107  m_rotate_aux_t1 = SFVEC3F( 0.0f );
109 
110 
111  // Since 0 = 2pi, we want to reset the angle to be the closest
112  // one to where we currently are. That ensures that we rotate
113  // the board around the smallest distance getting there.
114  if( m_rotate_aux_t0.x > M_PI )
115  m_rotate_aux_t1.x = static_cast<float>( 2.0f * M_PI );
116 
117  if( m_rotate_aux_t0.y > M_PI )
118  m_rotate_aux_t1.y = static_cast<float>( 2.0f * M_PI );
119 
120  if( m_rotate_aux_t0.z > M_PI )
121  m_rotate_aux_t1.z = static_cast<float>( 2.0f * M_PI );
122 }
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center)
Definition: ccamera.h:298
SFVEC3F m_camera_pos_t1
Definition: ccamera.h:293
SFVEC3F m_lookat_pos_t1
Definition: ccamera.h:297
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302
SFVEC3F m_camera_pos_init
Definition: ccamera.h:290
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
float m_zoom_t1
Definition: ccamera.h:261
SFVEC3F m_rotate_aux_t0
Definition: ccamera.h:301

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 CTRACK_BALL::Reset_T1(), and EDA_3D_CANVAS::SetView3D().

◆ ResetXYpos()

void CCAMERA::ResetXYpos ( )

Definition at line 405 of file ccamera.cpp.

406 {
407  m_parametersChanged = true;
408  m_camera_pos.x = 0.0f;
409  m_camera_pos.y = 0.0f;
410 
412  updateFrustum();
413 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: ccamera.h:324
void updateFrustum()
Definition: ccamera.cpp:262
void updateViewMatrix()
Definition: ccamera.cpp:125
SFVEC3F m_camera_pos
Definition: ccamera.h:291

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

◆ ResetXYpos_T1()

void CCAMERA::ResetXYpos_T1 ( )

Definition at line 416 of file ccamera.cpp.

417 {
418  m_camera_pos_t1.x = 0.0f;
419  m_camera_pos_t1.y = 0.0f;
420 }
SFVEC3F m_camera_pos_t1
Definition: ccamera.h:293

References m_camera_pos_t1.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ RotateX()

void CCAMERA::RotateX ( float  aAngleInRadians)

Definition at line 520 of file ccamera.cpp.

521 {
522  m_rotate_aux.x += aAngleInRadians;
524 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
void updateRotationMatrix()
Definition: ccamera.cpp:133

References m_rotate_aux, and updateRotationMatrix().

Referenced by EDA_3D_CONTROLLER::RotateView().

◆ RotateX_T1()

void CCAMERA::RotateX_T1 ( float  aAngleInRadians)

Definition at line 541 of file ccamera.cpp.

542 {
543  m_rotate_aux_t1.x += aAngleInRadians;
544 }
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302

References m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ RotateY()

void CCAMERA::RotateY ( float  aAngleInRadians)

Definition at line 527 of file ccamera.cpp.

528 {
529  m_rotate_aux.y += aAngleInRadians;
531 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
void updateRotationMatrix()
Definition: ccamera.cpp:133

References m_rotate_aux, and updateRotationMatrix().

Referenced by EDA_3D_CONTROLLER::RotateView().

◆ RotateY_T1()

void CCAMERA::RotateY_T1 ( float  aAngleInRadians)

Definition at line 547 of file ccamera.cpp.

548 {
549  m_rotate_aux_t1.y += aAngleInRadians;
550 }
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302

References m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ RotateZ()

void CCAMERA::RotateZ ( float  aAngleInRadians)

Definition at line 534 of file ccamera.cpp.

535 {
536  m_rotate_aux.z += aAngleInRadians;
538 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
void updateRotationMatrix()
Definition: ccamera.cpp:133

References m_rotate_aux, and updateRotationMatrix().

Referenced by EDA_3D_CONTROLLER::RotateView().

◆ RotateZ_T1()

void CCAMERA::RotateZ_T1 ( float  aAngleInRadians)

Definition at line 553 of file ccamera.cpp.

554 {
555  m_rotate_aux_t1.z += aAngleInRadians;
556 }
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302

References m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ SetBoardLookAtPos()

void CCAMERA::SetBoardLookAtPos ( const SFVEC3F aBoardPos)
inline

Definition at line 118 of file ccamera.h.

118  {
119  if( m_board_lookat_pos_init != aBoardPos )
120  {
121  m_board_lookat_pos_init = aBoardPos;
122  SetLookAtPos( aBoardPos );
123  }
124  }
SFVEC3F m_board_lookat_pos_init
Default boardlookat position (the board center)
Definition: ccamera.h:298
virtual void SetLookAtPos(const SFVEC3F &aLookAtPos)=0

References m_board_lookat_pos_init, and SetLookAtPos().

Referenced by C3D_RENDER_RAYTRACING::Reload(), and C3D_RENDER_OGL_LEGACY::reload().

◆ SetCurMousePosition()

void CCAMERA::SetCurMousePosition ( const wxPoint &  aPosition)

It updates the current mouse position without make any new recalculations on camera.

Definition at line 435 of file ccamera.cpp.

436 {
437  m_lastPosition = aNewMousePosition;
438 }
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: ccamera.h:271

References m_lastPosition.

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

◆ SetCurWindowSize()

bool CCAMERA::SetCurWindowSize ( const wxSize &  aSize)

SetCurWindowSize - update the windows size of the camera.

Parameters
aSize
Returns
true if the windows size changed since last time

Definition at line 452 of file ccamera.cpp.

453 {
454  const SFVEC2I newSize = SFVEC2I( aSize.x, aSize.y );
455 
456  if( m_windowSize != newSize )
457  {
458  m_windowSize = newSize;
460 
461  return true;
462  }
463 
464  return false;
465 }
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
void rebuildProjection()
Definition: ccamera.cpp:163
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266

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 CCAMERA::SetInterpolateMode ( CAMERA_INTERPOLATION  aInterpolateMode)
inline

Definition at line 200 of file ccamera.h.

201  {
202  m_interpolation_mode = aInterpolateMode;
203  }
CAMERA_INTERPOLATION m_interpolation_mode
Definition: ccamera.h:304

References m_interpolation_mode.

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

◆ SetLookAtPos()

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

Implemented in CTRACK_BALL.

Referenced by SetBoardLookAtPos().

◆ SetLookAtPos_T1()

void CCAMERA::SetLookAtPos_T1 ( const SFVEC3F aLookAtPos)
inline

Definition at line 128 of file ccamera.h.

128  {
129  m_lookat_pos_t1 = aLookAtPos;
130  }
SFVEC3F m_lookat_pos_t1
Definition: ccamera.h:297

References m_lookat_pos_t1.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ SetT0_and_T1_current_T()

void CCAMERA::SetT0_and_T1_current_T ( )
virtual

SetT0_and_T1_current_T - This will set T0 and T1 with the current values.

Reimplemented in CTRACK_BALL.

Definition at line 559 of file ccamera.cpp.

560 {
564  m_zoom_t0 = m_zoom;
565 
569  m_zoom_t1 = m_zoom;
570 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
SFVEC3F m_camera_pos_t1
Definition: ccamera.h:293
float m_zoom_t0
Definition: ccamera.h:260
SFVEC3F m_lookat_pos_t1
Definition: ccamera.h:297
SFVEC3F m_lookat_pos_t0
Definition: ccamera.h:296
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302
SFVEC3F m_camera_pos
Definition: ccamera.h:291
SFVEC3F m_camera_pos_t0
Definition: ccamera.h:292
float m_zoom_t1
Definition: ccamera.h:261
SFVEC3F m_rotate_aux_t0
Definition: ccamera.h:301
SFVEC3F m_lookat_pos
Definition: ccamera.h:295

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(), CTRACK_BALL::SetT0_and_T1_current_T(), and EDA_3D_CANVAS::SetView3D().

◆ ToggleProjection()

void CCAMERA::ToggleProjection ( )

◆ updateFrustum()

void CCAMERA::updateFrustum ( )
protected

Definition at line 262 of file ccamera.cpp.

263 {
264  // Update matrix and vectors
265  m_viewMatrixInverse = glm::inverse( m_viewMatrix );
266 
267  m_right = glm::normalize( SFVEC3F( m_viewMatrixInverse *
268  glm::vec4( SFVEC3F( 1.0, 0.0, 0.0 ), 0.0 ) ) );
269 
270  m_up = glm::normalize( SFVEC3F( m_viewMatrixInverse *
271  glm::vec4( SFVEC3F( 0.0, 1.0, 0.0 ), 0.0 ) ) );
272 
273  m_dir = glm::normalize( SFVEC3F( m_viewMatrixInverse *
274  glm::vec4( SFVEC3F( 0.0, 0.0, 1.0 ), 0.0 ) ) );
275 
276  m_pos = SFVEC3F( m_viewMatrixInverse * glm::vec4( SFVEC3F( 0.0, 0.0, 0.0 ), 1.0 ) );
277 
278 
279  /*
280  * Frustum is a implementation based on a tutorial by
281  * http://www.lighthouse3d.com/tutorials/view-frustum-culling/
282  */
283 
284  // compute the centers of the near and far planes
287 
288  // compute the 4 corners of the frustum on the near plane
293 
294  // compute the 4 corners of the frustum on the far plane
299 
300  if ( (m_windowSize.x > 0) &&
301  (m_windowSize.y > 0) )
302  {
303  // Reserve size for precalc values
304  m_right_nX.resize( m_windowSize.x + 1 );
305  m_up_nY.resize( m_windowSize.y + 1 );
306 
307  // Precalc X values for camera -> ray generation
308  const SFVEC3F right_nw = m_right * m_frustum.nw;
309 
310  for( unsigned int x = 0; x < ((unsigned int)m_windowSize.x + 1); ++x )
311  m_right_nX[x] = right_nw * m_scr_nX[x];
312 
313  // Precalc Y values for camera -> ray generation
314  const SFVEC3F up_nh = m_up * m_frustum.nh;
315 
316  for( unsigned int y = 0; y < ((unsigned int)m_windowSize.y + 1); ++y )
317  m_up_nY[y] = up_nh * m_scr_nY[y];
318  }
319 }
SFVEC3F fc
Definition: ccamera.h:51
SFVEC3F m_dir
Definition: ccamera.h:285
SFVEC3F ftl
Far Top Left.
Definition: ccamera.h:56
SFVEC3F ntl
Near Top Left.
Definition: ccamera.h:52
float farD
Definition: ccamera.h:60
std::vector< SFVEC3F > m_up_nY
Definition: ccamera.h:318
float nearD
Definition: ccamera.h:60
glm::mat4 m_viewMatrixInverse
Definition: ccamera.h:276
float nw
Definition: ccamera.h:61
std::vector< float > m_scr_nY
Definition: ccamera.h:311
std::vector< float > m_scr_nX
Precalc values array used to calc ray for each pixel (constant for the same window size)
Definition: ccamera.h:310
SFVEC3F fbr
Far Bottom Right.
Definition: ccamera.h:59
float fw
Definition: ccamera.h:61
SFVEC3F nbr
Near Bottom Right.
Definition: ccamera.h:55
SFVEC3F fbl
Far Bottom Left.
Definition: ccamera.h:58
SFVEC3F m_right
Definition: ccamera.h:283
SFVEC3F m_pos
Definition: ccamera.h:286
SFVEC3F m_up
Definition: ccamera.h:284
SFVEC3F nbl
Near Bottom Left.
Definition: ccamera.h:54
SFVEC3F ntr
Near Top Right.
Definition: ccamera.h:53
FRUSTUM m_frustum
Definition: ccamera.h:281
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: ccamera.h:317
SFVEC3F nc
Definition: ccamera.h:50
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266
SFVEC3F ftr
Far Top Right.
Definition: ccamera.h:57
float fh
Definition: ccamera.h:61
float nh
Definition: ccamera.h:61
glm::mat4 m_viewMatrix
Definition: ccamera.h:275

References FRUSTUM::farD, FRUSTUM::fbl, FRUSTUM::fbr, FRUSTUM::fc, FRUSTUM::fh, FRUSTUM::ftl, FRUSTUM::ftr, 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, FRUSTUM::nbl, FRUSTUM::nbr, FRUSTUM::nc, FRUSTUM::nearD, FRUSTUM::nh, FRUSTUM::ntl, FRUSTUM::ntr, and FRUSTUM::nw.

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

◆ updateRotationMatrix()

void CCAMERA::updateRotationMatrix ( )
protected

Definition at line 133 of file ccamera.cpp.

134 {
135  m_rotationMatrixAux = glm::rotate( glm::mat4( 1.0f ),
136  m_rotate_aux.x,
137  SFVEC3F( 1.0f, 0.0f, 0.0f ) );
139 
141  m_rotate_aux.y,
142  SFVEC3F( 0.0f, 1.0f, 0.0f ) );
144 
146  m_rotate_aux.z,
147  SFVEC3F( 0.0f, 0.0f, 1.0f ) );
149 
150  m_parametersChanged = true;
151 
153  updateFrustum();
154 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: ccamera.h:324
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
void updateFrustum()
Definition: ccamera.cpp:262
void updateViewMatrix()
Definition: ccamera.cpp:125
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
void normalise2PI(float &aAngle)
Definition: ccamera.cpp:35
glm::mat4 m_rotationMatrixAux
Definition: ccamera.h:274

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

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

◆ updateViewMatrix()

void CCAMERA::updateViewMatrix ( )
protected

Definition at line 125 of file ccamera.cpp.

126 {
127  m_viewMatrix = glm::translate( glm::mat4( 1.0f ), m_camera_pos ) *
129  glm::translate( glm::mat4( 1.0f ), -m_lookat_pos );
130 }
glm::mat4 m_rotationMatrix
Definition: ccamera.h:273
SFVEC3F m_camera_pos
Definition: ccamera.h:291
glm::mat4 m_rotationMatrixAux
Definition: ccamera.h:274
glm::mat4 m_viewMatrix
Definition: ccamera.h:275
SFVEC3F m_lookat_pos
Definition: ccamera.h:295

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

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

◆ Zoom()

bool CCAMERA::Zoom ( float  aFactor)

Definition at line 478 of file ccamera.cpp.

479 {
480  if ( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 ) || aFactor == 1 )
481  return false;
482 
483  m_zoom /= aFactor;
484  if( m_zoom <= MIN_ZOOM )
485  m_zoom = MIN_ZOOM;
486  if( m_zoom >= MAX_ZOOM )
487  m_zoom = MAX_ZOOM;
488 
490 
493 
494  return true;
495 }
#define MAX_ZOOM
Definition: ccamera.cpp:54
void updateViewMatrix()
Definition: ccamera.cpp:125
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259
SFVEC3F m_camera_pos_init
Definition: ccamera.h:290
SFVEC3F m_camera_pos
Definition: ccamera.h:291
void rebuildProjection()
Definition: ccamera.cpp:163
#define MIN_ZOOM
Definition: ccamera.cpp:53

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 CCAMERA::Zoom_T1 ( float  aFactor)

Definition at line 497 of file ccamera.cpp.

498 {
499  if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 ) || aFactor == 1 )
500  return false;
501 
502  m_zoom_t1 = m_zoom / aFactor;
503  if (m_zoom_t1 < MIN_ZOOM )
505  if (m_zoom_t1 > MAX_ZOOM )
507 
509 
510  return true;
511 }
#define MAX_ZOOM
Definition: ccamera.cpp:54
SFVEC3F m_camera_pos_t1
Definition: ccamera.h:293
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259
SFVEC3F m_camera_pos_init
Definition: ccamera.h:290
#define MIN_ZOOM
Definition: ccamera.cpp:53
float m_zoom_t1
Definition: ccamera.h:261

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 CCAMERA::ZoomGet ( ) const

Definition at line 514 of file ccamera.cpp.

515 {
516  return m_zoom;
517 }
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259

References m_zoom.

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

◆ ZoomReset()

void CCAMERA::ZoomReset ( )

Definition at line 468 of file ccamera.cpp.

469 {
470  m_zoom = 1.0f;
471 
473 
476 }
void updateViewMatrix()
Definition: ccamera.cpp:125
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259
SFVEC3F m_camera_pos_init
Definition: ccamera.h:290
SFVEC3F m_camera_pos
Definition: ccamera.h:291
void rebuildProjection()
Definition: ccamera.cpp:163

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

Member Data Documentation

◆ m_board_lookat_pos_init

SFVEC3F CCAMERA::m_board_lookat_pos_init
protected

Default boardlookat position (the board center)

Definition at line 298 of file ccamera.h.

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

◆ m_camera_pos

◆ m_camera_pos_init

SFVEC3F CCAMERA::m_camera_pos_init
protected

Definition at line 290 of file ccamera.h.

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

◆ m_camera_pos_t0

SFVEC3F CCAMERA::m_camera_pos_t0
protected

Definition at line 292 of file ccamera.h.

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

◆ m_camera_pos_t1

SFVEC3F CCAMERA::m_camera_pos_t1
protected

◆ m_dir

SFVEC3F CCAMERA::m_dir
protected

Definition at line 285 of file ccamera.h.

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

◆ m_focalLen

SFVEC2F CCAMERA::m_focalLen
protected

Definition at line 288 of file ccamera.h.

Referenced by GetFocalLen(), and rebuildProjection().

◆ m_frustum

FRUSTUM CCAMERA::m_frustum
protected

Definition at line 281 of file ccamera.h.

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

◆ m_interpolation_mode

CAMERA_INTERPOLATION CCAMERA::m_interpolation_mode
protected

Definition at line 304 of file ccamera.h.

Referenced by CCAMERA(), CTRACK_BALL::Interpolate(), and SetInterpolateMode().

◆ m_lastPosition

wxPoint CCAMERA::m_lastPosition
protected

The last mouse position in the screen.

Definition at line 271 of file ccamera.h.

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

◆ m_logTrace

const wxChar * CCAMERA::m_logTrace = wxT( "KI_TRACE_CCAMERA" )
staticprotected

Trace mask used to enable or disable the trace output of this class.

The debug output can be turned on by setting the WXTRACE environment variable to "KI_TRACE_CCAMERA". See the wxWidgets documentation on wxLogTrace for more information.

Definition at line 332 of file ccamera.h.

Referenced by CCAMERA(), and CTRACK_BALL::CTRACK_BALL().

◆ m_lookat_pos

SFVEC3F CCAMERA::m_lookat_pos
protected

◆ m_lookat_pos_t0

SFVEC3F CCAMERA::m_lookat_pos_t0
protected

Definition at line 296 of file ccamera.h.

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

◆ m_lookat_pos_t1

SFVEC3F CCAMERA::m_lookat_pos_t1
protected

◆ m_parametersChanged

bool CCAMERA::m_parametersChanged
protected

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

Definition at line 324 of file ccamera.h.

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

◆ m_pos

SFVEC3F CCAMERA::m_pos
protected

Definition at line 286 of file ccamera.h.

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

◆ m_projectionMatrix

glm::mat4 CCAMERA::m_projectionMatrix
protected

Definition at line 277 of file ccamera.h.

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

◆ m_projectionMatrixInv

glm::mat4 CCAMERA::m_projectionMatrixInv
protected

Definition at line 278 of file ccamera.h.

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

◆ m_projectionType

PROJECTION_TYPE CCAMERA::m_projectionType
protected

◆ m_range_scale

float CCAMERA::m_range_scale
protected

m_range_scale - the nominal range expected to be used in the camera.

It will be used to initialize the Z position

Definition at line 254 of file ccamera.h.

Referenced by CCAMERA().

◆ m_right

SFVEC3F CCAMERA::m_right
protected

Definition at line 283 of file ccamera.h.

Referenced by GetRight(), and updateFrustum().

◆ m_right_nX

std::vector< SFVEC3F > CCAMERA::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 317 of file ccamera.h.

Referenced by MakeRay(), and updateFrustum().

◆ m_rotate_aux

SFVEC3F CCAMERA::m_rotate_aux
protected

Stores the rotation angle auxiliar.

Definition at line 300 of file ccamera.h.

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

◆ m_rotate_aux_t0

SFVEC3F CCAMERA::m_rotate_aux_t0
protected

Definition at line 301 of file ccamera.h.

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

◆ m_rotate_aux_t1

SFVEC3F CCAMERA::m_rotate_aux_t1
protected

◆ m_rotationMatrix

glm::mat4 CCAMERA::m_rotationMatrix
protected

◆ m_rotationMatrixAux

glm::mat4 CCAMERA::m_rotationMatrixAux
protected

Definition at line 274 of file ccamera.h.

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

◆ m_scr_nX

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

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

Definition at line 310 of file ccamera.h.

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

◆ m_scr_nY

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

Definition at line 311 of file ccamera.h.

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

◆ m_up

SFVEC3F CCAMERA::m_up
protected

Definition at line 284 of file ccamera.h.

Referenced by GetUp(), and updateFrustum().

◆ m_up_nY

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

Definition at line 318 of file ccamera.h.

Referenced by MakeRay(), and updateFrustum().

◆ m_viewMatrix

glm::mat4 CCAMERA::m_viewMatrix
protected

Definition at line 275 of file ccamera.h.

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

◆ m_viewMatrixInverse

glm::mat4 CCAMERA::m_viewMatrixInverse
protected

Definition at line 276 of file ccamera.h.

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

◆ m_windowSize

SFVEC2I CCAMERA::m_windowSize
protected

The window size that this camera is working.

Definition at line 266 of file ccamera.h.

Referenced by CCAMERA(), CTRACK_BALL::Drag(), MakeRay(), MakeRayAtCurrrentMousePosition(), CTRACK_BALL::Pan(), rebuildProjection(), SetCurWindowSize(), and updateFrustum().

◆ m_zoom

float CCAMERA::m_zoom
protected

3D zoom value (Min 0.0 ...

Max 1.0)

Definition at line 259 of file ccamera.h.

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

◆ m_zoom_t0

float CCAMERA::m_zoom_t0
protected

Definition at line 260 of file ccamera.h.

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

◆ m_zoom_t1

float CCAMERA::m_zoom_t1
protected

Definition at line 261 of file ccamera.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: