# Is it possible to rotate an object in real time using a method other than clicking on the screen?

**URL:** https://discourse.vtk.org/t/is-it-possible-to-rotate-an-object-in-real-time-using-a-method-other-than-clicking-on-the-screen/7079
**Category:** Support
**Created:** [November 5, 2021, 9:19am UTC](https://discourse.vtk.org/t/is-it-possible-to-rotate-an-object-in-real-time-using-a-method-other-than-clicking-on-the-screen/7079 "2021-11-05T09:19:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![riki](https://discourse.vtk.org/user_avatar/discourse.vtk.org/riki/32/4176_2.png) [@riki](https://discourse.vtk.org/u/riki)
#### Post date: [November 5, 2021, 9:19am UTC](https://discourse.vtk.org/t/is-it-possible-to-rotate-an-object-in-real-time-using-a-method-other-than-clicking-on-the-screen/7079/1 "2021-11-05T09:19:27Z")

</div>

I started using VTK the other day, and now I’m mainly working on the code for the tutorial.  
I would like to use VTK to rotate an object by specifying the rotation angle from the GUI, or to read the sensor value and rotate the object as in the real world.

However, the vtkRenderWindowInteractor makes other operations impossible, and it was also impossible to change the PolyData value from another thread.

For example, in the last part of [this example](https://kitware.github.io/vtk-examples/site/Python/Texture/TexturePlane/), I tried to change the following without using the vtkRenderWindowInteractor.

```auto
    # render the image
    renWin.Render()

    renderer.ResetCamera()
    renderer.GetActiveCamera().Elevation(-30)
    renderer.GetActiveCamera().Roll(-20)
    renderer.ResetCameraClippingRange()
    renWin.Render()
    # --- change from here ---
    # iren.Start() # delete

    # add
    z = 0
    While True:
	plane.SetCenter(0, 0, z)
	z+=0.01
	renWin.Render()

```

I know this is obviously wrong (in fact, this code didn’t work), but I didn’t know what other code I could use to implement the functionality.  
Is there any other way to implement this kind of operation?

Also, I thought about using animation, but I don’t think it would be possible to implement the movement I have in mind, which is to change the direction of rotation according to the sensor value.

Any suggestion is appreciated!

---

<div class="post-metadata">

### Author: ![Drew\_Lazzeri](https://discourse.vtk.org/user_avatar/discourse.vtk.org/drew_lazzeri/32/3989_2.png) [@Drew\_Lazzeri](https://discourse.vtk.org/u/Drew_Lazzeri)
#### Post date: [November 5, 2021, 3:38pm UTC](https://discourse.vtk.org/t/is-it-possible-to-rotate-an-object-in-real-time-using-a-method-other-than-clicking-on-the-screen/7079/2 "2021-11-05T15:38:28Z")

</div>

This works for me when I replace the line `plane.SetCenter(0,0,z)` with `planeActor.SetPosition(0,0,z)`.

In VTK, our _Source_ isn’t situated in the world coordinates yet, so to achieve this rotation we need to move it’s _Actor_, which is the representation of our source within the rendered world.

---

<div class="post-metadata">

### Author: ![Drew\_Lazzeri](https://discourse.vtk.org/user_avatar/discourse.vtk.org/drew_lazzeri/32/3989_2.png) [@Drew\_Lazzeri](https://discourse.vtk.org/u/Drew_Lazzeri)
#### Post date: [November 5, 2021, 3:40pm UTC](https://discourse.vtk.org/t/is-it-possible-to-rotate-an-object-in-real-time-using-a-method-other-than-clicking-on-the-screen/7079/3 "2021-11-05T15:40:58Z")

</div>

[This thread](https://discourse.vtk.org/t/move-actors-and-retrieve-their-world-coordinates/6914) has more on the distinction between SetCenter and SetPosition. The code may be in javascript, but the same VTK principles apply there.

---

<div class="post-metadata">

### Author: ![riki](https://discourse.vtk.org/user_avatar/discourse.vtk.org/riki/32/4176_2.png) [@riki](https://discourse.vtk.org/u/riki)
#### Post date: [November 18, 2021, 1:50am UTC](https://discourse.vtk.org/t/is-it-possible-to-rotate-an-object-in-real-time-using-a-method-other-than-clicking-on-the-screen/7079/4 "2021-11-18T01:50:40Z")

</div>

Thank you!  
Following your advice, I was able to reflect the sensor value on the screen in real time by using `actor.SetPosition` and combining it with `TimerEvent` of `vtkRenderWindowInteractor`!
