1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkInteractorStyleFlight.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 16 /** 17 * @class vtkInteractorStyleFlight 18 * @brief provides flight motion routines 19 * 20 * 21 * Left mouse button press produces forward motion. 22 * Right mouse button press produces reverse motion. 23 * Moving mouse during motion steers user in desired direction. 24 * Keyboard controls are: 25 * Left/Right/Up/Down Arrows for steering direction 26 * 'A' forward, 'Z' reverse motion 27 * Ctrl Key causes sidestep instead of steering in mouse and key modes 28 * Shift key is accelerator in mouse and key modes 29 * Ctrl and Shift together causes Roll in mouse and key modes 30 * 31 * By default, one "step" of motion corresponds to 1/250th of the diagonal 32 * of bounding box of visible actors, '+' and '-' keys allow user to 33 * increase or decrease step size. 34 */ 35 36 #ifndef vtkInteractorStyleFlight_h 37 #define vtkInteractorStyleFlight_h 38 39 #include "vtkInteractionStyleModule.h" // For export macro 40 #include "vtkInteractorStyle.h" 41 class vtkCamera; 42 class vtkPerspectiveTransform; 43 44 class CPIDControl; 45 46 class VTKINTERACTIONSTYLE_EXPORT vtkInteractorStyleFlight : public vtkInteractorStyle 47 { 48 public: 49 static vtkInteractorStyleFlight* New(); 50 vtkTypeMacro(vtkInteractorStyleFlight, vtkInteractorStyle); 51 void PrintSelf(ostream& os, vtkIndent indent) override; 52 53 /** 54 * Move the Eye/Camera to a specific location (no intermediate 55 * steps are taken 56 */ 57 void JumpTo(double campos[3], double focpos[3]); 58 59 ///@{ 60 /** 61 * Set the basic unit step size : by default 1/250 of bounding diagonal 62 */ 63 vtkSetMacro(MotionStepSize, double); 64 vtkGetMacro(MotionStepSize, double); 65 ///@} 66 67 ///@{ 68 /** 69 * Set acceleration factor when shift key is applied : default 10 70 */ 71 vtkSetMacro(MotionAccelerationFactor, double); 72 vtkGetMacro(MotionAccelerationFactor, double); 73 ///@} 74 75 ///@{ 76 /** 77 * Set the basic angular unit for turning : default 1 degree 78 */ 79 vtkSetMacro(AngleStepSize, double); 80 vtkGetMacro(AngleStepSize, double); 81 ///@} 82 83 ///@{ 84 /** 85 * Set angular acceleration when shift key is applied : default 5 86 */ 87 vtkSetMacro(AngleAccelerationFactor, double); 88 vtkGetMacro(AngleAccelerationFactor, double); 89 ///@} 90 91 ///@{ 92 /** 93 * Disable motion (temporarily - for viewing etc) 94 */ 95 vtkSetMacro(DisableMotion, vtkTypeBool); 96 vtkGetMacro(DisableMotion, vtkTypeBool); 97 vtkBooleanMacro(DisableMotion, vtkTypeBool); 98 ///@} 99 100 ///@{ 101 /** 102 * When flying, apply a restorative force to the "Up" vector. 103 * This is activated when the current 'up' is close to the actual 'up' 104 * (as defined in DefaultUpVector). This prevents excessive twisting forces 105 * when viewing from arbitrary angles, but keep the horizon level when 106 * the user is flying over terrain. 107 */ 108 vtkSetMacro(RestoreUpVector, vtkTypeBool); 109 vtkGetMacro(RestoreUpVector, vtkTypeBool); 110 vtkBooleanMacro(RestoreUpVector, vtkTypeBool); 111 ///@} 112 113 // Specify "up" (by default {0,0,1} but can be changed) 114 vtkGetVectorMacro(DefaultUpVector, double, 3); 115 vtkSetVectorMacro(DefaultUpVector, double, 3); 116 117 ///@{ 118 /** 119 * Concrete implementation of Mouse event bindings for flight 120 */ 121 void OnMouseMove() override; 122 void OnLeftButtonDown() override; 123 void OnLeftButtonUp() override; 124 void OnMiddleButtonDown() override; 125 void OnMiddleButtonUp() override; 126 void OnRightButtonDown() override; 127 void OnRightButtonUp() override; 128 ///@} 129 130 ///@{ 131 /** 132 * Concrete implementation of Keyboard event bindings for flight 133 */ 134 void OnChar() override; 135 void OnKeyDown() override; 136 void OnKeyUp() override; 137 void OnTimer() override; 138 // 139 virtual void ForwardFly(); 140 virtual void ReverseFly(); 141 // 142 virtual void StartForwardFly(); 143 virtual void EndForwardFly(); 144 virtual void StartReverseFly(); 145 virtual void EndReverseFly(); 146 ///@} 147 148 protected: 149 vtkInteractorStyleFlight(); 150 ~vtkInteractorStyleFlight() override; 151 152 ///@{ 153 /** 154 * Routines used internally for computing motion and steering 155 */ 156 void UpdateSteering(vtkCamera* cam); 157 void UpdateMouseSteering(vtkCamera* cam); 158 void FlyByMouse(vtkCamera* cam); 159 void FlyByKey(vtkCamera* cam); 160 void GetLRVector(double vector[3], vtkCamera* cam); 161 void MotionAlongVector(double vector[3], double amount, vtkCamera* cam); 162 void SetupMotionVars(vtkCamera* cam); 163 void FinishCamera(vtkCamera* cam); 164 // 165 // 166 unsigned char KeysDown; 167 vtkTypeBool DisableMotion; 168 vtkTypeBool RestoreUpVector; 169 double DiagonalLength; 170 double MotionStepSize; 171 double MotionUserScale; 172 double MotionAccelerationFactor; 173 double AngleStepSize; 174 double AngleAccelerationFactor; 175 double DefaultUpVector[3]; 176 double AzimuthStepSize; 177 double IdealFocalPoint[3]; 178 vtkPerspectiveTransform* Transform; 179 double DeltaYaw; 180 double lYaw; 181 double DeltaPitch; 182 double lPitch; 183 ///@} 184 185 CPIDControl* PID_Yaw; 186 CPIDControl* PID_Pitch; 187 188 private: 189 vtkInteractorStyleFlight(const vtkInteractorStyleFlight&) = delete; 190 void operator=(const vtkInteractorStyleFlight&) = delete; 191 }; 192 193 #endif 194