Commit a1c1fcb5 authored by John Biddiscombe's avatar John Biddiscombe

ENH: New flight mode functions for standing still and looking around.

Plan on adding several additional functions. Particularly, forcing
UPVector to remain fixed. etc etc
parent 07b1b33d
......@@ -74,6 +74,12 @@ vtkInteractorStyleFlight::vtkInteractorStyleFlight()
this->AngleAccelerationFactor = 5.0;
this->OldX = 0.0;
this->OldY = 0.0;
this->AzimuthScanning = 0;
this->DisableMotion = 0;
this->FixUpVector = 0;
this->FixedUpVector[0] = 0;
this->FixedUpVector[1] = 0;
this->FixedUpVector[2] = 1;
}
//---------------------------------------------------------------------------
vtkInteractorStyleFlight::~vtkInteractorStyleFlight() {
......@@ -98,6 +104,7 @@ void vtkInteractorStyleFlight::DoTimerStop(void) {
//---------------------------------------------------------------------------
void vtkInteractorStyleFlight::OnLeftButtonDown(int ctrl, int shift, int X, int Y) {
this->UpdateInternalState(ctrl, shift, X, Y);
if (this->AzimuthScanning) return;
if (!this->Reversing) {
this->OldX = this->x2 = X;
this->OldY = this->y2 = Y;
......@@ -115,6 +122,7 @@ void vtkInteractorStyleFlight::OnLeftButtonUp(int ctrl, int shift, int X, int Y)
//---------------------------------------------------------------------------
void vtkInteractorStyleFlight::OnRightButtonDown(int ctrl, int shift, int X, int Y) {
this->UpdateInternalState(ctrl, shift, X, Y);
if (this->AzimuthScanning) return;
if (!this->Flying) {
this->OldX = this->x2 = X;
this->OldY = this->y2 = Y;
......@@ -132,6 +140,7 @@ void vtkInteractorStyleFlight::OnRightButtonUp(int ctrl, int shift, int X, int Y
//---------------------------------------------------------------------------
void vtkInteractorStyleFlight::OnMiddleButtonDown(int ctrl, int shift, int X, int Y) {
this->UpdateInternalState(ctrl, shift, X, Y);
if (this->AzimuthScanning) return;
// want to add some more functions???
// I've got no middle mouse button :(
}
......@@ -142,6 +151,7 @@ void vtkInteractorStyleFlight::OnMiddleButtonUp(int ctrl, int shift, int X, int
//---------------------------------------------------------------------------
void vtkInteractorStyleFlight::OnMouseMove(int ctrl, int shift, int X, int Y) {
this->UpdateInternalState(ctrl, shift, X, Y);
if (this->AzimuthScanning) return;
if (Flying || Reversing) UpdateMouseSteering(X, Y);
}
//---------------------------------------------------------------------------
......@@ -173,6 +183,10 @@ void vtkInteractorStyleFlight::OnChar(int ctrl, int shift,
case '-' :
this->MotionUserScale *= 0.5;
break;
case 'L' :
case 'l' :
this->PerformAzimuthalScan(360);
break;
}
}
//---------------------------------------------------------------------------
......@@ -181,6 +195,7 @@ void vtkInteractorStyleFlight::OnKeyDown(int ctrl, int shift,
{
this->CtrlKey = ctrl;
this->ShiftKey = shift;
if (this->AzimuthScanning) return;
// New Flight mode behaviour
// Note that we'll need #defines for ARROW key defs under non win32 OS
#ifdef _WIN32
......@@ -235,21 +250,69 @@ void vtkInteractorStyleFlight::OnKeyUp(int ctrl, int shift,
#endif
}
//---------------------------------------------------------------------------
void vtkInteractorStyleFlight::JumpTo(double campos[3], double focpos[3]) {
this->CurrentCamera->SetPosition(campos);
this->CurrentCamera->SetFocalPoint(focpos);
// Tidy up Camera stuff
this->CurrentCamera->OrthogonalizeViewUp();
if (this->FixUpVector) {
this->CurrentCamera->SetViewUp(this->FixedUpVector);
}
this->CurrentRenderer->ResetCameraClippingRange();
// Make sure light follows camera if desired
vtkRenderWindowInteractor *rwi = this->Interactor;
if (rwi->GetLightFollowCamera()) {
this->CurrentLight->SetPosition(campos);
this->CurrentLight->SetFocalPoint(focpos);
}
rwi->Render();
}
//---------------------------------------------------------------------------
void vtkInteractorStyleFlight::PerformAzimuthalScan(int numsteps) {
this->AzimuthScanning = numsteps;
this->Flying = 0;
this->Reversing = 0;
this->KeysDown = 0;
this->AzimuthStepSize = 360.0/numsteps;
this->DoTimerStart();
}
//---------------------------------------------------------------------------
void vtkInteractorStyleFlight::AzimuthScan(void) {
this->AzimuthScanning -= 1;
this->CurrentCamera->SetViewUp(0,0,1);
this->CurrentCamera->Yaw(this->AzimuthStepSize);
//
if (this->AzimuthScanning == 0) {
this->DoTimerStop();
}
}
//---------------------------------------------------------------------------
// All actual motion is performed in the timer
//---------------------------------------------------------------------------
void vtkInteractorStyleFlight::OnTimer(void) {
vtkRenderWindowInteractor *rwi = this->Interactor;
// if we get a timer message we weren't expecting, just shut it down
if (!Flying && !Reversing && !KeysDown) this->DoTimerStop();
if (!this->Flying && !this->Reversing
&& !this->KeysDown && !AzimuthScanning) {
//
this->DoTimerStop();
}
else {
// Make sure CurrentCamera variable is initialized
this->FindPokedCamera(this->OldX, this->OldY);
this->SetupMotionVars();
// Are we moving
if (Flying || Reversing) FlyByMouse();
if (KeysDown) FlyByKey();
// What sort of motion do we want
if (this->AzimuthScanning) {
AzimuthScan();
} else {
if (this->Flying || this->Reversing) FlyByMouse();
if (this->KeysDown) FlyByKey();
}
// Tidy up Camera stuff
this->CurrentCamera->OrthogonalizeViewUp();
if (this->FixUpVector) {
this->CurrentCamera->SetViewUp(this->FixedUpVector);
}
this->CurrentRenderer->ResetCameraClippingRange();
// Make sure light follows camera if desired
if (rwi->GetLightFollowCamera()) {
......@@ -328,7 +391,10 @@ void vtkInteractorStyleFlight::FlyByMouse(void) {
double a_vector[3];
double speed = this->DiagonalLength * this->MotionStepSize * this->MotionUserScale;
speed = speed * ( this->ShiftKey ? this->MotionAccelerationFactor : 1.0);
// Sidestep (convert steering angles to left right movement
if (this->DisableMotion) {
speed = 0;
}
// Sidestep (convert steering angles to left right movement :
// only because I added this after doing the angles earlier
if (this->CtrlKey) {
if (this->YawAngle!=0.0) {
......@@ -361,14 +427,17 @@ void vtkInteractorStyleFlight::FlyByKey(void) {
double speed = this->DiagonalLength * this->MotionStepSize * this->MotionUserScale;
speed = speed * ( this->ShiftKey ? this->MotionAccelerationFactor : 1.0);
double aspeed = AngleStepSize* (this->ShiftKey ? AngleAccelerationFactor : 1.0);
if (this->DisableMotion) {
speed = 0;
}
//
double aspeed = AngleStepSize* (this->ShiftKey ? AngleAccelerationFactor : 1.0);
double a_vector[3];
// Left and right
if (this->CtrlKey) { // Sidestep
ComputeLRVector(a_vector);
if (KeysDown & 1) MotionAlongVector(a_vector,-speed);
if (KeysDown & 2) MotionAlongVector(a_vector, speed);
if (KeysDown & 1) MotionAlongVector(a_vector,-speed);
if (KeysDown & 2) MotionAlongVector(a_vector, speed);
} else {
if (KeysDown & 1) this->CurrentCamera->Yaw( aspeed);
if (KeysDown & 2) this->CurrentCamera->Yaw(-aspeed);
......@@ -402,6 +471,14 @@ void vtkInteractorStyleFlight::PrintSelf(ostream& os, vtkIndent indent) {
<< this->AngleAccelerationFactor << "\n";
os << indent << "MotionUserScale: "
<< this->MotionUserScale << "\n";
os << indent << "DisableMotion: "
<< this->DisableMotion << "\n";
os << indent << "FixUpVector: "
<< this->FixUpVector << "\n";
os << indent << "FixedUpVector: "
<< this->FixedUpVector[0] << " "
<< this->FixedUpVector[1] << " "
<< this->FixedUpVector[2] << "\n";
}
......@@ -95,6 +95,18 @@ public:
// Mouse and key events set correct motion states, OnTimer performs the motion
virtual void OnTimer(void);
// Description:
// Move the Eye/Camera to a specific location (no intermediate
// steps are taken
void JumpTo(double campos[3], double focpos[3]);
// Description:
// rotate the camera round z axis by 360 degrees for viewing scene
// this routine starts a timer and disables key/mouse events preventing
// user interaction until finished (not fully implemented yet)
// the number of steps can be supplied.
void PerformAzimuthalScan(int numsteps);
// Description:
// Set the basic unit step size : by default 1/250 of bounding diagonal
vtkSetMacro(MotionStepSize,double);
......@@ -115,6 +127,21 @@ public:
vtkSetMacro(AngleAccelerationFactor,double);
vtkGetMacro(AngleAccelerationFactor,double);
// Description:
// Disable motion (temporarily - for viewing etc)
vtkSetMacro(DisableMotion,int);
vtkGetMacro(DisableMotion,int);
vtkBooleanMacro(DisableMotion,int);
// Description:
// Fix the "up" vector: also use FixedUpVector
vtkSetMacro(FixUpVector,int);
vtkGetMacro(FixUpVector,int);
vtkBooleanMacro(FixUpVector,int);
// Specify fixed "up"
vtkGetVectorMacro(FixedUpVector,double,3);
vtkSetVectorMacro(FixedUpVector,double,3);
protected:
vtkInteractorStyleFlight();
......@@ -132,12 +159,16 @@ protected:
void ComputeLRVector(double vector[3]);
void MotionAlongVector(double vector[3], double amount);
void SetupMotionVars(void);
void AzimuthScan(void);
//
//
unsigned char KeysDown;
int Flying;
int Reversing;
int TimerRunning;
int AzimuthScanning;
int DisableMotion;
int FixUpVector;
double OldX;
double OldY;
double x2;
......@@ -150,6 +181,8 @@ protected:
double AngleAccelerationFactor;
double YawAngle;
double PitchAngle;
double FixedUpVector[3];
double AzimuthStepSize;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment