[vtkusers] Re: vtkPanel translate problem

Brandon Douthit-Wood asbcd2 at uaa.alaska.edu
Thu Mar 6 20:05:05 EST 2003


Jeff,
Here are a few snippets of code from my app.  I can send you all the 
files if you want to try and run it.

// here's where I setup the render window and renderer for the file 
// importer
renderWindow = visPanel.GetRenderWindow();
renderer = visPanel.GetRenderer();
fileImporter = new vtk3DSImporter();
fileImporter.SetRenderWindow(renderWindow);
fileImporter.ComputeNormalsOn();
fileImporter.SetFileName(filename);
fileImporter.Read();
visPanel.SetRenderer(renderer);

// this is the code that is used for translate (nothing was changed)
if (this.InteractionMode == 2)
{
        double  FPoint[];
	double  PPoint[];
	double  APoint[] = new double[3];
	double  RPoint[];
	double focalDepth;

	// get the current focal point and position
	FPoint = cam.GetFocalPoint();
	PPoint = cam.GetPosition();

	// 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;
	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];
		RPoint[2] = RPoint[2]/RPoint[3];
	}
	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]);
	resetCameraClippingRange();
	}

thanks,

--
Brandon Douthit




More information about the vtkusers mailing list