protected double activeRate = 5.0;
protected double passiveRate = 0.01;
protected boolean doNotRotate = true;
+ private double[] upDirection = new double[] { 0, 1, 0 };
public vtkCameraAndSelectorAction(InteractiveVtkComposite panel) {
super(panel);
this.rw = panel.getRenderWindow();
this.cam = ren.GetActiveCamera();
}
+
+ public void setUpDirection(double[] upDirection) {
+ this.upDirection = upDirection;
+ }
public void Lock() {
panel.lock();
cam.Azimuth(lastX - x);
cam.Elevation(y - lastY);
if (doNotRotate)
- cam.SetRoll(0);
+ cam.SetViewUp(upDirection);
cam.OrthogonalizeViewUp();
resetCameraClippingRange();
// panel.UpdateLight();
if (this.InteractionMode == 2) {
double FPoint[];
double PPoint[];
- double APoint[] = new double[3];
+ double APoint[];
double RPoint[];
- double focalDepth;
// get the current focal point and position
FPoint = cam.GetFocalPoint();
// calculate the focal depth since we'll be using it a lot
ren.SetWorldPoint(FPoint[0], FPoint[1], FPoint[2], 1.0);
ren.WorldToDisplay();
- focalDepth = ren.GetDisplayPoint()[2];
-
- APoint[0] = rw.GetSize()[0] / 2.0 + (x - lastX);
- APoint[1] = rw.GetSize()[1] / 2.0 - (y - lastY);
- APoint[2] = focalDepth;
+ APoint = ren.GetDisplayPoint();
+
+// int[] size = rw.GetSize();
+ APoint[0] -= x - lastX;
+ APoint[1] += y - lastY;
ren.SetDisplayPoint(APoint);
ren.DisplayToWorld();
RPoint = ren.GetWorldPoint();
+
if (RPoint[3] != 0.0) {
RPoint[0] = RPoint[0] / RPoint[3];
RPoint[1] = RPoint[1] / RPoint[3];
* Compute a translation vector, moving everything 1/2 the distance to the
* cursor. (Arbitrary scale factor)
*/
- cam.SetFocalPoint((FPoint[0] - RPoint[0]) / 2.0 + FPoint[0], (FPoint[1] - RPoint[1]) / 2.0 + FPoint[1],
- (FPoint[2] - RPoint[2]) / 2.0 + FPoint[2]);
- cam.SetPosition((FPoint[0] - RPoint[0]) / 2.0 + PPoint[0], (FPoint[1] - RPoint[1]) / 2.0 + PPoint[1],
- (FPoint[2] - RPoint[2]) / 2.0 + PPoint[2]);
+ cam.SetFocalPoint(RPoint);
+ cam.SetPosition((RPoint[0] - FPoint[0]) + PPoint[0], (RPoint[1] - FPoint[1]) + PPoint[1],
+ (RPoint[2] - FPoint[2]) + PPoint[2]);
resetCameraClippingRange();
}
// zoom
Lock();
cam.SetFocalPoint(x, y, z);
if (doNotRotate)
- cam.SetRoll(0);
+ cam.SetViewUp(upDirection);
cam.OrthogonalizeViewUp();
resetCameraClippingRange();
// panel.UpdateLight();
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
private P3DNodeMap nodeMap;
+ /** Constants for selecting the up-direction */
+ public static final int X = 0, Y = 1, Z = 2;
+
+ protected int upDirection = 1;
+
@Override
public void createPartControl(Composite parent) {
this.parent = parent;
new ContextMenuListener(panel, contextMenu);
cameraAction = createCameraAction();
+ switch (upDirection) {
+ case 0:
+ cameraAction.setUpDirection(new double[] { 1, 0, 0 });
+ break;
+ case 1:
+ cameraAction.setUpDirection(new double[] { 0, 1, 0 });
+ break;
+ case 2:
+ cameraAction.setUpDirection(new double[] { 0, 0, 1 });
+ break;
+ }
+
panel.setDefaultAction(cameraAction);
panel.useDefaultAction();
panel.setPickType(4);
}
+ public void setUpDirection(int upDirection) {
+ this.upDirection = upDirection;
+ }
+
protected vtkCameraAndSelectorAction createCameraAction() {
return new vtkCameraAndSelectorAction(panel);
}
ren1.SetGradientBackground(true);
// vtkActor grid = vtkShape.createGridActor(8,1.0,1|2|4);
- vtkActor grid = vtkShape.createGridActor(8,1.0, 2 );
+ int dir = 1 << upDirection;
+ vtkActor grid = vtkShape.createGridActor(8, 1.0, dir);
grid.SetPickable(0);
ren1.AddActor(grid);
panel.addDeletable(grid);