Quote:
The center, in this example, actually remains at (0,0,0) and does not get assigned to (1,1,1), (2,2,2), or (3,3,3). However, the keyboard rotations all work correctly. Does this make sense?
|
The center is not changing because there is some incorrect syntax. The line:
Code:
shaft.center = (1,1,1)
should be:
Code:
shaft.center(1,1,1)
If you make that change throughout the function then it will print the center to be (3,3,3) because that's the last center command called before Kinematics_1 returns. Also, it does not appear you are using the task function properly. If the main task function yields to a subtask, the subtask should have a yield command somewhere within it. The following is an example that yields within the subtask for a key event and sets a new rotation point based on that:
Code:
import viztask
import viz
import vizshape
import vizcam
import vizact
viz.go()
viz.clearcolor(0.5,0.7,1)
#Change navigation style to pivot
cam = vizcam.PivotNavigate(center=[0,0,0], distance = 25)
cam.rotateUp(45)
cam.rotateRight(0)
#Add grid
grid = vizshape.addGrid()
grid.color(viz.GRAY)
grid.collidePlane() # Make collideable plane
#Add an object.
shaft = vizshape.addCylinder(height = 5, radius = .25, slices = 15)
shaft.runAction(vizact.spin(0,0,1,30))
def Kinematics_1():
d = yield viztask.waitKeyDown(('a','s','d','f'))
if d.key == 'a':
shaft.setCenter(0.5,0,0)
elif d.key == 's':
shaft.setCenter(1,0,0)
elif d.key == 'd':
shaft.setCenter(2,0,0)
elif d.key == 'f':
shaft.setCenter(0,0,0)
def Main_Loop():
while True:
print 'shaft center = ', shaft.getCenter()
yield Kinematics_1()
print ''
viztask.schedule(Main_Loop())
Quote:
Furthermore, the 'f' key would not rotate with viz.REL_LOCAL for some reason, but does for viz.REL_PARENT (even though there is no parent present).
|
The shaft object is a child of the world so
viz.REL_PARENT in this case refers to world coordinates.