KiCad PCB EDA Suite
CTRACK_BALL Class Reference

#include <ctrack_ball.h>

Inheritance diagram for CTRACK_BALL:
CCAMERA

Public Member Functions

 CTRACK_BALL (float aRangeScale)
 
virtual ~CTRACK_BALL ()
 
void Drag (const wxPoint &aNewMousePosition) override
 Calculate a new mouse drag position. More...
 
void Pan (const wxPoint &aNewMousePosition) override
 
void Pan (const SFVEC3F &aDeltaOffsetInc) override
 
void Pan_T1 (const SFVEC3F &aDeltaOffsetInc) override
 
void SetLookAtPos (const SFVEC3F &aLookAtPos) override
 
void Reset () override
 Reset the camera to initial state. More...
 
void Reset_T1 () override
 
void SetT0_and_T1_current_T () override
 SetT0_and_T1_current_T - This will set T0 and T1 with the current values. More...
 
void Interpolate (float t) override
 Interpolate - It will update the matrix to interpolate between T0 and T1 values. More...
 
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)
 
void SetLookAtPos_T1 (const SFVEC3F &aLookAtPos)
 
const SFVEC3FGetLookAtPos_T1 () const
 
const SFVEC3FGetCameraPos () const
 
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)
 
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...
 

Private Attributes

double m_quat [4]
 quarternion of the trackball More...
 
double m_quat_t0 [4]
 
double m_quat_t1 [4]
 

Detailed Description

Definition at line 36 of file ctrack_ball.h.

Constructor & Destructor Documentation

◆ CTRACK_BALL()

CTRACK_BALL::CTRACK_BALL ( float  aRangeScale)
explicit

Definition at line 37 of file ctrack_ball.cpp.

37  : CCAMERA( aRangeScale )
38 {
39  wxLogTrace( m_logTrace, wxT( "CTRACK_BALL::CTRACK_BALL" ) );
40 
41  memset( m_quat, 0, sizeof( m_quat ) );
42  memset( m_quat_t0, 0, sizeof( m_quat_t0 ) );
43  memset( m_quat_t1, 0, sizeof( m_quat_t1 ) );
44 
45  trackball( m_quat, 0.0, 0.0, 0.0, 0.0 );
46  trackball( m_quat_t0, 0.0, 0.0, 0.0, 0.0 );
47  trackball( m_quat_t1, 0.0, 0.0, 0.0, 0.0 );
48 }
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Definition: ccamera.h:332
CCAMERA(float aRangeScale)
CCAMERA initialize a camera.
Definition: ccamera.cpp:56
double m_quat[4]
quarternion of the trackball
Definition: ctrack_ball.h:70
void trackball(double q[4], double p1x, double p1y, double p2x, double p2y)
Definition: trackball.cpp:155
double m_quat_t0[4]
Definition: ctrack_ball.h:71
double m_quat_t1[4]
Definition: ctrack_ball.h:72

References CCAMERA::m_logTrace, m_quat, m_quat_t0, m_quat_t1, and trackball().

◆ ~CTRACK_BALL()

virtual CTRACK_BALL::~CTRACK_BALL ( )
inlinevirtual

Definition at line 43 of file ctrack_ball.h.

44  {
45  }

Member Function Documentation

◆ Drag()

void CTRACK_BALL::Drag ( const wxPoint aNewMousePosition)
overridevirtual

Calculate a new mouse drag position.

Implements CCAMERA.

Definition at line 51 of file ctrack_ball.cpp.

52 {
53  m_parametersChanged = true;
54 
55  double spin_quat[4];
56 
57  // "Pass the x and y coordinates of the last and current positions of
58  // the mouse, scaled so they are from (-1.0 ... 1.0)."
59  const float zoom = 1.0f;
60 
61  trackball( spin_quat,
62  zoom * (2.0 * m_lastPosition.x - m_windowSize.x) / m_windowSize.x,
63  zoom * (m_windowSize.y - 2.0 * m_lastPosition.y) / m_windowSize.y,
64  zoom * (2.0 * aNewMousePosition.x - m_windowSize.x) / m_windowSize.x,
65  zoom * ( m_windowSize.y - 2.0 * aNewMousePosition.y ) / m_windowSize.y);
66 
67  add_quats( spin_quat, m_quat, m_quat );
68 
69  float rotationMatrix[4][4];
70 
71  build_rotmatrix( rotationMatrix, m_quat );
72 
73  m_rotationMatrix = glm::make_mat4( &rotationMatrix[0][0] );
74 
76 
77  updateFrustum();
78 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: ccamera.h:324
void build_rotmatrix(float m[4][4], double q[4])
Definition: trackball.cpp:306
double m_quat[4]
quarternion of the trackball
Definition: ctrack_ball.h:70
void updateFrustum()
Definition: ccamera.cpp:263
void updateViewMatrix()
Definition: ccamera.cpp:126
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: ccamera.h:271
void trackball(double q[4], double p1x, double p1y, double p2x, double p2y)
Definition: trackball.cpp:155
glm::mat4 m_rotationMatrix
Definition: ccamera.h:273
void add_quats(double q1[4], double q2[4], double dest[4])
Definition: trackball.cpp:249
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266

References add_quats(), build_rotmatrix(), CCAMERA::m_lastPosition, CCAMERA::m_parametersChanged, m_quat, CCAMERA::m_rotationMatrix, CCAMERA::m_windowSize, trackball(), CCAMERA::updateFrustum(), CCAMERA::updateViewMatrix(), wxPoint::x, and wxPoint::y.

Referenced by C3D_MODEL_VIEWER::OnMouseMove().

◆ GetCameraPos()

const SFVEC3F& CCAMERA::GetCameraPos ( ) const
inlineinherited

Definition at line 134 of file ccamera.h.

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

References CCAMERA::m_camera_pos.

Referenced by EDA_3D_CANVAS::DisplayStatus().

◆ GetDir()

const SFVEC3F& CCAMERA::GetDir ( ) const
inlineinherited

Definition at line 112 of file ccamera.h.

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

References CCAMERA::m_dir.

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

◆ GetFar()

float CCAMERA::GetFar ( ) const
inlineinherited

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 CCAMERA::m_frustum.

◆ GetFocalLen()

const SFVEC2F& CCAMERA::GetFocalLen ( ) const
inlineinherited

Definition at line 114 of file ccamera.h.

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

References CCAMERA::m_focalLen.

◆ GetLookAtPos_T1()

const SFVEC3F& CCAMERA::GetLookAtPos_T1 ( ) const
inlineinherited

Definition at line 132 of file ccamera.h.

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

References CCAMERA::m_lookat_pos_t1.

Referenced by EDA_3D_CANVAS::render_pivot().

◆ GetNear()

float CCAMERA::GetNear ( ) const
inlineinherited

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 CCAMERA::m_frustum, and FRUSTUM::nearD.

◆ GetPos()

const SFVEC3F& CCAMERA::GetPos ( ) const
inlineinherited

Definition at line 113 of file ccamera.h.

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

References CCAMERA::m_pos.

Referenced by C3D_RENDER_OGL_LEGACY::Redraw().

◆ GetProjection()

PROJECTION_TYPE CCAMERA::GetProjection ( )
inlineinherited

Definition at line 164 of file ccamera.h.

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

References CCAMERA::m_projectionType.

Referenced by EDA_3D_VIEWER::SyncToolbars().

◆ GetProjectionMatrix()

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

Definition at line 389 of file ccamera.cpp.

390 {
391  return m_projectionMatrix;
392 }
glm::mat4 m_projectionMatrix
Definition: ccamera.h:277

References CCAMERA::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
inherited

Definition at line 395 of file ccamera.cpp.

396 {
397  return m_projectionMatrixInv;
398 }
glm::mat4 m_projectionMatrixInv
Definition: ccamera.h:278

References CCAMERA::m_projectionMatrixInv.

◆ GetRight()

const SFVEC3F& CCAMERA::GetRight ( ) const
inlineinherited

Definition at line 110 of file ccamera.h.

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

References CCAMERA::m_right.

◆ GetRotationMatrix()

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

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

Returns
the rotation matrix of the camera

Definition at line 158 of file ccamera.cpp.

159 {
161 }
glm::mat4 m_rotationMatrix
Definition: ccamera.h:273
glm::mat4 m_rotationMatrixAux
Definition: ccamera.h:274

References CCAMERA::m_rotationMatrix, and CCAMERA::m_rotationMatrixAux.

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

◆ GetUp()

const SFVEC3F& CCAMERA::GetUp ( ) const
inlineinherited

Definition at line 111 of file ccamera.h.

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

References CCAMERA::m_up.

◆ GetViewMatrix()

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

Definition at line 419 of file ccamera.cpp.

420 {
421  return m_viewMatrix;
422 }
glm::mat4 m_viewMatrix
Definition: ccamera.h:275

References CCAMERA::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
inherited

Definition at line 425 of file ccamera.cpp.

426 {
427  return m_viewMatrixInverse;
428 }
glm::mat4 m_viewMatrixInverse
Definition: ccamera.h:276

References CCAMERA::m_viewMatrixInverse.

◆ Interpolate()

void CTRACK_BALL::Interpolate ( float  t)
overridevirtual

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 from CCAMERA.

Definition at line 163 of file ctrack_ball.cpp.

164 {
165  wxASSERT( t >= 0.0f );
166 
167  // Limit t o 1.0
168  t = (t > 1.0f)?1.0f:t;
169 
170  switch( m_interpolation_mode )
171  {
173  t = BezierBlend( t );
174  break;
175 
177  t = QuadricEasingInOut( t );
178  break;
179 
181  default:
182  break;
183  }
184 
185  const float t0 = 1.0f - t;
186 
187  m_quat[0] = m_quat_t0[0] * t0 + m_quat_t1[0] * t;
188  m_quat[1] = m_quat_t0[1] * t0 + m_quat_t1[1] * t;
189  m_quat[2] = m_quat_t0[2] * t0 + m_quat_t1[2] * t;
190  m_quat[3] = m_quat_t0[3] * t0 + m_quat_t1[3] * t;
191 
192  float rotationMatrix[4][4];
193 
194  build_rotmatrix( rotationMatrix, m_quat );
195 
196  m_rotationMatrix = glm::make_mat4( &rotationMatrix[0][0] );
197 
199 }
void build_rotmatrix(float m[4][4], double q[4])
Definition: trackball.cpp:306
float BezierBlend(float t)
Definition: 3d_math.h:188
double m_quat[4]
quarternion of the trackball
Definition: ctrack_ball.h:70
float QuadricEasingInOut(float t)
Definition: 3d_math.h:172
virtual void Interpolate(float t)
Interpolate - It will update the matrix to interpolate between T0 and T1 values.
Definition: ccamera.cpp:569
glm::mat4 m_rotationMatrix
Definition: ccamera.h:273
double m_quat_t0[4]
Definition: ctrack_ball.h:71
double m_quat_t1[4]
Definition: ctrack_ball.h:72
CAMERA_INTERPOLATION m_interpolation_mode
Definition: ccamera.h:304

References BEZIER, BezierBlend(), build_rotmatrix(), EASING_IN_OUT, CCAMERA::Interpolate(), LINEAR, CCAMERA::m_interpolation_mode, m_quat, m_quat_t0, m_quat_t1, CCAMERA::m_rotationMatrix, and QuadricEasingInOut().

◆ MakeRay() [1/2]

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

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

326 {
327  wxASSERT( aWindowPos.x < m_windowSize.x );
328  wxASSERT( aWindowPos.y < m_windowSize.y );
329 
330  const SFVEC3F up_plus_right = m_up_nY[aWindowPos.y] +
331  m_right_nX[aWindowPos.x];
332 
333  switch( m_projectionType )
334  {
335  default:
337  aOutOrigin = up_plus_right + m_frustum.nc;
338  aOutDirection = glm::normalize( aOutOrigin - m_pos );
339  break;
340 
342  aOutOrigin = up_plus_right * 0.5f + m_frustum.nc;
343  aOutDirection = -m_dir + SFVEC3F( FLT_EPSILON );
344  break;
345  }
346 }
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 CCAMERA::m_dir, CCAMERA::m_frustum, CCAMERA::m_pos, CCAMERA::m_projectionType, CCAMERA::m_right_nX, CCAMERA::m_up_nY, CCAMERA::m_windowSize, FRUSTUM::nc, ORTHO, and PERSPECTIVE.

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

◆ MakeRay() [2/2]

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

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

350 {
351  wxASSERT( aWindowPos.x < (float)m_windowSize.x );
352  wxASSERT( aWindowPos.y < (float)m_windowSize.y );
353 
354  const SFVEC2F floorWinPos_f = glm::floor( aWindowPos );
355  const SFVEC2I floorWinPos_i = (SFVEC2I)floorWinPos_f;
356  const SFVEC2F relativeWinPos = aWindowPos - floorWinPos_f;
357 
358  // Note: size of vectors m_up and m_right are m_windowSize + 1
359  const SFVEC3F up_plus_right = m_up_nY[floorWinPos_i.y] * (1.0f - relativeWinPos.y) +
360  m_up_nY[floorWinPos_i.y + 1] * relativeWinPos.y +
361  m_right_nX[floorWinPos_i.x] * (1.0f - relativeWinPos.x) +
362  m_right_nX[floorWinPos_i.x + 1] * relativeWinPos.x;
363 
364  switch( m_projectionType )
365  {
366  default:
368  aOutOrigin = up_plus_right + m_frustum.nc;
369  aOutDirection = glm::normalize( aOutOrigin - m_pos );
370  break;
371 
373  aOutOrigin = up_plus_right * 0.5f + m_frustum.nc;
374  aOutDirection = -m_dir + SFVEC3F( FLT_EPSILON );
375  break;
376  }
377 }
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 CCAMERA::m_dir, CCAMERA::m_frustum, CCAMERA::m_pos, CCAMERA::m_projectionType, CCAMERA::m_right_nX, CCAMERA::m_up_nY, CCAMERA::m_windowSize, FRUSTUM::nc, ORTHO, and PERSPECTIVE.

◆ MakeRayAtCurrrentMousePosition()

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

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

Parameters
aOutOriginout origin position of the ray
aOutDirectionout direction

Definition at line 380 of file ccamera.cpp.

382 {
385  aOutOrigin, aOutDirection );
386 }
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:323

References CCAMERA::m_lastPosition, CCAMERA::m_windowSize, CCAMERA::MakeRay(), wxPoint::x, and wxPoint::y.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ Pan() [1/2]

void CTRACK_BALL::Pan ( const wxPoint aNewMousePosition)
overridevirtual

Implements CCAMERA.

Definition at line 95 of file ctrack_ball.cpp.

96 {
97  m_parametersChanged = true;
98 
100  {
101  // With the ortographic projection, there is just a zoom factor
102  const float panFactor = m_zoom / 37.5f; // Magic number from CCAMERA::rebuildProjection
103  m_camera_pos.x -= panFactor * ( m_lastPosition.x - aNewMousePosition.x );
104  m_camera_pos.y -= panFactor * ( aNewMousePosition.y - m_lastPosition.y );
105  }
106  else // PROJECTION_TYPE::PERSPECTIVE
107  {
108  // Unproject the coordinates using the precomputed frustum tangent (zoom level dependent)
109  const float panFactor = -m_camera_pos.z * m_frustum.tang * 2;
110  m_camera_pos.x -= panFactor * m_frustum.ratio * ( m_lastPosition.x - aNewMousePosition.x ) / m_windowSize.x;
111  m_camera_pos.y -= panFactor * ( aNewMousePosition.y - m_lastPosition.y ) / m_windowSize.y;
112  }
113 
115  updateFrustum();
116 }
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:263
float tang
Definition: ccamera.h:60
void updateViewMatrix()
Definition: ccamera.cpp:126
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: ccamera.h:271
FRUSTUM m_frustum
Definition: ccamera.h:281
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259
SFVEC3F m_camera_pos
Definition: ccamera.h:291
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266
float ratio
Definition: ccamera.h:60
PROJECTION_TYPE m_projectionType
Definition: ccamera.h:279

References CCAMERA::m_camera_pos, CCAMERA::m_frustum, CCAMERA::m_lastPosition, CCAMERA::m_parametersChanged, CCAMERA::m_projectionType, CCAMERA::m_windowSize, CCAMERA::m_zoom, ORTHO, FRUSTUM::ratio, FRUSTUM::tang, CCAMERA::updateFrustum(), CCAMERA::updateViewMatrix(), wxPoint::x, and wxPoint::y.

◆ Pan() [2/2]

void CTRACK_BALL::Pan ( const SFVEC3F aDeltaOffsetInc)
overridevirtual

Implements CCAMERA.

Definition at line 119 of file ctrack_ball.cpp.

120 {
121  m_parametersChanged = true;
122 
123  m_camera_pos += aDeltaOffsetInc;
124 
126  updateFrustum();
127 }
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:263
void updateViewMatrix()
Definition: ccamera.cpp:126
SFVEC3F m_camera_pos
Definition: ccamera.h:291

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

◆ Pan_T1()

void CTRACK_BALL::Pan_T1 ( const SFVEC3F aDeltaOffsetInc)
overridevirtual

Implements CCAMERA.

Definition at line 130 of file ctrack_ball.cpp.

131 {
132  m_camera_pos_t1 = m_camera_pos + aDeltaOffsetInc;
133 }
SFVEC3F m_camera_pos_t1
Definition: ccamera.h:293
SFVEC3F m_camera_pos
Definition: ccamera.h:291

References CCAMERA::m_camera_pos, and CCAMERA::m_camera_pos_t1.

◆ ParametersChanged()

bool CCAMERA::ParametersChanged ( )
inherited

Function ParametersChanged.

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

Definition at line 587 of file ccamera.cpp.

588 {
589  const bool parametersChanged = m_parametersChanged;
590 
591  m_parametersChanged = false;
592 
593  return parametersChanged;
594 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: ccamera.h:324

References CCAMERA::m_parametersChanged.

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

◆ ParametersChangedQuery()

bool CCAMERA::ParametersChangedQuery ( ) const
inlineinherited

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 CCAMERA::m_parametersChanged.

◆ rebuildProjection()

void CCAMERA::rebuildProjection ( )
protectedinherited

Definition at line 164 of file ccamera.cpp.

165 {
166  if( (m_windowSize.x == 0) ||
167  (m_windowSize.y == 0) )
168  return;
169 
170  m_frustum.ratio = (float) m_windowSize.x / (float)m_windowSize.y;
171 
172  // Consider that we can render double the length multiplied by the 2/sqrt(2)
173  //
174  m_frustum.farD = glm::length( m_camera_pos_init ) * 2.0f * ( 2.0f * sqrtf( 2.0f ) );
175 
176  switch( m_projectionType )
177  {
178  default:
180 
181  m_frustum.nearD = 0.10f;
182 
183  // Ratio width / height of the window display
184  m_frustum.angle = 45.0f * m_zoom;
185 
186 
187  m_projectionMatrix = glm::perspective( glm::radians( m_frustum.angle ),
190  m_frustum.farD );
191 
192  m_projectionMatrixInv = glm::inverse( m_projectionMatrix );
193 
194  m_frustum.tang = glm::tan( glm::radians( m_frustum.angle ) * 0.5f );
195 
196  m_focalLen.x = ( (float)m_windowSize.y / (float)m_windowSize.x ) / m_frustum.tang;
197  m_focalLen.y = 1.0f / m_frustum.tang;
198 
203  break;
204 
206 
207  m_frustum.nearD = -m_frustum.farD; // Use a symmetrical clip plane for ortho projection
208 
209  // This formula was found by trial and error
210  const float orthoReductionFactor = glm::length( m_camera_pos_init ) *
211  m_zoom * m_zoom * 0.5f;
212 
213  // Initialize Projection Matrix for Ortographic View
214  m_projectionMatrix = glm::ortho( -m_frustum.ratio * orthoReductionFactor,
215  m_frustum.ratio * orthoReductionFactor,
216  -orthoReductionFactor,
217  orthoReductionFactor,
219 
220  m_projectionMatrixInv = glm::inverse( m_projectionMatrix );
221 
222  m_frustum.nw = orthoReductionFactor * 2.0f * m_frustum.ratio;
223  m_frustum.nh = orthoReductionFactor * 2.0f;
226 
227  break;
228  }
229 
230  if ( (m_windowSize.x > 0) &&
231  (m_windowSize.y > 0) )
232  {
233  m_scr_nX.resize( m_windowSize.x + 1 );
234  m_scr_nY.resize( m_windowSize.y + 1 );
235 
236  // Precalc X values for camera -> ray generation
237  for( unsigned int x = 0; x < (unsigned int)m_windowSize.x + 1; ++x )
238  {
239  // Converts 0.0 .. 1.0
240  const float xNormalizedDeviceCoordinates = ( ( (float)x + 0.5f ) /
241  (m_windowSize.x - 0.0f) );
242 
243  // Converts -1.0 .. 1.0
244  m_scr_nX[x] = 2.0f * xNormalizedDeviceCoordinates - 1.0f;
245  }
246 
247  // Precalc Y values for camera -> ray generation
248  for( unsigned int y = 0; y < (unsigned int)m_windowSize.y + 1 ; ++y )
249  {
250  // Converts 0.0 .. 1.0
251  const float yNormalizedDeviceCoordinates = ( ( (float)y + 0.5f ) /
252  (m_windowSize.y - 0.0f) );
253 
254  // Converts -1.0 .. 1.0
255  m_scr_nY[y] = 2.0f * yNormalizedDeviceCoordinates - 1.0f;
256  }
257 
258  updateFrustum();
259  }
260 }
float farD
Definition: ccamera.h:60
void updateFrustum()
Definition: ccamera.cpp:263
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, CCAMERA::m_camera_pos_init, CCAMERA::m_focalLen, CCAMERA::m_frustum, CCAMERA::m_projectionMatrix, CCAMERA::m_projectionMatrixInv, CCAMERA::m_projectionType, CCAMERA::m_scr_nX, CCAMERA::m_scr_nY, CCAMERA::m_windowSize, CCAMERA::m_zoom, FRUSTUM::nearD, FRUSTUM::nh, FRUSTUM::nw, ORTHO, PERSPECTIVE, FRUSTUM::ratio, FRUSTUM::tang, and CCAMERA::updateFrustum().

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

◆ Reset()

void CTRACK_BALL::Reset ( )
overridevirtual

Reset the camera to initial state.

Reimplemented from CCAMERA.

Definition at line 136 of file ctrack_ball.cpp.

137 {
138  CCAMERA::Reset();
139 
140  memset( m_quat, 0, sizeof( m_quat ) );
141  trackball( m_quat, 0.0, 0.0, 0.0, 0.0 );
142 }
virtual void Reset()
Reset the camera to initial state.
Definition: ccamera.cpp:71
double m_quat[4]
quarternion of the trackball
Definition: ctrack_ball.h:70
void trackball(double q[4], double p1x, double p1y, double p2x, double p2y)
Definition: trackball.cpp:155

References m_quat, CCAMERA::Reset(), and trackball().

◆ Reset_T1()

void CTRACK_BALL::Reset_T1 ( )
overridevirtual

Reimplemented from CCAMERA.

Definition at line 145 of file ctrack_ball.cpp.

146 {
148 
149  memset( m_quat_t1, 0, sizeof( m_quat_t1 ) );
150  trackball( m_quat_t1, 0.0, 0.0, 0.0, 0.0 );
151 }
void trackball(double q[4], double p1x, double p1y, double p2x, double p2y)
Definition: trackball.cpp:155
virtual void Reset_T1()
Definition: ccamera.cpp:103
double m_quat_t1[4]
Definition: ctrack_ball.h:72

References m_quat_t1, CCAMERA::Reset_T1(), and trackball().

◆ ResetXYpos()

void CCAMERA::ResetXYpos ( )
inherited

Definition at line 401 of file ccamera.cpp.

402 {
403  m_parametersChanged = true;
404  m_camera_pos.x = 0.0f;
405  m_camera_pos.y = 0.0f;
406 
408  updateFrustum();
409 }
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:263
void updateViewMatrix()
Definition: ccamera.cpp:126
SFVEC3F m_camera_pos
Definition: ccamera.h:291

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

◆ ResetXYpos_T1()

void CCAMERA::ResetXYpos_T1 ( )
inherited

Definition at line 412 of file ccamera.cpp.

413 {
414  m_camera_pos_t1.x = 0.0f;
415  m_camera_pos_t1.y = 0.0f;
416 }
SFVEC3F m_camera_pos_t1
Definition: ccamera.h:293

References CCAMERA::m_camera_pos_t1.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ RotateX()

void CCAMERA::RotateX ( float  aAngleInRadians)
inherited

Definition at line 516 of file ccamera.cpp.

517 {
518  m_rotate_aux.x += aAngleInRadians;
520 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
void updateRotationMatrix()
Definition: ccamera.cpp:134

References CCAMERA::m_rotate_aux, and CCAMERA::updateRotationMatrix().

Referenced by EDA_3D_VIEWER_CONTROL::RotateView().

◆ RotateX_T1()

void CCAMERA::RotateX_T1 ( float  aAngleInRadians)
inherited

Definition at line 537 of file ccamera.cpp.

538 {
539  m_rotate_aux_t1.x += aAngleInRadians;
540 }
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302

References CCAMERA::m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ RotateY()

void CCAMERA::RotateY ( float  aAngleInRadians)
inherited

Definition at line 523 of file ccamera.cpp.

524 {
525  m_rotate_aux.y += aAngleInRadians;
527 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
void updateRotationMatrix()
Definition: ccamera.cpp:134

References CCAMERA::m_rotate_aux, and CCAMERA::updateRotationMatrix().

Referenced by EDA_3D_VIEWER_CONTROL::RotateView().

◆ RotateY_T1()

void CCAMERA::RotateY_T1 ( float  aAngleInRadians)
inherited

Definition at line 543 of file ccamera.cpp.

544 {
545  m_rotate_aux_t1.y += aAngleInRadians;
546 }
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302

References CCAMERA::m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ RotateZ()

void CCAMERA::RotateZ ( float  aAngleInRadians)
inherited

Definition at line 530 of file ccamera.cpp.

531 {
532  m_rotate_aux.z += aAngleInRadians;
534 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliar.
Definition: ccamera.h:300
void updateRotationMatrix()
Definition: ccamera.cpp:134

References CCAMERA::m_rotate_aux, and CCAMERA::updateRotationMatrix().

Referenced by EDA_3D_VIEWER_CONTROL::RotateView().

◆ RotateZ_T1()

void CCAMERA::RotateZ_T1 ( float  aAngleInRadians)
inherited

Definition at line 549 of file ccamera.cpp.

550 {
551  m_rotate_aux_t1.z += aAngleInRadians;
552 }
SFVEC3F m_rotate_aux_t1
Definition: ccamera.h:302

References CCAMERA::m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ SetBoardLookAtPos()

void CCAMERA::SetBoardLookAtPos ( const SFVEC3F aBoardPos)
inlineinherited

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 CCAMERA::m_board_lookat_pos_init, and CCAMERA::SetLookAtPos().

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

◆ SetCurMousePosition()

void CCAMERA::SetCurMousePosition ( const wxPoint aPosition)
inherited

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

Definition at line 431 of file ccamera.cpp.

432 {
433  m_lastPosition = aNewMousePosition;
434 }
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: ccamera.h:271

References CCAMERA::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)
inherited

SetCurWindowSize - update the windows size of the camera.

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

Definition at line 448 of file ccamera.cpp.

449 {
450  const SFVEC2I newSize = SFVEC2I( aSize.x, aSize.y );
451 
452  if( m_windowSize != newSize )
453  {
454  m_windowSize = newSize;
456 
457  return true;
458  }
459 
460  return false;
461 }
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
void rebuildProjection()
Definition: ccamera.cpp:164
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: ccamera.h:266

References CCAMERA::m_windowSize, and CCAMERA::rebuildProjection().

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

◆ SetInterpolateMode()

void CCAMERA::SetInterpolateMode ( CAMERA_INTERPOLATION  aInterpolateMode)
inlineinherited

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 CCAMERA::m_interpolation_mode.

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

◆ SetLookAtPos()

void CTRACK_BALL::SetLookAtPos ( const SFVEC3F aLookAtPos)
overridevirtual

Implements CCAMERA.

Definition at line 81 of file ctrack_ball.cpp.

82 {
83  if( m_lookat_pos != aLookAtPos )
84  {
85  m_lookat_pos = aLookAtPos;
86 
88  updateFrustum();
89 
90  m_parametersChanged = true;
91  }
92 }
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:263
void updateViewMatrix()
Definition: ccamera.cpp:126
SFVEC3F m_lookat_pos
Definition: ccamera.h:295

References CCAMERA::m_lookat_pos, CCAMERA::m_parametersChanged, CCAMERA::updateFrustum(), and CCAMERA::updateViewMatrix().

◆ SetLookAtPos_T1()

void CCAMERA::SetLookAtPos_T1 ( const SFVEC3F aLookAtPos)
inlineinherited

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 CCAMERA::m_lookat_pos_t1.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ SetT0_and_T1_current_T()

void CTRACK_BALL::SetT0_and_T1_current_T ( )
overridevirtual

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

Reimplemented from CCAMERA.

Definition at line 154 of file ctrack_ball.cpp.

155 {
157 
158  memcpy( m_quat_t0, m_quat, sizeof( m_quat ) );
159  memcpy( m_quat_t1, m_quat, sizeof( m_quat ) );
160 }
virtual void SetT0_and_T1_current_T()
SetT0_and_T1_current_T - This will set T0 and T1 with the current values.
Definition: ccamera.cpp:555
double m_quat[4]
quarternion of the trackball
Definition: ctrack_ball.h:70
double m_quat_t0[4]
Definition: ctrack_ball.h:71
double m_quat_t1[4]
Definition: ctrack_ball.h:72

References m_quat, m_quat_t0, m_quat_t1, and CCAMERA::SetT0_and_T1_current_T().

◆ ToggleProjection()

void CCAMERA::ToggleProjection ( )
inherited

◆ updateFrustum()

void CCAMERA::updateFrustum ( )
protectedinherited

Definition at line 263 of file ccamera.cpp.

264 {
265  // Update matrix and vectors
266  m_viewMatrixInverse = glm::inverse( m_viewMatrix );
267 
268  m_right = glm::normalize( SFVEC3F( m_viewMatrixInverse *
269  glm::vec4( SFVEC3F( 1.0, 0.0, 0.0 ), 0.0 ) ) );
270 
271  m_up = glm::normalize( SFVEC3F( m_viewMatrixInverse *
272  glm::vec4( SFVEC3F( 0.0, 1.0, 0.0 ), 0.0 ) ) );
273 
274  m_dir = glm::normalize( SFVEC3F( m_viewMatrixInverse *
275  glm::vec4( SFVEC3F( 0.0, 0.0, 1.0 ), 0.0 ) ) );
276 
277  m_pos = SFVEC3F( m_viewMatrixInverse * glm::vec4( SFVEC3F( 0.0, 0.0, 0.0 ), 1.0 ) );
278 
279 
280  /*
281  * Frustum is a implementation based on a tutorial by
282  * http://www.lighthouse3d.com/tutorials/view-frustum-culling/
283  */
284 
285  // compute the centers of the near and far planes
288 
289  // compute the 4 corners of the frustum on the near plane
294 
295  // compute the 4 corners of the frustum on the far plane
300 
301  if ( (m_windowSize.x > 0) &&
302  (m_windowSize.y > 0) )
303  {
304  // Reserve size for precalc values
305  m_right_nX.resize( m_windowSize.x + 1 );
306  m_up_nY.resize( m_windowSize.y + 1 );
307 
308  // Precalc X values for camera -> ray generation
309  const SFVEC3F right_nw = m_right * m_frustum.nw;
310 
311  for( unsigned int x = 0; x < ((unsigned int)m_windowSize.x + 1); ++x )
312  m_right_nX[x] = right_nw * m_scr_nX[x];
313 
314  // Precalc Y values for camera -> ray generation
315  const SFVEC3F up_nh = m_up * m_frustum.nh;
316 
317  for( unsigned int y = 0; y < ((unsigned int)m_windowSize.y + 1); ++y )
318  m_up_nY[y] = up_nh * m_scr_nY[y];
319  }
320 }
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, CCAMERA::m_dir, CCAMERA::m_frustum, CCAMERA::m_pos, CCAMERA::m_right, CCAMERA::m_right_nX, CCAMERA::m_scr_nX, CCAMERA::m_scr_nY, CCAMERA::m_up, CCAMERA::m_up_nY, CCAMERA::m_viewMatrix, CCAMERA::m_viewMatrixInverse, CCAMERA::m_windowSize, FRUSTUM::nbl, FRUSTUM::nbr, FRUSTUM::nc, FRUSTUM::nearD, FRUSTUM::nh, FRUSTUM::ntl, FRUSTUM::ntr, and FRUSTUM::nw.

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

◆ updateRotationMatrix()

void CCAMERA::updateRotationMatrix ( )
protectedinherited

Definition at line 134 of file ccamera.cpp.

135 {
136  m_rotationMatrixAux = glm::rotate( glm::mat4( 1.0f ),
137  m_rotate_aux.x,
138  SFVEC3F( 1.0f, 0.0f, 0.0f ) );
140 
142  m_rotate_aux.y,
143  SFVEC3F( 0.0f, 1.0f, 0.0f ) );
145 
147  m_rotate_aux.z,
148  SFVEC3F( 0.0f, 0.0f, 1.0f ) );
150 
151  m_parametersChanged = true;
152 
154  updateFrustum();
155 }
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:263
void updateViewMatrix()
Definition: ccamera.cpp:126
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 CCAMERA::m_parametersChanged, CCAMERA::m_rotate_aux, CCAMERA::m_rotationMatrixAux, normalise2PI(), CCAMERA::updateFrustum(), and CCAMERA::updateViewMatrix().

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

◆ updateViewMatrix()

void CCAMERA::updateViewMatrix ( )
protectedinherited

Definition at line 126 of file ccamera.cpp.

127 {
128  m_viewMatrix = glm::translate( glm::mat4( 1.0f ), m_camera_pos ) *
130  glm::translate( glm::mat4( 1.0f ), -m_lookat_pos );
131 }
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 CCAMERA::m_camera_pos, CCAMERA::m_lookat_pos, CCAMERA::m_rotationMatrix, CCAMERA::m_rotationMatrixAux, and CCAMERA::m_viewMatrix.

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

◆ Zoom()

bool CCAMERA::Zoom ( float  aFactor)
inherited

Definition at line 474 of file ccamera.cpp.

475 {
476  if ( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 ) || aFactor == 1 )
477  return false;
478 
479  m_zoom /= aFactor;
480  if( m_zoom <= MIN_ZOOM )
481  m_zoom = MIN_ZOOM;
482  if( m_zoom >= MAX_ZOOM )
483  m_zoom = MAX_ZOOM;
484 
486 
489 
490  return true;
491 }
#define MAX_ZOOM
Definition: ccamera.cpp:54
void updateViewMatrix()
Definition: ccamera.cpp:126
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:164
#define MIN_ZOOM
Definition: ccamera.cpp:53

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

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

◆ Zoom_T1()

bool CCAMERA::Zoom_T1 ( float  aFactor)
inherited

Definition at line 493 of file ccamera.cpp.

494 {
495  if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 ) || aFactor == 1 )
496  return false;
497 
498  m_zoom_t1 = m_zoom / aFactor;
499  if (m_zoom_t1 < MIN_ZOOM )
501  if (m_zoom_t1 > MAX_ZOOM )
503 
505 
506  return true;
507 }
#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 CCAMERA::m_camera_pos_init, CCAMERA::m_camera_pos_t1, CCAMERA::m_zoom, CCAMERA::m_zoom_t1, MAX_ZOOM, and MIN_ZOOM.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ ZoomGet()

float CCAMERA::ZoomGet ( ) const
inherited

Definition at line 510 of file ccamera.cpp.

511 {
512  return m_zoom;
513 }
float m_zoom
3D zoom value (Min 0.0 ...
Definition: ccamera.h:259

References CCAMERA::m_zoom.

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

◆ ZoomReset()

void CCAMERA::ZoomReset ( )
inherited

Definition at line 464 of file ccamera.cpp.

465 {
466  m_zoom = 1.0f;
467 
469 
472 }
void updateViewMatrix()
Definition: ccamera.cpp:126
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:164

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

Member Data Documentation

◆ m_board_lookat_pos_init

SFVEC3F CCAMERA::m_board_lookat_pos_init
protectedinherited

Default boardlookat position (the board center)

Definition at line 298 of file ccamera.h.

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

◆ m_camera_pos

◆ m_camera_pos_init

SFVEC3F CCAMERA::m_camera_pos_init
protectedinherited

◆ m_camera_pos_t0

SFVEC3F CCAMERA::m_camera_pos_t0
protectedinherited

◆ m_camera_pos_t1

SFVEC3F CCAMERA::m_camera_pos_t1
protectedinherited

◆ m_dir

SFVEC3F CCAMERA::m_dir
protectedinherited

Definition at line 285 of file ccamera.h.

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

◆ m_focalLen

SFVEC2F CCAMERA::m_focalLen
protectedinherited

Definition at line 288 of file ccamera.h.

Referenced by CCAMERA::GetFocalLen(), and CCAMERA::rebuildProjection().

◆ m_frustum

FRUSTUM CCAMERA::m_frustum
protectedinherited

◆ m_interpolation_mode

CAMERA_INTERPOLATION CCAMERA::m_interpolation_mode
protectedinherited

Definition at line 304 of file ccamera.h.

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

◆ m_lastPosition

wxPoint CCAMERA::m_lastPosition
protectedinherited

The last mouse position in the screen.

Definition at line 271 of file ccamera.h.

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

◆ m_logTrace

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

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

◆ m_lookat_pos

SFVEC3F CCAMERA::m_lookat_pos
protectedinherited

◆ m_lookat_pos_t0

SFVEC3F CCAMERA::m_lookat_pos_t0
protectedinherited

◆ m_lookat_pos_t1

◆ m_parametersChanged

bool CCAMERA::m_parametersChanged
protectedinherited

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

Definition at line 324 of file ccamera.h.

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

◆ m_pos

SFVEC3F CCAMERA::m_pos
protectedinherited

Definition at line 286 of file ccamera.h.

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

◆ m_projectionMatrix

glm::mat4 CCAMERA::m_projectionMatrix
protectedinherited

◆ m_projectionMatrixInv

glm::mat4 CCAMERA::m_projectionMatrixInv
protectedinherited

◆ m_projectionType

PROJECTION_TYPE CCAMERA::m_projectionType
protectedinherited

◆ m_quat

double CTRACK_BALL::m_quat[4]
private

quarternion of the trackball

Definition at line 70 of file ctrack_ball.h.

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

◆ m_quat_t0

double CTRACK_BALL::m_quat_t0[4]
private

Definition at line 71 of file ctrack_ball.h.

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

◆ m_quat_t1

double CTRACK_BALL::m_quat_t1[4]
private

Definition at line 72 of file ctrack_ball.h.

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

◆ m_range_scale

float CCAMERA::m_range_scale
protectedinherited

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

◆ m_right

SFVEC3F CCAMERA::m_right
protectedinherited

Definition at line 283 of file ccamera.h.

Referenced by CCAMERA::GetRight(), and CCAMERA::updateFrustum().

◆ m_right_nX

std::vector< SFVEC3F > CCAMERA::m_right_nX
protectedinherited

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 CCAMERA::MakeRay(), and CCAMERA::updateFrustum().

◆ m_rotate_aux

SFVEC3F CCAMERA::m_rotate_aux
protectedinherited

◆ m_rotate_aux_t0

SFVEC3F CCAMERA::m_rotate_aux_t0
protectedinherited

◆ m_rotate_aux_t1

◆ m_rotationMatrix

glm::mat4 CCAMERA::m_rotationMatrix
protectedinherited

◆ m_rotationMatrixAux

glm::mat4 CCAMERA::m_rotationMatrixAux
protectedinherited

◆ m_scr_nX

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

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

◆ m_scr_nY

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

Definition at line 311 of file ccamera.h.

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

◆ m_up

SFVEC3F CCAMERA::m_up
protectedinherited

Definition at line 284 of file ccamera.h.

Referenced by CCAMERA::GetUp(), and CCAMERA::updateFrustum().

◆ m_up_nY

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

Definition at line 318 of file ccamera.h.

Referenced by CCAMERA::MakeRay(), and CCAMERA::updateFrustum().

◆ m_viewMatrix

glm::mat4 CCAMERA::m_viewMatrix
protectedinherited

◆ m_viewMatrixInverse

glm::mat4 CCAMERA::m_viewMatrixInverse
protectedinherited

Definition at line 276 of file ccamera.h.

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

◆ m_windowSize

SFVEC2I CCAMERA::m_windowSize
protectedinherited

◆ m_zoom

float CCAMERA::m_zoom
protectedinherited

◆ m_zoom_t0

float CCAMERA::m_zoom_t0
protectedinherited

◆ m_zoom_t1

float CCAMERA::m_zoom_t1
protectedinherited

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