Camera Orientation

Paul Hsieh pahsieh at usgs.gov
Wed Nov 24 12:38:06 EST 1999


"Jerome, Ron" wrote:
> 
> Does anyone know if there is any easy way to reorient the camera to a
> specific direction, i.e. looking down one of the axis (x,y, or z)?
> 

This is what I do to reset the camera to look down the x direction
at the focal point. (I am still using vtk 2.3 and I am not sure if the
methods are still the same in later versions.)

	// First, get the camera position and the focal point
	vtkCamera *camera = m_Renderer->GetActiveCamera();
	float *pos = camera->GetPosition();
	float *fp = camera->GetFocalPoint();
	// Next, compute the distance between the camera and the focal point
	float dist = sqrt((pos[0]-fp[0])*(pos[0]-fp[0]) + 
		(pos[1]-fp[1])*(pos[1]-fp[1]) + (pos[2]-fp[2])*(pos[2]-fp[2]));
	// Now reposition the camera to look down the x direction at the focal point,
	// keeping the same distance
	camera->SetPosition(fp[0] - dist, fp[1], fp[2]);
	// Set the view up vector. Depending on whether or not you are using
	// a right handed coordinate system, the last parameter might be 1.
	camera->SetViewUp(0, 0, -1);
	camera->ComputeViewPlaneNormal();
	// Assuming you want the light to follow the camera (i.e., "headlight")
        // reposition the light. Here I am using just one light
	vtkLightCollection *lights = m_Renderer->GetLights();
	lights->InitTraversal();
	vtkLight *light = lights->GetNextItem();
	light->SetPosition(camera->GetPosition());
	light->SetFocalPoint(camera->GetFocalPoint());

Hope this helps.

Paul


-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list