Skip to content

Commit

Permalink
add some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
laumaya committed Aug 26, 2015
1 parent 2c232bf commit 497c734
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
25 changes: 10 additions & 15 deletions src/lib/viewport/glc_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,20 @@ bool GLC_Camera::operator==(const GLC_Camera& other) const
/////////////////////////////////////////////////////////////////////
// Set Functions
/////////////////////////////////////////////////////////////////////
void GLC_Camera::orbit(GLC_Vector3d VectOldPoss, GLC_Vector3d VectCurPoss)
void GLC_Camera::orbit(GLC_Vector3d vectOldPoss, GLC_Vector3d vectCurPoss)
{
// Map Vectors
GLC_Matrix4x4 invMat(m_ModelViewMatrix);
invMat.invert();
VectOldPoss= invMat * VectOldPoss;
VectCurPoss= invMat * VectCurPoss;

// Compute rotation matrix
const GLC_Vector3d VectAxeRot(VectCurPoss ^ VectOldPoss);
// Check if rotation vector is not null
if (!VectAxeRot.isNull())
{ // Ok, is not null
const double Angle= acos(VectCurPoss * VectOldPoss);
const GLC_Matrix4x4 MatOrbit(VectAxeRot, Angle);
const GLC_Vector3d rotationAxis(vectCurPoss ^ vectOldPoss);
// Check if rotation axis is not null
if (!rotationAxis.isNull())
{
const double angle= acos(vectCurPoss * vectOldPoss);
const GLC_Matrix4x4 invMat(m_ModelViewMatrix.inverted());
const GLC_Matrix4x4 orbitMatrix(invMat * rotationAxis, angle);

// Camera transformation
m_Eye= (MatOrbit * (m_Eye - m_Target)) + m_Target;
m_VectUp= MatOrbit * m_VectUp;
m_Eye= (orbitMatrix * (m_Eye - m_Target)) + m_Target;
m_VectUp= orbitMatrix * m_VectUp;
createMatComp();
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewport/glc_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class GLC_LIB_EXPORT GLC_Camera : public QObject
//////////////////////////////////////////////////////////////////////
public:
//! Camera orbiting
void orbit(GLC_Vector3d VectOldPoss, GLC_Vector3d VectCurPoss);
void orbit(GLC_Vector3d vectOldPoss, GLC_Vector3d vectCurPoss);

//! panoramic movement
void pan(GLC_Vector3d VectDep);
Expand Down
14 changes: 8 additions & 6 deletions src/lib/viewport/glc_trackballmover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,21 @@ void GLC_TrackBallMover::init(const GLC_UserInput& userInput)
// Move the camera
bool GLC_TrackBallMover::move(const GLC_UserInput& userInput)
{
const GLC_Vector3d VectCurOrbit(mapForTracking(static_cast<double>(userInput.x()), static_cast<double>(userInput.y())));
const double x= static_cast<double>(userInput.x());
const double y= static_cast<double>(userInput.y());

const GLC_Vector3d vectCurOrbit(mapForTracking(x, y));

// Update camera position (orbit)
GLC_Mover::m_pViewport->cameraHandle()->orbit(GLC_Mover::m_PreviousVector, VectCurOrbit);
GLC_Mover::m_pViewport->cameraHandle()->orbit(GLC_Mover::m_PreviousVector, vectCurOrbit);

// Update arcs of circle's positionning matrix
const GLC_Matrix4x4 MatRot(GLC_Mover::m_PreviousVector, VectCurOrbit);

GLC_Mover::m_MoverInfo.m_MatrixInfo.first()= MatRot;
const GLC_Matrix4x4 matRot(GLC_Mover::m_PreviousVector, vectCurOrbit);
GLC_Mover::m_MoverInfo.m_MatrixInfo.first()= matRot;
updateRepresentation();

// Previous vector become current vector
GLC_Mover::m_PreviousVector = VectCurOrbit;
GLC_Mover::m_PreviousVector = vectCurOrbit;

return true;
}
Expand Down

0 comments on commit 497c734

Please sign in to comment.