I just submitted my very first Pull Request on bitbucket, for my very first new feature — mousewheel zoom! Check it out:
Previously, to zoom in in a scene, you had to hold down the SHIFT key and then move the camera in or out. This is not the most intuitive thing to a user! Part of what I want to revamp in the program is the intuitiveness of the camera controls, so I implemented a MouseWheel event handler which zooms the camera in or out depending on whether the user rolls the mousewheel forwards or backwards. This gives users with the right hardware a much easier way to control zooming.
It’s really a simple piece of code, but it’s a start, and signifies that I’m beginning to understand how to successfully add new functionality to VISTAS.
void VI_SphereInteractor::MouseWheel(int wheelRotationAmount, bool shift, bool alt, bool ctrl) { float sceneSizeMultiplier(0.8); const float originalDistance = GetBounds().maxZ + GetBounds().GetDiameter(); const float currentDistance = GetCamera()->GetDistanceToPoint(GetCenter()); float distanceRatio = 1 - (originalDistance-currentDistance)/originalDistance; if (distanceRatio < 0) { distanceRatio = -log(-distanceRatio); // Keep camera from zooming out too fast once we are further back than the edge of the original camera distance } if (d->i_type == VI_SphereInteractorData::SCENE) { sceneSizeMultiplier *= d->i_scene.GetBoundingBox().GetDiameter()/2; } float zoomAmount = wheelRotationAmount/WHEEL_DELTA * sceneSizeMultiplier * distanceRatio; if (wheelRotationAmount < 0 && zoomAmount <= 0) { // Allow for rapid zoom-out even when zoomed in very closely zoomAmount -= 1; } if (shift == true) { // Fast zoom zoomAmount *= 2; } else if (ctrl == true) { // Precision zoom zoomAmount *= 0.25; } d->i_distance += zoomAmount; RefreshPosition(); };