MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / spaceMouseMove_

Method spaceMouseMove_

source/MRViewer/MRSpaceMouseController.cpp:25–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25bool Controller::spaceMouseMove_( const Vector3f& translate, const Vector3f& rotate )
26{
27 auto& viewer = getViewerInstance();
28 auto& viewport = viewer.viewport();
29
30 const Vector3f translateScaled = mult( translate, params_.translateScale ) * 0.02f;
31 const Vector3f rotateScaled = mult( rotate, params_.rotateScale ) * 0.001f;
32
33 const auto& viewportParams = viewport.getParameters();
34
35 //translation
36 Vector3f axisN;
37 Vector3f axisX = Vector3f::plusX();
38 Vector3f axisY = Vector3f::minusY();
39 axisN = viewport.unprojectFromClipSpace( axisN );
40 axisX = ( viewport.unprojectFromClipSpace( axisX ) - axisN );
41 axisY = ( viewport.unprojectFromClipSpace( axisY ) - axisN );
42 Vector3f diff( translateScaled.x * axisX + translateScaled.z * axisY );
43
44 viewport.setCameraTranslation( viewportParams.cameraTranslation + diff * 0.1f );
45
46 //zoom
47 float mult = pow( 0.95f, fabs( translateScaled.y ) * translateScaled.y );
48 constexpr float min_angle = 0.001f;
49 constexpr float max_angle = 179.99f;
50 constexpr float d2r = PI_F / 180.0f;
51 float angle = viewportParams.cameraViewAngle;
52 angle = float( atan( tan( ( angle ) * ( d2r / 2.f ) ) * mult ) / ( d2r / 2.f ) );
53 angle = std::clamp( angle, min_angle, max_angle );
54 viewport.setCameraViewAngle( angle );
55
56 //rotation
57 if ( !lockRotate_ )
58 {
59 Quaternionf quat = (
60 Quaternionf( Vector3f{ 1,0,0 }, rotateScaled.x ) *
61 Quaternionf( Vector3f{ 0,0,1 }, rotateScaled.y ) *
62 Quaternionf( Vector3f{ 0,-1,0 }, rotateScaled.z ) *
63 viewportParams.cameraTrackballAngle
64 ).normalized();
65 viewport.setCameraTrackballAngle( quat );
66 }
67
68 return true;
69}
70
71bool Controller::spaceMouseDown_( int key )
72{

Callers

nothing calls this directly

Calls 7

clampFunction · 0.85
setCameraTranslationMethod · 0.80
setCameraViewAngleMethod · 0.80
multFunction · 0.50
normalizedMethod · 0.45

Tested by

no test coverage detected