# Synchronising multiple cameras

**URL:** https://discourse.vtk.org/t/synchronising-multiple-cameras/3860
**Category:** Support
**Created:** [July 28, 2020, 6:47am UTC](https://discourse.vtk.org/t/synchronising-multiple-cameras/3860 "2020-07-28T06:47:19Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![dwventer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dwventer/32/1579_2.png) [@dwventer](https://discourse.vtk.org/u/dwventer)
#### Post date: [July 31, 2020, 2:11am UTC](https://discourse.vtk.org/t/synchronising-multiple-cameras/3860/2 "2020-07-31T02:11:03Z")

</div>

Manage to figure out my own solution. There might be better ways out there but I am unaware of them at this stage.

This is what I have done:

I have a renderer for each actor. I then set the window centre for each renderer so that they do not overlap one another.

e.g. `vtkRenderer->GetActiveCamera()->SetWindowCenter(0.5, 0);`

Then I added an `vtkCommand::InteractionEvent` observer to vtkInteractorStyleTrackballCamera.

The callback method of the observer:

```
void TrackballRotateEvent(vtkObject* obj, unsigned long eid, void* clientdata, void* calldata)
{
if ((m_ViewMode != E3DVIEWMODE::CAMERA_SYNC)|| (m_pvtkTrackballInteractorStyle->GetState() != VTKIS_ROTATE))
	return;

vtkSmartPointer < vtkRenderer > curRenderer = m_pvtkTrackballInteractorStyle->GetCurrentRenderer();

for (size_t i = 0; i < m_3DImageVec.size(); ++i) {
	//Rotate all other renderers
	if (m_3DImageVec[i].m_pvtkRenderer != curRenderer) {
		m_pvtkTrackballInteractorStyle->SetDefaultRenderer(m_3DImageVec[i].m_pvtkRenderer); //must set the default renderer before setting
		m_pvtkTrackballInteractorStyle->SetCurrentRenderer(m_3DImageVec[i].m_pvtkRenderer); //the current renderer otherwise it will have no affect
		m_pvtkTrackballInteractorStyle->Rotate(); //This is basically what is used to rotate the object according to the mouse move event
	}
}
//set back to original renderer
m_pvtkTrackballInteractorStyle->SetDefaultRenderer(curRenderer);
m_pvtkTrackballInteractorStyle->SetCurrentRenderer(curRenderer);
}

```

As you can see that I then simply call Rotate on the Style after swapping out renderers. This allows all actors to rotate synchronously. Note: I have complete access to the main object within the callback method above.

The advantage here is that I can simply change the view mode and it is then possible to rotate only the selected actor.

---

_[View the full topic](https://discourse.vtk.org/t/synchronising-multiple-cameras/3860)._
