KiCad PCB EDA Suite
TRACK_BALL Class Reference

#include <track_ball.h>

Inheritance diagram for TRACK_BALL:
CAMERA

Public Member Functions

 TRACK_BALL (float aRangeScale, float aDefaultZoom)
 
virtual ~TRACK_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
 This will set T0 and T1 with the current values. More...
 
void Interpolate (float t) override
 It will update the matrix to interpolate between T0 and T1 values. More...
 
const glm::mat4 GetRotationMatrix () const
 Get the rotation matrix to be applied in a transformation camera. More...
 
const glm::mat4 & GetViewMatrix () const
 
const glm::mat4 & GetViewMatrix_Inv () const
 
const glm::mat4 & GetProjectionMatrix () const
 
const glm::mat4 & GetProjectionMatrixInv () const
 
const SFVEC3FGetRight () const
 
const SFVEC3FGetUp () const
 
const SFVEC3FGetDir () const
 
const SFVEC3FGetPos () const
 
const SFVEC2FGetFocalLen () const
 
float GetNear () const
 
float GetFar () const
 
void SetBoardLookAtPos (const SFVEC3F &aBoardPos)
 
void SetLookAtPos_T1 (const SFVEC3F &aLookAtPos)
 
const SFVEC3FGetLookAtPos_T1 () const
 
const SFVEC3FGetCameraPos () const
 
void ResetXYpos ()
 
void ResetXYpos_T1 ()
 
void SetCurMousePosition (const wxPoint &aPosition)
 Update the current mouse position without make any new calculations on camera. More...
 
void ToggleProjection ()
 
PROJECTION_TYPE GetProjection ()
 
void SetProjection (PROJECTION_TYPE aProjection)
 
bool SetCurWindowSize (const wxSize &aSize)
 Update the windows size of the camera. More...
 
void ZoomReset ()
 
bool Zoom (float aFactor)
 
bool Zoom_T1 (float aFactor)
 
float ZoomGet () const
 
void RotateX (float aAngleInRadians)
 
void RotateY (float aAngleInRadians)
 
void RotateZ (float aAngleInRadians)
 
void RotateX_T1 (float aAngleInRadians)
 
void RotateY_T1 (float aAngleInRadians)
 
void RotateZ_T1 (float aAngleInRadians)
 
void SetInterpolateMode (CAMERA_INTERPOLATION aInterpolateMode)
 
bool ParametersChanged ()
 
bool ParametersChangedQuery () const
 
void MakeRay (const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
 Make a ray based on a windows screen position. More...
 
void MakeRay (const SFVEC2F &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
 Make a ray based on a windows screen position, it will interpolate based on the aWindowPos. More...
 
void MakeRayAtCurrrentMousePosition (SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection) const
 Make a ray based on the latest mouse position. More...
 

Protected Member Functions

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

Protected Attributes

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

Static Protected Attributes

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

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 track_ball.h.

Constructor & Destructor Documentation

◆ TRACK_BALL()

TRACK_BALL::TRACK_BALL ( float  aRangeScale,
float  aDefaultZoom 
)
explicit

Definition at line 37 of file track_ball.cpp.

37  :
38  CAMERA( aRangeScale, aDefaultZoom )
39 {
40  wxLogTrace( m_logTrace, wxT( "TRACK_BALL::TRACK_BALL" ) );
41 
42  memset( m_quat, 0, sizeof( m_quat ) );
43  memset( m_quat_t0, 0, sizeof( m_quat_t0 ) );
44  memset( m_quat_t1, 0, sizeof( m_quat_t1 ) );
45 
46  trackball( m_quat, 0.0, 0.0, 0.0, 0.0 );
47  trackball( m_quat_t0, 0.0, 0.0, 0.0, 0.0 );
48  trackball( m_quat_t1, 0.0, 0.0, 0.0, 0.0 );
49 }
double m_quat_t1[4]
Definition: track_ball.h:69
double m_quat_t0[4]
Definition: track_ball.h:68
void trackball(double q[4], double p1x, double p1y, double p2x, double p2y)
Definition: trackball.cpp:155
double m_quat[4]
quarternion of the trackball
Definition: track_ball.h:67
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
Definition: camera.h:331
CAMERA(float aRangeScale, float aDefaultZoom)
Initialize a camera.
Definition: camera.cpp:54

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

◆ ~TRACK_BALL()

virtual TRACK_BALL::~TRACK_BALL ( )
inlinevirtual

Definition at line 41 of file track_ball.h.

42  {
43  }

Member Function Documentation

◆ Drag()

void TRACK_BALL::Drag ( const wxPoint &  aNewMousePosition)
overridevirtual

Calculate a new mouse drag position.

Implements CAMERA.

Definition at line 52 of file track_ball.cpp.

53 {
54  m_parametersChanged = true;
55 
56  double spin_quat[4];
57 
58  // "Pass the x and y coordinates of the last and current positions of
59  // the mouse, scaled so they are from (-1.0 ... 1.0)."
60  const float zoom = 1.0f;
61 
62  trackball( spin_quat, 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 }
void build_rotmatrix(float m[4][4], double q[4])
Definition: trackball.cpp:306
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:322
void trackball(double q[4], double p1x, double p1y, double p2x, double p2y)
Definition: trackball.cpp:155
double m_quat[4]
quarternion of the trackball
Definition: track_ball.h:67
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: camera.h:271
void updateViewMatrix()
Definition: camera.cpp:123
glm::mat4 m_rotationMatrix
Definition: camera.h:273
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:266
void updateFrustum()
Definition: camera.cpp:251
void add_quats(double q1[4], double q2[4], double dest[4])
Definition: trackball.cpp:249

References add_quats(), build_rotmatrix(), CAMERA::m_lastPosition, CAMERA::m_parametersChanged, m_quat, CAMERA::m_rotationMatrix, CAMERA::m_windowSize, trackball(), CAMERA::updateFrustum(), CAMERA::updateViewMatrix(), and zoom.

Referenced by EDA_3D_MODEL_VIEWER::OnMouseMove().

◆ GetCameraPos()

const SFVEC3F& CAMERA::GetCameraPos ( ) const
inlineinherited

Definition at line 132 of file camera.h.

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

References CAMERA::m_camera_pos.

Referenced by EDA_3D_CANVAS::DisplayStatus().

◆ GetDir()

const SFVEC3F& CAMERA::GetDir ( ) const
inlineinherited

Definition at line 108 of file camera.h.

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

References CAMERA::m_dir.

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

◆ GetFar()

float CAMERA::GetFar ( ) const
inlineinherited

Definition at line 112 of file camera.h.

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

References CAMERA_FRUSTUM::farD, and CAMERA::m_frustum.

◆ GetFocalLen()

const SFVEC2F& CAMERA::GetFocalLen ( ) const
inlineinherited

Definition at line 110 of file camera.h.

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

References CAMERA::m_focalLen.

◆ GetLookAtPos_T1()

const SFVEC3F& CAMERA::GetLookAtPos_T1 ( ) const
inlineinherited

Definition at line 130 of file camera.h.

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

References CAMERA::m_lookat_pos_t1.

Referenced by EDA_3D_CANVAS::render_pivot().

◆ GetNear()

float CAMERA::GetNear ( ) const
inlineinherited

Definition at line 111 of file camera.h.

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

References CAMERA::m_frustum, and CAMERA_FRUSTUM::nearD.

◆ GetPos()

const SFVEC3F& CAMERA::GetPos ( ) const
inlineinherited

Definition at line 109 of file camera.h.

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

References CAMERA::m_pos.

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

◆ GetProjection()

PROJECTION_TYPE CAMERA::GetProjection ( )
inlineinherited

Definition at line 160 of file camera.h.

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

References CAMERA::m_projectionType.

Referenced by EDA_3D_CANVAS::GetProjectionMode(), and EDA_3D_VIEWER_FRAME::setupUIConditions().

◆ GetProjectionMatrix()

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

Definition at line 377 of file camera.cpp.

378 {
379  return m_projectionMatrix;
380 }
glm::mat4 m_projectionMatrix
Definition: camera.h:277

References CAMERA::m_projectionMatrix.

Referenced by EDA_3D_MODEL_VIEWER::OnPaint(), RENDER_3D_OPENGL::Redraw(), and EDA_3D_CANVAS::render_pivot().

◆ GetProjectionMatrixInv()

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

Definition at line 383 of file camera.cpp.

384 {
385  return m_projectionMatrixInv;
386 }
glm::mat4 m_projectionMatrixInv
Definition: camera.h:278

References CAMERA::m_projectionMatrixInv.

◆ GetRight()

const SFVEC3F& CAMERA::GetRight ( ) const
inlineinherited

Definition at line 106 of file camera.h.

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

References CAMERA::m_right.

◆ GetRotationMatrix()

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

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

Returns
the rotation matrix of the camera

Definition at line 152 of file camera.cpp.

153 {
155 }
glm::mat4 m_rotationMatrix
Definition: camera.h:273
glm::mat4 m_rotationMatrixAux
Definition: camera.h:274

References CAMERA::m_rotationMatrix, and CAMERA::m_rotationMatrixAux.

Referenced by EDA_3D_MODEL_VIEWER::OnPaint(), and RENDER_3D_OPENGL::render3dArrows().

◆ GetUp()

const SFVEC3F& CAMERA::GetUp ( ) const
inlineinherited

Definition at line 107 of file camera.h.

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

References CAMERA::m_up.

◆ GetViewMatrix()

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

Definition at line 407 of file camera.cpp.

408 {
409  return m_viewMatrix;
410 }
glm::mat4 m_viewMatrix
Definition: camera.h:275

References CAMERA::m_viewMatrix.

Referenced by EDA_3D_MODEL_VIEWER::OnPaint(), RENDER_3D_OPENGL::Redraw(), and EDA_3D_CANVAS::render_pivot().

◆ GetViewMatrix_Inv()

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

Definition at line 413 of file camera.cpp.

414 {
415  return m_viewMatrixInverse;
416 }
glm::mat4 m_viewMatrixInverse
Definition: camera.h:276

References CAMERA::m_viewMatrixInverse.

◆ Interpolate()

void TRACK_BALL::Interpolate ( float  t)
overridevirtual

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 CAMERA.

Definition at line 164 of file track_ball.cpp.

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

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

◆ MakeRay() [1/2]

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

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 309 of file camera.cpp.

311 {
312  wxASSERT( aWindowPos.x < m_windowSize.x );
313  wxASSERT( aWindowPos.y < m_windowSize.y );
314 
315  const SFVEC3F up_plus_right = m_up_nY[aWindowPos.y] + m_right_nX[aWindowPos.x];
316 
317  switch( m_projectionType )
318  {
319  default:
321  aOutOrigin = up_plus_right + m_frustum.nc;
322  aOutDirection = glm::normalize( aOutOrigin - m_pos );
323  break;
324 
326  aOutOrigin = up_plus_right * 0.5f + m_frustum.nc;
327  aOutDirection = -m_dir + SFVEC3F( FLT_EPSILON );
328  break;
329  }
330 }
SFVEC3F m_dir
Definition: camera.h:285
std::vector< SFVEC3F > m_right_nX
Precalc values array used to calc ray for each pixel, for X and Y axis of each new camera position.
Definition: camera.h:316
SFVEC3F m_pos
Definition: camera.h:286
PROJECTION_TYPE m_projectionType
Definition: camera.h:279
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:266
std::vector< SFVEC3F > m_up_nY
Definition: camera.h:317
CAMERA_FRUSTUM m_frustum
Definition: camera.h:281
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F nc
Definition: camera.h:49

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

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

◆ MakeRay() [2/2]

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

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

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

Definition at line 333 of file camera.cpp.

335 {
336  wxASSERT( aWindowPos.x < (float)m_windowSize.x );
337  wxASSERT( aWindowPos.y < (float)m_windowSize.y );
338 
339  const SFVEC2F floorWinPos_f = glm::floor( aWindowPos );
340  const SFVEC2I floorWinPos_i = (SFVEC2I)floorWinPos_f;
341  const SFVEC2F relativeWinPos = aWindowPos - floorWinPos_f;
342 
343  // Note: size of vectors m_up and m_right are m_windowSize + 1
344  const SFVEC3F up_plus_right = m_up_nY[floorWinPos_i.y] * (1.0f - relativeWinPos.y) +
345  m_up_nY[floorWinPos_i.y + 1] * relativeWinPos.y +
346  m_right_nX[floorWinPos_i.x] * (1.0f - relativeWinPos.x) +
347  m_right_nX[floorWinPos_i.x + 1] * relativeWinPos.x;
348 
349  switch( m_projectionType )
350  {
351  default:
353  aOutOrigin = up_plus_right + m_frustum.nc;
354  aOutDirection = glm::normalize( aOutOrigin - m_pos );
355  break;
356 
358  aOutOrigin = up_plus_right * 0.5f + m_frustum.nc;
359  aOutDirection = -m_dir + SFVEC3F( FLT_EPSILON );
360  break;
361  }
362 }
SFVEC3F m_dir
Definition: camera.h:285
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
std::vector< SFVEC3F > m_right_nX
Precalc values array used to calc ray for each pixel, for X and Y axis of each new camera position.
Definition: camera.h:316
SFVEC3F m_pos
Definition: camera.h:286
PROJECTION_TYPE m_projectionType
Definition: camera.h:279
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:266
std::vector< SFVEC3F > m_up_nY
Definition: camera.h:317
CAMERA_FRUSTUM m_frustum
Definition: camera.h:281
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F nc
Definition: camera.h:49

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

◆ MakeRayAtCurrrentMousePosition()

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

Make a ray based on the latest mouse position.

Parameters
aOutOriginout origin position of the ray.
aOutDirectionout direction.

Definition at line 365 of file camera.cpp.

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

References CAMERA::m_lastPosition, CAMERA::m_windowSize, and CAMERA::MakeRay().

Referenced by EDA_3D_CANVAS::getRayAtCurrrentMousePosition().

◆ Pan() [1/2]

void TRACK_BALL::Pan ( const wxPoint &  aNewMousePosition)
overridevirtual

Implements CAMERA.

Definition at line 95 of file track_ball.cpp.

96 {
97  m_parametersChanged = true;
98 
100  {
101  m_camera_pos.x -= m_frustum.nw *
102  ( m_lastPosition.x - aNewMousePosition.x ) / m_windowSize.x;
103  m_camera_pos.y -= m_frustum.nh *
104  ( aNewMousePosition.y - m_lastPosition.y ) / m_windowSize.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 *
111  ( m_lastPosition.x - aNewMousePosition.x ) / m_windowSize.x;
112  m_camera_pos.y -= panFactor * ( aNewMousePosition.y - m_lastPosition.y ) / m_windowSize.y;
113  }
114 
116  updateFrustum();
117 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:322
float ratio
Definition: camera.h:59
float nw
Definition: camera.h:60
float tang
Definition: camera.h:59
PROJECTION_TYPE m_projectionType
Definition: camera.h:279
wxPoint m_lastPosition
The last mouse position in the screen.
Definition: camera.h:271
void updateViewMatrix()
Definition: camera.cpp:123
SFVEC2I m_windowSize
The window size that this camera is working.
Definition: camera.h:266
SFVEC3F m_camera_pos
Definition: camera.h:291
void updateFrustum()
Definition: camera.cpp:251
CAMERA_FRUSTUM m_frustum
Definition: camera.h:281
float nh
Definition: camera.h:60

References CAMERA::m_camera_pos, CAMERA::m_frustum, CAMERA::m_lastPosition, CAMERA::m_parametersChanged, CAMERA::m_projectionType, CAMERA::m_windowSize, CAMERA_FRUSTUM::nh, CAMERA_FRUSTUM::nw, ORTHO, CAMERA_FRUSTUM::ratio, CAMERA_FRUSTUM::tang, CAMERA::updateFrustum(), and CAMERA::updateViewMatrix().

◆ Pan() [2/2]

void TRACK_BALL::Pan ( const SFVEC3F aDeltaOffsetInc)
overridevirtual

Implements CAMERA.

Definition at line 120 of file track_ball.cpp.

121 {
122  m_parametersChanged = true;
123 
124  m_camera_pos += aDeltaOffsetInc;
125 
127  updateFrustum();
128 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:322
void updateViewMatrix()
Definition: camera.cpp:123
SFVEC3F m_camera_pos
Definition: camera.h:291
void updateFrustum()
Definition: camera.cpp:251

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

◆ Pan_T1()

void TRACK_BALL::Pan_T1 ( const SFVEC3F aDeltaOffsetInc)
overridevirtual

Implements CAMERA.

Definition at line 131 of file track_ball.cpp.

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

References CAMERA::m_camera_pos, and CAMERA::m_camera_pos_t1.

◆ ParametersChanged()

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

Definition at line 582 of file camera.cpp.

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

References CAMERA::m_parametersChanged.

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

◆ ParametersChangedQuery()

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

Definition at line 211 of file camera.h.

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

References CAMERA::m_parametersChanged.

◆ rebuildProjection()

void CAMERA::rebuildProjection ( )
protectedinherited

Definition at line 158 of file camera.cpp.

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

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

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

◆ Reset()

void TRACK_BALL::Reset ( )
overridevirtual

Reset the camera to initial state.

Reimplemented from CAMERA.

Definition at line 137 of file track_ball.cpp.

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

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

◆ Reset_T1()

void TRACK_BALL::Reset_T1 ( )
overridevirtual

Reimplemented from CAMERA.

Definition at line 146 of file track_ball.cpp.

147 {
149 
150  memset( m_quat_t1, 0, sizeof( m_quat_t1 ) );
151  trackball( m_quat_t1, 0.0, 0.0, 0.0, 0.0 );
152 }
double m_quat_t1[4]
Definition: track_ball.h:69
void trackball(double q[4], double p1x, double p1y, double p2x, double p2y)
Definition: trackball.cpp:155
virtual void Reset_T1()
Definition: camera.cpp:102

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

◆ ResetXYpos()

void CAMERA::ResetXYpos ( )
inherited

Definition at line 389 of file camera.cpp.

390 {
391  m_parametersChanged = true;
392  m_camera_pos.x = 0.0f;
393  m_camera_pos.y = 0.0f;
394 
396  updateFrustum();
397 }
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:322
void updateViewMatrix()
Definition: camera.cpp:123
SFVEC3F m_camera_pos
Definition: camera.h:291
void updateFrustum()
Definition: camera.cpp:251

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

◆ ResetXYpos_T1()

void CAMERA::ResetXYpos_T1 ( )
inherited

Definition at line 400 of file camera.cpp.

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

References CAMERA::m_camera_pos_t1.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ RotateX()

void CAMERA::RotateX ( float  aAngleInRadians)
inherited

Definition at line 511 of file camera.cpp.

512 {
513  m_rotate_aux.x += aAngleInRadians;
515 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:300
void updateRotationMatrix()
Definition: camera.cpp:131

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

Referenced by EDA_3D_CONTROLLER::RotateView().

◆ RotateX_T1()

void CAMERA::RotateX_T1 ( float  aAngleInRadians)
inherited

Definition at line 532 of file camera.cpp.

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

References CAMERA::m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ RotateY()

void CAMERA::RotateY ( float  aAngleInRadians)
inherited

Definition at line 518 of file camera.cpp.

519 {
520  m_rotate_aux.y += aAngleInRadians;
522 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:300
void updateRotationMatrix()
Definition: camera.cpp:131

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

Referenced by EDA_3D_CONTROLLER::RotateView().

◆ RotateY_T1()

void CAMERA::RotateY_T1 ( float  aAngleInRadians)
inherited

Definition at line 538 of file camera.cpp.

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

References CAMERA::m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ RotateZ()

void CAMERA::RotateZ ( float  aAngleInRadians)
inherited

Definition at line 525 of file camera.cpp.

526 {
527  m_rotate_aux.z += aAngleInRadians;
529 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:300
void updateRotationMatrix()
Definition: camera.cpp:131

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

Referenced by EDA_3D_CONTROLLER::RotateView().

◆ RotateZ_T1()

void CAMERA::RotateZ_T1 ( float  aAngleInRadians)
inherited

Definition at line 544 of file camera.cpp.

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

References CAMERA::m_rotate_aux_t1.

Referenced by EDA_3D_CANVAS::SetView3D().

◆ SetBoardLookAtPos()

void CAMERA::SetBoardLookAtPos ( const SFVEC3F aBoardPos)
inlineinherited

Definition at line 114 of file camera.h.

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

References CAMERA::m_board_lookat_pos_init, and CAMERA::SetLookAtPos().

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

◆ SetCurMousePosition()

void CAMERA::SetCurMousePosition ( const wxPoint &  aPosition)
inherited

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

Definition at line 419 of file camera.cpp.

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

References CAMERA::m_lastPosition.

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

◆ SetCurWindowSize()

bool CAMERA::SetCurWindowSize ( const wxSize &  aSize)
inherited

Update the windows size of the camera.

Returns
true if the windows size changed since last time.

Definition at line 436 of file camera.cpp.

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

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

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

◆ SetInterpolateMode()

void CAMERA::SetInterpolateMode ( CAMERA_INTERPOLATION  aInterpolateMode)
inlineinherited

Definition at line 198 of file camera.h.

199  {
200  m_interpolation_mode = aInterpolateMode;
201  }
CAMERA_INTERPOLATION m_interpolation_mode
Definition: camera.h:304

References CAMERA::m_interpolation_mode.

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

◆ SetLookAtPos()

void TRACK_BALL::SetLookAtPos ( const SFVEC3F aLookAtPos)
overridevirtual

Implements CAMERA.

Definition at line 81 of file track_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: camera.h:322
void updateViewMatrix()
Definition: camera.cpp:123
SFVEC3F m_lookat_pos
Definition: camera.h:295
void updateFrustum()
Definition: camera.cpp:251

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

◆ SetLookAtPos_T1()

void CAMERA::SetLookAtPos_T1 ( const SFVEC3F aLookAtPos)
inlineinherited

Definition at line 125 of file camera.h.

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

References CAMERA::m_lookat_pos_t1.

Referenced by EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ SetProjection()

void CAMERA::SetProjection ( PROJECTION_TYPE  aProjection)
inlineinherited

Definition at line 161 of file camera.h.

161 { m_projectionType = aProjection; }
PROJECTION_TYPE m_projectionType
Definition: camera.h:279

References CAMERA::m_projectionType.

Referenced by EDA_3D_CANVAS::SetProjectionMode().

◆ SetT0_and_T1_current_T()

void TRACK_BALL::SetT0_and_T1_current_T ( )
overridevirtual

This will set T0 and T1 with the current values.

Reimplemented from CAMERA.

Definition at line 155 of file track_ball.cpp.

156 {
158 
159  memcpy( m_quat_t0, m_quat, sizeof( m_quat ) );
160  memcpy( m_quat_t1, m_quat, sizeof( m_quat ) );
161 }
double m_quat_t1[4]
Definition: track_ball.h:69
double m_quat_t0[4]
Definition: track_ball.h:68
double m_quat[4]
quarternion of the trackball
Definition: track_ball.h:67
virtual void SetT0_and_T1_current_T()
This will set T0 and T1 with the current values.
Definition: camera.cpp:550

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

◆ ToggleProjection()

void CAMERA::ToggleProjection ( )
inherited

◆ updateFrustum()

void CAMERA::updateFrustum ( )
protectedinherited

Definition at line 251 of file camera.cpp.

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

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

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

◆ updateRotationMatrix()

void CAMERA::updateRotationMatrix ( )
protectedinherited

Definition at line 131 of file camera.cpp.

132 {
133  m_rotationMatrixAux = glm::rotate( glm::mat4( 1.0f ), m_rotate_aux.x,
134  SFVEC3F( 1.0f, 0.0f, 0.0f ) );
136 
138  SFVEC3F( 0.0f, 1.0f, 0.0f ) );
140 
142  SFVEC3F( 0.0f, 0.0f, 1.0f ) );
144 
145  m_parametersChanged = true;
146 
148  updateFrustum();
149 }
SFVEC3F m_rotate_aux
Stores the rotation angle auxiliary.
Definition: camera.h:300
bool m_parametersChanged
Set to true if any of the parameters in the camera was changed.
Definition: camera.h:322
void normalise2PI(float &aAngle)
Definition: camera.cpp:34
void updateViewMatrix()
Definition: camera.cpp:123
void updateFrustum()
Definition: camera.cpp:251
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
glm::mat4 m_rotationMatrixAux
Definition: camera.h:274

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

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

◆ updateViewMatrix()

void CAMERA::updateViewMatrix ( )
protectedinherited

Definition at line 123 of file camera.cpp.

124 {
125  m_viewMatrix = glm::translate( glm::mat4( 1.0f ), m_camera_pos ) *
127  glm::translate( glm::mat4( 1.0f ), -m_lookat_pos );
128 }
glm::mat4 m_viewMatrix
Definition: camera.h:275
glm::mat4 m_rotationMatrix
Definition: camera.h:273
SFVEC3F m_lookat_pos
Definition: camera.h:295
SFVEC3F m_camera_pos
Definition: camera.h:291
glm::mat4 m_rotationMatrixAux
Definition: camera.h:274

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

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

◆ Zoom()

bool CAMERA::Zoom ( float  aFactor)
inherited

Definition at line 462 of file camera.cpp.

463 {
464  if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 )
465  || aFactor == 1 )
466  return false;
467 
468  m_zoom /= aFactor;
469 
470  if( m_zoom <= MIN_ZOOM )
471  m_zoom = MIN_ZOOM;
472 
473  if( m_zoom >= MAX_ZOOM )
474  m_zoom = MAX_ZOOM;
475 
477 
480 
481  return true;
482 }
#define MIN_ZOOM
Definition: camera.cpp:50
float m_zoom
Definition: camera.h:259
#define MAX_ZOOM
Definition: camera.cpp:51
SFVEC3F m_camera_pos_init
Definition: camera.h:290
void rebuildProjection()
Definition: camera.cpp:158
void updateViewMatrix()
Definition: camera.cpp:123
SFVEC3F m_camera_pos
Definition: camera.h:291

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

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

◆ Zoom_T1()

bool CAMERA::Zoom_T1 ( float  aFactor)
inherited

Definition at line 485 of file camera.cpp.

486 {
487  if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 )
488  || aFactor == 1 )
489  return false;
490 
491  m_zoom_t1 = m_zoom / aFactor;
492 
493  if( m_zoom_t1 < MIN_ZOOM )
495 
496  if( m_zoom_t1 > MAX_ZOOM )
498 
500 
501  return true;
502 }
#define MIN_ZOOM
Definition: camera.cpp:50
float m_zoom
Definition: camera.h:259
#define MAX_ZOOM
Definition: camera.cpp:51
float m_zoom_t1
Definition: camera.h:261
SFVEC3F m_camera_pos_init
Definition: camera.h:290
SFVEC3F m_camera_pos_t1
Definition: camera.h:293

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

Referenced by EDA_3D_CANVAS::SetView3D().

◆ ZoomGet()

float CAMERA::ZoomGet ( ) const
inherited

Definition at line 505 of file camera.cpp.

506 {
507  return m_zoom;
508 }
float m_zoom
Definition: camera.h:259

References CAMERA::m_zoom.

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

◆ ZoomReset()

void CAMERA::ZoomReset ( )
inherited

Definition at line 452 of file camera.cpp.

453 {
454  m_zoom = 1.0f;
455 
457 
460 }
float m_zoom
Definition: camera.h:259
SFVEC3F m_camera_pos_init
Definition: camera.h:290
void rebuildProjection()
Definition: camera.cpp:158
void updateViewMatrix()
Definition: camera.cpp:123
SFVEC3F m_camera_pos
Definition: camera.h:291

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

Member Data Documentation

◆ m_board_lookat_pos_init

SFVEC3F CAMERA::m_board_lookat_pos_init
protectedinherited

Default boardlookat position (the board center).

Definition at line 298 of file camera.h.

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

◆ m_camera_pos

◆ m_camera_pos_init

SFVEC3F CAMERA::m_camera_pos_init
protectedinherited

◆ m_camera_pos_t0

SFVEC3F CAMERA::m_camera_pos_t0
protectedinherited

Definition at line 292 of file camera.h.

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

◆ m_camera_pos_t1

SFVEC3F CAMERA::m_camera_pos_t1
protectedinherited

◆ m_default_zoom

float CAMERA::m_default_zoom
protectedinherited

3D zoom value (Min 0.0 ...

Max 1.0)

Definition at line 258 of file camera.h.

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

◆ m_dir

SFVEC3F CAMERA::m_dir
protectedinherited

Definition at line 285 of file camera.h.

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

◆ m_focalLen

SFVEC2F CAMERA::m_focalLen
protectedinherited

Definition at line 288 of file camera.h.

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

◆ m_frustum

CAMERA_FRUSTUM CAMERA::m_frustum
protectedinherited

◆ m_interpolation_mode

CAMERA_INTERPOLATION CAMERA::m_interpolation_mode
protectedinherited

Definition at line 304 of file camera.h.

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

◆ m_lastPosition

wxPoint CAMERA::m_lastPosition
protectedinherited

The last mouse position in the screen.

Definition at line 271 of file camera.h.

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

◆ m_lookat_pos

SFVEC3F CAMERA::m_lookat_pos
protectedinherited

◆ m_lookat_pos_t0

SFVEC3F CAMERA::m_lookat_pos_t0
protectedinherited

Definition at line 296 of file camera.h.

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

◆ m_lookat_pos_t1

SFVEC3F CAMERA::m_lookat_pos_t1
protectedinherited

◆ m_parametersChanged

bool CAMERA::m_parametersChanged
protectedinherited

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

Definition at line 322 of file camera.h.

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

◆ m_pos

SFVEC3F CAMERA::m_pos
protectedinherited

Definition at line 286 of file camera.h.

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

◆ m_projectionMatrix

glm::mat4 CAMERA::m_projectionMatrix
protectedinherited

Definition at line 277 of file camera.h.

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

◆ m_projectionMatrixInv

glm::mat4 CAMERA::m_projectionMatrixInv
protectedinherited

◆ m_projectionType

◆ m_quat

double TRACK_BALL::m_quat[4]
private

quarternion of the trackball

Definition at line 67 of file track_ball.h.

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

◆ m_quat_t0

double TRACK_BALL::m_quat_t0[4]
private

Definition at line 68 of file track_ball.h.

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

◆ m_quat_t1

double TRACK_BALL::m_quat_t1[4]
private

Definition at line 69 of file track_ball.h.

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

◆ m_range_scale

float CAMERA::m_range_scale
protectedinherited

The nominal range expected to be used in the camera.

It will be used to initialize the Z position

Definition at line 252 of file camera.h.

Referenced by CAMERA::CAMERA().

◆ m_right

SFVEC3F CAMERA::m_right
protectedinherited

Definition at line 283 of file camera.h.

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

◆ m_right_nX

std::vector< SFVEC3F > CAMERA::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 316 of file camera.h.

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

◆ m_rotate_aux

SFVEC3F CAMERA::m_rotate_aux
protectedinherited

◆ m_rotate_aux_t0

SFVEC3F CAMERA::m_rotate_aux_t0
protectedinherited

◆ m_rotate_aux_t1

◆ m_rotationMatrix

glm::mat4 CAMERA::m_rotationMatrix
protectedinherited

◆ m_rotationMatrixAux

glm::mat4 CAMERA::m_rotationMatrixAux
protectedinherited

◆ m_scr_nX

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

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

Definition at line 309 of file camera.h.

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

◆ m_scr_nY

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

Definition at line 310 of file camera.h.

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

◆ m_up

SFVEC3F CAMERA::m_up
protectedinherited

Definition at line 284 of file camera.h.

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

◆ m_up_nY

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

Definition at line 317 of file camera.h.

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

◆ m_viewMatrix

glm::mat4 CAMERA::m_viewMatrix
protectedinherited

◆ m_viewMatrixInverse

glm::mat4 CAMERA::m_viewMatrixInverse
protectedinherited

Definition at line 276 of file camera.h.

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

◆ m_windowSize

SFVEC2I CAMERA::m_windowSize
protectedinherited

◆ m_zoom

◆ m_zoom_t0

float CAMERA::m_zoom_t0
protectedinherited

Definition at line 260 of file camera.h.

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

◆ m_zoom_t1

float CAMERA::m_zoom_t1
protectedinherited

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