Animierte Rotation zweier Kugeln um eine feste Achse
Verfasst: Mittwoch 1. Juni 2011, 09:24
Hallo,
ich programmiere noch nicht lange mit Python und bin dewegen noch etwas unerfahren.
Ich versuche gerade zwei Kugeln um eine feste Koordinaten-Achse animiert zu rotieren.
Mein Versuch sieht dabei so aus:
Dabei soll bei Klick auf den Start/Stop Button die Funktion "animation" gestartet werden und die Kugeln einemal (360°) um die Y Achse rotieren. Jedoch funktioniert die Animation nicht.
Also bin ich irgendwie auf dem Holzweg, kann mir jemand einen Tipp geben wie ich die Animation zum laufen bekommen?
LG
Joa
ich programmiere noch nicht lange mit Python und bin dewegen noch etwas unerfahren.
Ich versuche gerade zwei Kugeln um eine feste Koordinaten-Achse animiert zu rotieren.
Mein Versuch sieht dabei so aus:
Code: Alles auswählen
from Tkinter import *
from vtk.tk.vtkTkRenderWidget import *
import vtk
def animation():
global sphere1, sphere2
t_matrix = ( 1 , 0 , 0 , 1.0,
0 , 1 , 0 , 0,
0 , 0 , 1 , 0,
0 , 0 , 0 , 1)
t1 = vtk.vtkTransform()
t1.SetMatrix(t_matrix)
rot = vtk.vtkTransform()
for i in range (0,361):
print i
rot.RotateY(i)
t1.Concatenate(rot)
sphere1Act.SetUserMatrix(t1.GetMatrix())
sphere2Act.SetUserMatrix(t1.GetMatrix())
ren1.AddActor(sphere1Act)
ren1.AddActor(sphere2Act)
root = Tk()
sphere1 = vtk.vtkSphereSource()
sphere1.SetCenter(3,3,3)
sphere1.SetRadius(0.25)
sphere1Map = vtk.vtkPolyDataMapper()
sphere1Map.SetInputConnection(sphere1.GetOutputPort())
sphere1Act = vtk.vtkActor()
sphere1Act.SetMapper(sphere1Map)
ren1=vtk.vtkRenderer()
ren1.AddActor(sphere1Act)
ren1.SetBackground(0.1, 0.2, 0.4)
s_prop1 = sphere1Act.GetProperty()
s_prop1.SetColor(0.0,1.0,1.0)
sphere2 = vtk.vtkSphereSource()
sphere2.SetCenter(-3,-3,-3)
sphere2.SetRadius(0.25)
sphere2Map = vtk.vtkPolyDataMapper()
sphere2Map.SetInputConnection(sphere2.GetOutputPort())
sphere2Act = vtk.vtkActor()
sphere2Act.SetMapper(sphere2Map)
ren1.AddActor(sphere2Act)
s_prop2 = sphere2Act.GetProperty()
s_prop2.SetColor(1.0,0.0,1.0)
rWidget = vtkTkRenderWidget(root, width='800', height='600')
rWidget.pack(expand='true', fill='both')
renWin = rWidget.GetRenderWindow()
renWin.AddRenderer(ren1)
renWin.SetSize(800,600)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
buttonQ = Button(root, text='quit', command=root.quit)
buttonQ.pack(expand='true', fill='x')
buttonS = Button(root, text='start/stop', command=animation)
buttonS.pack(expand='true', fill='x')
root.mainloop()
iren.Initialize()
iren.Start
Also bin ich irgendwie auf dem Holzweg, kann mir jemand einen Tipp geben wie ich die Animation zum laufen bekommen?
LG
Joa