-
Notifications
You must be signed in to change notification settings - Fork 3
/
vtkinteractorstyletrackballcamerastyle2.cpp
739 lines (595 loc) · 22.6 KB
/
vtkinteractorstyletrackballcamerastyle2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/*=========================================================================
Program: Visualization Toolkit
Module: vtkInteractorStyleTrackballCamera2.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkinteractorstyletrackballcamerastyle2.h"
#include "vtkCallbackCommand.h"
#include "vtkCamera.h"
#include "vtkMath.h"
#include "vtkMatrix3x3.h"
#include "vtkObjectFactory.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include <vtkPropPicker.h>
#include <vtkNamedColors.h>
#include <vtkCellPicker.h>
#include <vtkTransform.h>
#include <vtkPlane.h>
#include <vtkBoundedPlanePointPlacer.h>
#include "qtvtkitem.h"
vtkStandardNewMacro(vtkInteractorStyleTrackballCamera2);
//------------------------------------------------------------------------------
vtkInteractorStyleTrackballCamera2::vtkInteractorStyleTrackballCamera2()
{
this->MotionFactor = 10.0;
LastPickedActor = NULL;
LastPickedProperty = vtkProperty::New();
}
//------------------------------------------------------------------------------
vtkInteractorStyleTrackballCamera2::~vtkInteractorStyleTrackballCamera2() = default;
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::OnMouseMove()
{
// std::cout<<"On mouse move "<<std::endl;
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
switch (this->State)
{
case VTKIS_ENV_ROTATE:
this->FindPokedRenderer(x, y);
this->EnvironmentRotate();
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break;
case VTKIS_ROTATE:
this->FindPokedRenderer(x, y);
this->Rotate();
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break;
case VTKIS_PAN:
this->FindPokedRenderer(x, y);
this->Pan();
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break;
case VTKIS_DOLLY:
this->FindPokedRenderer(x, y);
this->Dolly();
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break;
case VTKIS_SPIN:
this->FindPokedRenderer(x, y);
this->Spin();
this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break;
}
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::OnLeftButtonDown()
{
/**
* pick the actor when leftbutton down
**/
// Pick from this location.
vtkNew<vtkNamedColors> colors;
vtkNew<vtkCellPicker> picker;
int* clickPos = this->GetInteractor()->GetEventPosition();
picker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());
auto currentPickActor = picker->GetActor();
if (currentPickActor)
{
// Save the property of the picked actor so that we can restore it next time
// if we select an actor and this actor are another one,
// we should restore the last actor and reset the last actor and its property
if(LastPickedActor != currentPickActor && LastPickedActor ){
qtItem->setSelectedModel(LastPickedActor,false);
}
this->LastPickedActor = currentPickActor;
this->InteractionProp = vtkProp3D::SafeDownCast ( picker->GetViewProp() );
if(qtItem) qtItem->setSelectedModel(LastPickedActor,true);
IsModelSelected = true ;
}else{
if(this->LastPickedActor)
if(qtItem) qtItem->setSelectedModel(LastPickedActor,false);
IsModelSelected = false ;
}
//part of move actor
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
this->FindPokedRenderer(x, y);
if (this->CurrentRenderer == nullptr || picker->GetActor() == nullptr)
{
return;
}
this->GrabFocus(this->EventCallbackCommand);
if (this->Interactor->GetControlKey())
{
this->StartDolly();
}
else
{
this->StartPan();
}
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::OnLeftButtonUp()
{
switch (this->State)
{
case VTKIS_DOLLY:
this->EndDolly();
break;
case VTKIS_PAN:
this->EndPan();
break;
case VTKIS_SPIN:
this->EndSpin();
break;
case VTKIS_ROTATE:
this->EndRotate();
break;
}
if (this->Interactor)
{
this->ReleaseFocus();
}
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::OnMiddleButtonDown()
{
this->FindPokedRenderer(
this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]);
if (this->CurrentRenderer == nullptr)
{
return;
}
this->GrabFocus(this->EventCallbackCommand);
this->StartPan();
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::OnMiddleButtonUp()
{
switch (this->State)
{
case VTKIS_PAN:
this->EndPan();
if (this->Interactor)
{
this->ReleaseFocus();
}
break;
}
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::OnRightButtonDown()
{
//remote right button dolly function
this->FindPokedRenderer(
this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]);
if (this->CurrentRenderer == nullptr)
{
return;
}
this->GrabFocus(this->EventCallbackCommand);
if (this->Interactor->GetShiftKey())
{
if (this->Interactor->GetControlKey())
{
this->StartDolly();
}
else
{
this->StartPan();
}
}
else
{
if (this->Interactor->GetControlKey())
{
this->StartSpin();
}
else
{
this->StartRotate();
}
}
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::OnRightButtonUp()
{
//remote right button dolly function
switch (this->State)
{
case VTKIS_DOLLY:
this->EndDolly();
break;
case VTKIS_PAN:
this->EndPan();
break;
case VTKIS_SPIN:
this->EndSpin();
break;
case VTKIS_ROTATE:
this->EndRotate();
break;
}
if (this->Interactor)
{
this->ReleaseFocus();
}
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::OnMouseWheelForward()
{
this->FindPokedRenderer(
this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]);
if (this->CurrentRenderer == nullptr)
{
return;
}
this->GrabFocus(this->EventCallbackCommand);
this->StartDolly();
double factor = this->MotionFactor * 0.2 * this->MouseWheelMotionFactor;
this->Dolly(pow(1.1, factor));
this->EndDolly();
this->ReleaseFocus();
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::OnMouseWheelBackward()
{
this->FindPokedRenderer(
this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]);
if (this->CurrentRenderer == nullptr)
{
return;
}
this->GrabFocus(this->EventCallbackCommand);
this->StartDolly();
double factor = this->MotionFactor * -0.2 * this->MouseWheelMotionFactor;
this->Dolly(pow(1.1, factor));
this->EndDolly();
this->ReleaseFocus();
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::Rotate()
{
if (this->CurrentRenderer == nullptr)
{
return;
}
vtkRenderWindowInteractor* rwi = this->Interactor;
int dx = rwi->GetEventPosition()[0] - rwi->GetLastEventPosition()[0];
int dy = rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1];
const int* size = this->CurrentRenderer->GetRenderWindow()->GetSize();
double delta_elevation = -20.0 / size[1];
double delta_azimuth = -20.0 / size[0];
double rxf = dx * delta_azimuth * this->MotionFactor;
double ryf = dy * delta_elevation * this->MotionFactor;
vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
camera->Azimuth(rxf);
camera->Elevation(ryf);
camera->OrthogonalizeViewUp();
camera->SetViewUp(0,0,1);
if (this->AutoAdjustCameraClippingRange)
{
this->CurrentRenderer->ResetCameraClippingRange();
}
if (rwi->GetLightFollowCamera())
{
this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
}
rwi->Render();
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::Spin()
{
if (this->CurrentRenderer == nullptr)
{
return;
}
vtkRenderWindowInteractor* rwi = this->Interactor;
double* center = this->CurrentRenderer->GetCenter();
double newAngle = vtkMath::DegreesFromRadians(
atan2(rwi->GetEventPosition()[1] - center[1], rwi->GetEventPosition()[0] - center[0]));
double oldAngle = vtkMath::DegreesFromRadians(
atan2(rwi->GetLastEventPosition()[1] - center[1], rwi->GetLastEventPosition()[0] - center[0]));
vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
camera->Roll(newAngle - oldAngle);
camera->OrthogonalizeViewUp();
rwi->Render();
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::Pan()
{
if(!IsModelSelected){
//if no model selected , the pan can move camera
//so the whole scene will move
if (this->CurrentRenderer == nullptr)
{
return;
}
vtkRenderWindowInteractor* rwi = this->Interactor;
double viewFocus[4], focalDepth, viewPoint[3];
double newPickPoint[4], oldPickPoint[4], motionVector[3];
// Calculate the focal depth since we'll be using it a lot
vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
camera->GetFocalPoint(viewFocus);
this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1], viewFocus[2], viewFocus);
focalDepth = viewFocus[2];
this->ComputeDisplayToWorld(
rwi->GetEventPosition()[0], rwi->GetEventPosition()[1], focalDepth, newPickPoint);
// Has to recalc old mouse point since the viewport has moved,
// so can't move it outside the loop
this->ComputeDisplayToWorld(
rwi->GetLastEventPosition()[0], rwi->GetLastEventPosition()[1], focalDepth, oldPickPoint);
// Camera motion is reversed
motionVector[0] = oldPickPoint[0] - newPickPoint[0];
motionVector[1] = oldPickPoint[1] - newPickPoint[1];
motionVector[2] = oldPickPoint[2] - newPickPoint[2];
camera->GetFocalPoint(viewFocus);
camera->GetPosition(viewPoint);
camera->SetFocalPoint(
motionVector[0] + viewFocus[0], motionVector[1] + viewFocus[1], motionVector[2] + viewFocus[2]);
camera->SetPosition(
motionVector[0] + viewPoint[0], motionVector[1] + viewPoint[1], motionVector[2] + viewPoint[2]);
if (rwi->GetLightFollowCamera())
{
this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
}
rwi->Render();
}else if(0){
//this method is not used
//if model is selected
//the pan only move the actor which user selected
//this part of source is from vtkInteractorStyleTrackballActor.cxx pan() code
//and modified to suitable platform
if (this->CurrentRenderer == nullptr || this->InteractionProp == nullptr)
{
return;
}
vtkRenderWindowInteractor* rwi = this->Interactor;
// Use initial center as the origin from which to pan
double* obj_center = this->InteractionProp->GetCenter();
double disp_obj_center[3], new_pick_point[4];
double old_pick_point[4], motion_vector[3];
this->ComputeWorldToDisplay(obj_center[0], obj_center[1], obj_center[2], disp_obj_center);
this->ComputeDisplayToWorld(
rwi->GetEventPosition()[0], rwi->GetEventPosition()[1], disp_obj_center[2], new_pick_point);
this->ComputeDisplayToWorld(rwi->GetLastEventPosition()[0], rwi->GetLastEventPosition()[1],
disp_obj_center[2], old_pick_point);
motion_vector[0] = new_pick_point[0] - old_pick_point[0];
motion_vector[1] = new_pick_point[1] - old_pick_point[1];
motion_vector[2] = new_pick_point[2] - old_pick_point[2];
//we need set z to origin because the models are on platform
motion_vector[2] = 0;
if (this->InteractionProp->GetUserMatrix() != nullptr)
{
vtkTransform* t = vtkTransform::New();
t->PostMultiply();
t->SetMatrix(this->InteractionProp->GetUserMatrix());
t->Translate(motion_vector[0], motion_vector[1], motion_vector[2]);
this->InteractionProp->GetUserMatrix()->DeepCopy(t->GetMatrix());
t->Delete();
}
else
{
this->InteractionProp->AddPosition(motion_vector[0], motion_vector[1], motion_vector[2]);
}
if (this->AutoAdjustCameraClippingRange)
{
this->CurrentRenderer->ResetCameraClippingRange();
}
rwi->Render();
//method 1 is not good ,we use plane::intersectwithline directly.
}else{
//we can use this method to calculate point ,but is no needed.
// double camPos[3],focalPoint[3];
// vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
// camera->GetPosition(camPos);
// camera->GetFocalPoint(focalPoint);
// double nearWorldPoint[4];
// double farWorldPoint[4];
// double tmp[3];
// tmp[0] = displayPos[0];
// tmp[1] = displayPos[1];
// tmp[2] = 0.0; // near plane
// ren->SetDisplayPoint(tmp);
// ren->DisplayToWorld();
// ren->GetWorldPoint(nearWorldPoint);
// tmp[2] = 1.0; // far plane
// ren->SetDisplayPoint(tmp);
// ren->DisplayToWorld();
// ren->GetWorldPoint(farWorldPoint);
// double normal[3];
// double origin[3];
// this->GetProjectionNormal(normal);
// this->GetProjectionOrigin(origin);
// double position[3];
// double distance;
// if (vtkPlane::IntersectWithLine(
// nearWorldPoint, farWorldPoint, normal, origin, distance, position))
//Create bounding planes for projection plane
vtkSmartPointer<vtkPlane> boundingPlanes[4];
boundingPlanes[0] = vtkSmartPointer<vtkPlane>::New();
boundingPlanes[0]->SetOrigin(0.0, 1000.0, 0.0);
boundingPlanes[0]->SetNormal(0.0, -1.0, 0.0);
boundingPlanes[1] = vtkSmartPointer<vtkPlane>::New();
boundingPlanes[1]->SetOrigin(0.0, -1000.0, 0.0);
boundingPlanes[1]->SetNormal(0.0, 1.0, 0.0);
boundingPlanes[2] = vtkSmartPointer<vtkPlane>::New();
boundingPlanes[2]->SetOrigin(1000.0, 0.0, 0.0);
boundingPlanes[2]->SetNormal(-1.0, 0.0, 0.0);
boundingPlanes[3] = vtkSmartPointer<vtkPlane>::New();
boundingPlanes[3]->SetOrigin(-1000.0, 0.0, 0.0);
boundingPlanes[3]->SetNormal(1.0, 0.0, 0.0);
// Create projection plane parallel platform and Z coordinate from clicked position in model
vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
plane->SetOrigin(0.0, 0.0, 0);
plane->SetNormal(0.0, 0.0, 1.0);
// Set projection and bounding planes to placer
vtkSmartPointer<vtkBoundedPlanePointPlacer> placer = vtkSmartPointer<vtkBoundedPlanePointPlacer>::New();
placer->SetObliquePlane(plane);
placer->SetProjectionNormalToOblique();
placer->AddBoundingPlane(boundingPlanes[0].Get());
placer->AddBoundingPlane(boundingPlanes[1].Get());
placer->AddBoundingPlane(boundingPlanes[2].Get());
placer->AddBoundingPlane(boundingPlanes[3].Get());
double screenPos[2];
double worldOrient[9];
vtkRenderWindowInteractor* rwi = this->Interactor;
screenPos[0] = rwi->GetEventPosition()[0];
// Compensate the y-axis flip for the picking
screenPos[1] = rwi->GetEventPosition()[1];
int16_t withinBounds;
std::array<double, 3> worldPos;
withinBounds = placer->ComputeWorldPosition(this->CurrentRenderer, screenPos, worldPos.data(), worldOrient);
// Use initial center as the origin from which to pan
double* obj_center = this->InteractionProp->GetCenter();
double disp_obj_center[3], new_pick_point[4];
double old_pick_point[4], motion_vector[3];
this->ComputeWorldToDisplay(obj_center[0], obj_center[1], obj_center[2], disp_obj_center);
this->ComputeDisplayToWorld(
rwi->GetEventPosition()[0], rwi->GetEventPosition()[1], disp_obj_center[2], new_pick_point);
this->ComputeDisplayToWorld(rwi->GetLastEventPosition()[0], rwi->GetLastEventPosition()[1],
disp_obj_center[2], old_pick_point);
motion_vector[0] = worldPos[0] - old_pick_point[0];
motion_vector[1] = worldPos[1] - old_pick_point[1];
motion_vector[2] = worldPos[2] - old_pick_point[2];
//we need set z to origin because the models are on platform
motion_vector[2] = 0;
if (this->InteractionProp->GetUserMatrix() != nullptr)
{
vtkTransform* t = vtkTransform::New();
t->PostMultiply();
t->SetMatrix(this->InteractionProp->GetUserMatrix());
t->Translate(motion_vector[0], motion_vector[1], motion_vector[2]);
this->InteractionProp->GetUserMatrix()->DeepCopy(t->GetMatrix());
t->Delete();
}
else
{
this->InteractionProp->AddPosition(motion_vector[0], motion_vector[1], motion_vector[2]);
}
if (this->AutoAdjustCameraClippingRange)
{
this->CurrentRenderer->ResetCameraClippingRange();
}
rwi->Render();
}
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::Dolly()
{
if (this->CurrentRenderer == nullptr)
{
return;
}
vtkRenderWindowInteractor* rwi = this->Interactor;
double* center = this->CurrentRenderer->GetCenter();
int dy = rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1];
double dyf = this->MotionFactor * dy / center[1];
this->Dolly(pow(1.1, dyf));
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::Dolly(double factor)
{
if (this->CurrentRenderer == nullptr)
{
return;
}
vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
if (camera->GetParallelProjection())
{
camera->SetParallelScale(camera->GetParallelScale() / factor);
}
else
{
camera->Dolly(factor);
if (this->AutoAdjustCameraClippingRange)
{
this->CurrentRenderer->ResetCameraClippingRange();
}
}
if (this->Interactor->GetLightFollowCamera())
{
this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
}
this->Interactor->Render();
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::EnvironmentRotate()
{
if (this->CurrentRenderer == nullptr)
{
return;
}
vtkRenderWindowInteractor* rwi = this->Interactor;
int dx = rwi->GetEventPosition()[0] - rwi->GetLastEventPosition()[0];
int sizeX = this->CurrentRenderer->GetRenderWindow()->GetSize()[0];
vtkNew<vtkMatrix3x3> mat;
double* up = this->CurrentRenderer->GetEnvironmentUp();
double* right = this->CurrentRenderer->GetEnvironmentRight();
double front[3];
vtkMath::Cross(right, up, front);
for (int i = 0; i < 3; i++)
{
mat->SetElement(i, 0, right[i]);
mat->SetElement(i, 1, up[i]);
mat->SetElement(i, 2, front[i]);
}
double angle = (dx / static_cast<double>(sizeX)) * this->MotionFactor;
double c = std::cos(angle);
double s = std::sin(angle);
double t = 1.0 - c;
vtkNew<vtkMatrix3x3> rot;
rot->SetElement(0, 0, t * up[0] * up[0] + c);
rot->SetElement(0, 1, t * up[0] * up[1] - up[2] * s);
rot->SetElement(0, 2, t * up[0] * up[2] + up[1] * s);
rot->SetElement(1, 0, t * up[0] * up[1] + up[2] * s);
rot->SetElement(1, 1, t * up[1] * up[1] + c);
rot->SetElement(1, 2, t * up[1] * up[2] - up[0] * s);
rot->SetElement(2, 0, t * up[0] * up[2] - up[1] * s);
rot->SetElement(2, 1, t * up[1] * up[2] + up[0] * s);
rot->SetElement(2, 2, t * up[2] * up[2] + c);
vtkMatrix3x3::Multiply3x3(rot, mat, mat);
// update environment orientation
this->CurrentRenderer->SetEnvironmentUp(
mat->GetElement(0, 1), mat->GetElement(1, 1), mat->GetElement(2, 1));
this->CurrentRenderer->SetEnvironmentRight(
mat->GetElement(0, 0), mat->GetElement(1, 0), mat->GetElement(2, 0));
rwi->Render();
}
bool vtkInteractorStyleTrackballCamera2::getIsModelSelected() const
{
return IsModelSelected;
}
void vtkInteractorStyleTrackballCamera2::setQtItem(qtVtkItem *item)
{
qtItem = item;
}
void vtkInteractorStyleTrackballCamera2::OnKeyDown()
{
int key = (int)this->Interactor->GetKeyCode();
switch (key) {
case 127:
this->CurrentRenderer->RemoveActor(LastPickedActor);
qtItem->setSelectedModel(LastPickedActor,false);
qtItem->setIsModelSelected(false);
LastPickedActor = nullptr;
LastPickedProperty = nullptr;
default:
std::cout<<"key code is "<<(int)this->Interactor->GetKeyCode()<<std::endl;
break;
}
}
//------------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera2::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "MotionFactor: " << this->MotionFactor << "\n";
}